Skip to content

Commit f88a366

Browse files
authored
test: speed up config-lerna-scopes test suite (conventional-changelog#950)
1 parent 9fa03d5 commit f88a366

File tree

6 files changed

+668
-32
lines changed

6 files changed

+668
-32
lines changed

@commitlint/config-lerna-scopes/index.test.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {npm} from '@commitlint/test';
1+
import {lerna} from '@commitlint/test';
22
import config from '.';
33

44
test('exports rules key', () => {
@@ -46,27 +46,29 @@ test('scope-enum has expected modifier', async () => {
4646

4747
test('returns empty value for empty lerna repository', async () => {
4848
const {'scope-enum': fn} = config.rules;
49-
const cwd = await npm.bootstrap('fixtures/empty', __dirname);
49+
const cwd = await lerna.bootstrap('empty', __dirname);
5050
const [, , value] = await fn({cwd});
5151
expect(value).toEqual([]);
52-
}, 60000);
52+
});
5353

5454
test('returns expected value for basic lerna repository', async () => {
5555
const {'scope-enum': fn} = config.rules;
56-
const cwd = await npm.bootstrap('fixtures/basic', __dirname);
56+
const cwd = await lerna.bootstrap('basic', __dirname);
57+
5758
const [, , value] = await fn({cwd});
5859
expect(value).toEqual(['a', 'b']);
59-
}, 60000);
60+
});
6061

6162
test('returns expected value for scoped lerna repository', async () => {
6263
const {'scope-enum': fn} = config.rules;
63-
const cwd = await npm.bootstrap('fixtures/scoped', __dirname);
64+
const cwd = await lerna.bootstrap('scoped', __dirname);
65+
6466
const [, , value] = await fn({cwd});
6567
expect(value).toEqual(['a', 'b']);
66-
}, 60000);
68+
});
6769

6870
test('works with lerna version < 3', async () => {
6971
const {'scope-enum': fn} = config.rules;
70-
const cwd = await npm.bootstrap('fixtures/lerna-two', __dirname);
72+
const cwd = await lerna.bootstrap('lerna-two', __dirname);
7173
await expect(fn({cwd})).resolves.toBeTruthy();
72-
}, 60000);
74+
});

@packages/test/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as fix from './fix';
22
import * as git from './git';
3+
import * as lerna from './lerna';
34
import * as npm from './npm';
45

5-
export {fix, git, npm};
6+
export {fix, git, lerna, npm};

@packages/test/src/lerna.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import path from 'path';
2+
import fs from 'fs-extra';
3+
import resolvePkg from 'resolve-pkg';
4+
import * as fix from './fix';
5+
6+
export type LernaFixture = 'basic' | 'empty' | 'lerna-two' | 'scoped';
7+
8+
export async function bootstrap(
9+
fixture: string,
10+
directory: string
11+
): Promise<string> {
12+
const cwd = await fix.bootstrap(`fixtures/${fixture}`, directory);
13+
const lerna = fixture === 'lerna-two' ? 'lerna-v2' : 'lerna-v3';
14+
await fs.mkdirp(path.join(cwd, 'node_modules', '@lerna'));
15+
await fs.symlink(
16+
resolvePkg('@lerna/project')!,
17+
path.join(cwd, 'node_modules', '@lerna', 'project')
18+
);
19+
await fs.symlink(resolvePkg(lerna)!, path.join(cwd, 'node_modules', 'lerna'));
20+
return cwd;
21+
}

@packages/test/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outDir": "./lib"
77
},
88
"include": [
9-
"./src"
9+
"./src/**/*.ts"
1010
],
1111
"exclude": [
1212
"./src/**/*.test.ts",

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@
8282
"lint-staged": "10.0.7",
8383
"prettier": "1.17.1",
8484
"ts-jest": "25.2.0",
85-
"typescript": "3.7.5"
85+
"typescript": "3.7.5",
86+
"lerna-v2": "npm:lerna@2",
87+
"lerna-v3": "npm:lerna@3"
8688
},
8789
"husky": {
8890
"hooks": {

0 commit comments

Comments
 (0)