Skip to content

Commit 07536b5

Browse files
committed
Added full coverage by tests
1 parent f62778b commit 07536b5

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ thumbs.db
88
*.iws
99

1010
node_modules/
11+
coverage/
1112
package-lock.json

__specs__/index.spec.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const babelLoaderExcludeNodeModulesExcept = require('../index');
2+
const path = require('path');
3+
const escapeStringRegexp = require('escape-string-regexp');
4+
const ESCAPED_PATH_SEP = escapeStringRegexp(path.sep);
5+
6+
const X = ESCAPED_PATH_SEP === '\\\\';
7+
8+
describe('Should create a correct regular expression for excluding node_modules', function () {
9+
/**
10+
* @type {TestCase[]}
11+
*/
12+
const testCases = [
13+
{
14+
params: undefined,
15+
expected: /node_modules/i
16+
},
17+
{
18+
params: [],
19+
expected: /node_modules/i
20+
},
21+
{
22+
params: ['xxx'],
23+
expected: X ? /node_modules\\(?!(xxx)\\)/i : /node_modules\/(?!(xxx)\/)/i
24+
},
25+
{
26+
params: ['xxx/'],
27+
expected: X ? /node_modules\\(?!(xxx)\\)/i : /node_modules\/(?!(xxx)\/)/i
28+
},
29+
{
30+
params: ['zZz', 'yYy'],
31+
expected: X
32+
? /node_modules\\(?!(zZz|yYy)\\)/i
33+
: /node_modules\/(?!(zZz|yYy)\/)/i
34+
}
35+
];
36+
37+
testCases.forEach(function ({ params, expected }, i) {
38+
test(`Test case #${i + 1}`, function () {
39+
const result = babelLoaderExcludeNodeModulesExcept(params);
40+
expect(result).toEqual(expected);
41+
});
42+
});
43+
});
44+
45+
/**
46+
* @typedef {Object} TestCase
47+
* @property {string[]} params
48+
* @property {RegExp} expected
49+
*/

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
coverageReporters: ['json-summary', 'lcov'],
3+
coveragePathIgnorePatterns: ['<rootDir>/node_modules/'],
4+
testPathIgnorePatterns: ['<rootDir>/node_modules/']
5+
};

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{
22
"name": "babel-loader-exclude-node-modules-except",
3-
"version": "1.0.3",
3+
"version": "1.1.0",
44
"description": "Creating a regular expression for excluding node_modules from babel transpiling except for individual modules",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "npm run prettier && npm run eslint",
8+
"prettier": "prettier index.js --check",
9+
"eslint": "eslint index.js",
10+
"jest": "jest",
11+
"jest:coverage": "jest --coverage --collectCoverageFrom=\"index.js\" && istanbul-badges-readme"
812
},
913
"repository": {
1014
"type": "git",
@@ -28,5 +32,13 @@
2832
"homepage": "https://github.com/WezomAgency/babel-loader-exclude-node-modules-except#readme",
2933
"dependencies": {
3034
"escape-string-regexp": "2.0.0"
35+
},
36+
"devDependencies": {
37+
"@wezom/eslint-config": "^2.1.0-beta.0",
38+
"eslint": "^7.19.0",
39+
"eslint-config-prettier": "^7.2.0",
40+
"istanbul-badges-readme": "^1.2.0",
41+
"jest": "^26.6.3",
42+
"prettier": "^2.2.1"
3143
}
3244
}

0 commit comments

Comments
 (0)