forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunPublished.spec.ts
146 lines (117 loc) · 4.43 KB
/
runPublished.spec.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/no-explicit-any */
import childProcess from 'child_process';
import main from './runPublished';
// ☝️ NOTE - don't comment or remove this mock while running tests - you will need to manually kill lot of node processes :P
jest.mock('child_process');
describe(`#runPublished`, () => {
const originalConsoleLog = console.log;
beforeEach(() => {
console.log = () => {};
});
afterAll(() => {
console.log = originalConsoleLog;
});
function setup() {
const workspacePackagesMetadata = {
'@fluentui/web-components': {
packagePath: 'packages/web-components',
packageJson: { name: '@fluentui/web-components', version: '1.0.0', main: 'lib/index.js', private: false },
},
'@fluentui/react': {
packagePath: 'packages/react',
packageJson: { name: '@fluentui/react', version: '8.0.0', main: 'lib/index.js', private: false },
},
'@fluentui/react-northstar': {
packagePath: 'packages/fluentui/react-northstar',
packageJson: { name: '@fluentui/react-northstar', version: '0.1.0', main: 'lib/index.js', private: false },
},
'@fluentui/react-components': {
packagePath: 'packages/react-components/react-components',
packageJson: { name: '@fluentui/react-components', version: '9.0.0', main: 'lib/index.js', private: false },
},
};
const spawnSyncMock = jest.spyOn(childProcess, 'spawnSync').mockImplementation((() => {
return { status: 0 };
}) as any);
jest.spyOn(process, 'exit').mockImplementation((() => {}) as any);
function getSpawnCallArguments() {
const [, spawnSyncArgs, spawnSyncOptions] = spawnSyncMock.mock.calls[0];
const [lagePath, ...restArgs] = spawnSyncArgs as string[];
return { spawnSyncArgs, spawnSyncOptions, lagePath, restArgs };
}
return { workspacePackagesMetadata, spawnSyncMock, getSpawnCallArguments };
}
it(`should exit and provide help info if there are not arguments provided`, () => {
const { workspacePackagesMetadata, spawnSyncMock } = setup();
const logSpy = jest.spyOn(console, 'log');
main({
argv: [],
workspacePackagesMetadata,
});
expect(spawnSyncMock).not.toHaveBeenCalled();
expect(logSpy.mock.calls[0][0]).toMatchInlineSnapshot(`
"Usage:
yarn run:published <script> [<args>]
This command runs <script> for all beachball-published packages, as well as packages for the version 8 website.
"
`);
});
it(`should do not invoke lage with '--to' if all packages are private`, () => {
const { workspacePackagesMetadata, getSpawnCallArguments } = setup();
const metadataCopy = { ...workspacePackagesMetadata };
metadataCopy['@fluentui/react'].packageJson.private = true;
metadataCopy['@fluentui/react-components'].packageJson.private = true;
main({
argv: ['build'],
workspacePackagesMetadata: metadataCopy,
});
const { restArgs } = getSpawnCallArguments();
expect(restArgs).toMatchInlineSnapshot(`
Array [
"run",
"build",
"--verbose",
]
`);
});
it(`should never invoke built --to for northstar and web-components`, () => {
const { spawnSyncMock, workspacePackagesMetadata, getSpawnCallArguments } = setup();
main({
argv: ['build'],
workspacePackagesMetadata,
});
const { lagePath, restArgs, spawnSyncOptions } = getSpawnCallArguments();
expect(spawnSyncMock).toHaveBeenCalledTimes(1);
expect(lagePath.endsWith('node_modules/lage/bin/lage.js')).toBe(true);
expect(restArgs).toMatchInlineSnapshot(`
Array [
"run",
"build",
"--verbose",
"--to=@fluentui/react",
]
`);
expect(spawnSyncOptions).toEqual({ stdio: 'inherit', maxBuffer: 524288000 });
expect(process.exit).toHaveBeenCalledWith(0);
});
it(`should invoke built --to for v9`, () => {
const { workspacePackagesMetadata, getSpawnCallArguments } = setup();
process.env.RELEASE_VNEXT = 'true';
main({
argv: ['build'],
workspacePackagesMetadata,
});
const { restArgs } = getSpawnCallArguments();
expect(restArgs).toMatchInlineSnapshot(`
Array [
"run",
"build",
"--verbose",
"--to=@fluentui/react-components",
]
`);
expect(process.exit).toHaveBeenCalledWith(0);
delete process.env.RELEASE_VNEXT;
});
});