Skip to content

Commit 71e2d85

Browse files
committed
test(unit): converted the js scaffolder tests to vitest
and re-test drove all of the logic to improve the complexity of the tests for this module. there is still plenty of opportunity to refactor to simplify, but the tests of the current state feel a lot more manageable than before for #452
1 parent 6d9fa7f commit 71e2d85

File tree

6 files changed

+286
-411
lines changed

6 files changed

+286
-411
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"watch": "run-s 'build:js -- --watch'",
4949
"prepack": "run-s build",
5050
"test:unit": "cross-env NODE_ENV=test c8 run-s test:unit:base",
51-
"test:unit:base": "npm-run-all --print-label build --parallel test:unit:mocha test:unit:vitest",
51+
"test:unit:base": "npm-run-all --print-label build --parallel test:unit:vitest",
5252
"test:unit:vitest": "DEBUG=any vitest run",
5353
"test:unit:mocha": "DEBUG=any mocha 'src/**/*-test.js'"
5454
},

src/package/scaffolder.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import {info} from '@travi/cli-messages';
22
import {writePackageJson} from '@form8ion/javascript-core';
33

4+
import buildPackageName from './package-name.js';
45
import buildPackageDetails from './details.js';
56

67
export default async function ({
78
projectRoot,
9+
projectName,
10+
scope,
811
dialect,
9-
packageName,
1012
license,
1113
author,
1214
description
1315
}) {
1416
info('Configuring package.json');
1517

18+
const packageName = buildPackageName(projectName, scope);
19+
1620
await writePackageJson({
1721
projectRoot,
1822
config: await buildPackageDetails({
@@ -24,5 +28,5 @@ export default async function ({
2428
})
2529
});
2630

27-
return {};
31+
return {packageName};
2832
}

src/package/scaffolder.test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import {writePackageJson} from '@form8ion/javascript-core';
22

3-
import {afterEach, describe, expect, it, vi} from 'vitest';
3+
import {describe, expect, it, vi} from 'vitest';
44
import any from '@travi/any';
55
import {when} from 'jest-when';
66

77
import * as buildPackageDetails from './details.js';
8+
import buildPackageName from './package-name.js';
89
import {scaffold} from './index.js';
910

1011
vi.mock('@form8ion/javascript-core');
11-
vi.mock('./details');
12+
vi.mock('./package-name.js');
13+
vi.mock('./details.js');
1214

1315
describe('package scaffolder', () => {
14-
afterEach(() => {
15-
vi.clearAllMocks();
16-
});
17-
1816
it('should create the package file', async () => {
17+
const projectName = any.string();
1918
const packageName = any.string();
19+
const scope = any.word();
2020
const packageDetails = any.simpleObject();
2121
const projectRoot = any.string();
2222
const dialect = any.word();
2323
const license = any.string();
2424
const author = any.simpleObject();
2525
const description = any.sentence();
26+
when(buildPackageName).calledWith(projectName, scope).mockReturnValue(packageName);
2627
when(buildPackageDetails.default).calledWith({
2728
packageName,
2829
dialect,
@@ -33,12 +34,13 @@ describe('package scaffolder', () => {
3334

3435
expect(await scaffold({
3536
projectRoot,
37+
projectName,
38+
scope,
3639
dialect,
37-
packageName,
3840
license,
3941
author,
4042
description
41-
})).toEqual({});
43+
})).toEqual({packageName});
4244
expect(writePackageJson).toHaveBeenCalledWith({projectRoot, config: packageDetails});
4345
});
4446
});

0 commit comments

Comments
 (0)