Skip to content

Commit 39773cb

Browse files
committed
test: add scope test
1 parent fe791c6 commit 39773cb

4 files changed

Lines changed: 57 additions & 2 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"patterns": {
3+
"system": [
4+
"build",
5+
"deps",
6+
"package",
7+
"release"
8+
],
9+
"packages": [
10+
"core",
11+
"native",
12+
"desktop",
13+
"web"
14+
],
15+
"components": {
16+
"auth": "Authentication, login, OAuth, etc.",
17+
"forms": "General user input, forms, etc.",
18+
"navigation": "Navigation, history and routing.",
19+
"networking": "Network-related code, connectivity checks, offline persistence, etc.",
20+
"notifications": "Notification code, in-app notifications, push notifications, etc",
21+
"profile": "User profile",
22+
"settings": "Settings and preferences"
23+
}
24+
}
25+
}

‎__tests__/index.test.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const config = require('../index');
2+
3+
describe('config', () => {
4+
it('parses .commitlint-patterns.json', () => {
5+
const scopes = config.rules['scope-enum']()[2];
6+
7+
expect(scopes).toEqual(
8+
expect.arrayContaining([
9+
'build',
10+
'deps',
11+
'package',
12+
'release',
13+
'core',
14+
'native',
15+
'desktop',
16+
'web',
17+
'auth',
18+
'forms',
19+
'navigation',
20+
'networking',
21+
'notifications',
22+
'profile',
23+
'settings',
24+
'system',
25+
]),
26+
);
27+
});
28+
});

‎index.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const { flatten, keys, mapObjIndexed, merge } = require('ramda');
55

66
const { patterns } = JSON.parse(
77
fs.readFileSync(
8-
path.resolve(process.cwd(), '.commitlint-patterns.json'),
8+
process.env.NODE_ENV === 'test'
9+
? './__tests__/.commitlint-patterns.json'
10+
: path.resolve(process.cwd(), '.commitlint-patterns.json'),
911
'utf-8',
1012
),
1113
);

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
},
6161
"jest": {
6262
"testMatch": [
63-
"<rootDir>/src/**/*.test.js"
63+
"<rootDir>/**/*.test.js"
6464
],
6565
"collectCoverageFrom": [
6666
"src/**/*.js",

0 commit comments

Comments
 (0)