-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
Copy pathcommands.test.ts
60 lines (53 loc) · 1.79 KB
/
commands.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { Arguments } from 'yargs';
import type { CreatePackageOptions } from './commands';
import { createPackageHandler } from './commands';
import * as utils from './utils';
jest.mock('./utils', () => ({
finalizeAndWriteData: jest.fn(),
readMonorepoFiles: jest.fn(),
}));
// January 2 to avoid time zone issues.
jest.useFakeTimers().setSystemTime(new Date('2023-01-02'));
describe('create-package/commands', () => {
describe('createPackageHandler', () => {
it('should create the expected package', async () => {
(utils.readMonorepoFiles as jest.Mock).mockResolvedValue({
tsConfig: {
references: [{ path: '../packages/foo' }],
},
tsConfigBuild: {
references: [{ path: '../packages/foo' }],
},
nodeVersions: '>=18.0.0',
});
const args: Arguments<CreatePackageOptions> = {
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/naming-convention
_: [],
$0: 'create-package',
name: '@metamask/new-package',
description: 'A new MetaMask package.',
};
await createPackageHandler(args);
expect(utils.finalizeAndWriteData).toHaveBeenCalledTimes(1);
expect(utils.finalizeAndWriteData).toHaveBeenCalledWith(
{
name: '@metamask/new-package',
description: 'A new MetaMask package.',
directoryName: 'new-package',
nodeVersions: '>=18.0.0',
currentYear: '2023',
},
{
tsConfig: {
references: [{ path: '../packages/foo' }],
},
tsConfigBuild: {
references: [{ path: '../packages/foo' }],
},
nodeVersions: '>=18.0.0',
},
);
});
});
});