/
runPublish.spec.js
92 lines (89 loc) · 2.55 KB
/
runPublish.spec.js
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
import { expandPackageList } from 'shipjs-lib';
import { run, print } from '../../../util';
import runPublish from '../runPublish';
import { mockPrint } from '../../../../tests/util';
jest.unmock('../../../helper');
// if `unmock` causes any trouble in the future,
// we might try this: https://github.com/facebook/jest/issues/2649#issuecomment-360467278
// `runPublish` depends on `getPublishCommand` from `helper`
// and we need it unmocked to successfully run the following tests.
describe('runPublish', () => {
it('works with yarn', () => {
runPublish({
isYarn: true,
config: {
publishCommand: ({ defaultCommand }) => defaultCommand,
},
releaseTag: 'latest',
dir: '.',
dryRun: false,
});
expect(run).toHaveBeenCalledTimes(1);
expect(run.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
"command": "npm_config_registry=https://registry.npmjs.org/ npm publish --tag latest",
"dir": ".",
"dryRun": false,
}
`);
});
it('works with npm', () => {
runPublish({
isYarn: false,
config: {
publishCommand: ({ defaultCommand }) => defaultCommand,
},
releaseTag: 'latest',
dir: '.',
dryRun: false,
});
expect(run).toHaveBeenCalledTimes(1);
expect(run.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
"command": "npm publish --tag latest",
"dir": ".",
"dryRun": false,
}
`);
});
it('works with monorepo', () => {
const output = [];
mockPrint(print, output);
expandPackageList.mockImplementationOnce(() => [
'/package-a',
'/package-b',
]);
runPublish({
isYarn: true,
config: {
publishCommand: ({ defaultCommand }) => defaultCommand,
monorepo: {},
},
releaseTag: 'latest',
dir: '.',
dryRun: false,
});
expect(output).toMatchInlineSnapshot(`
Array [
"› Publishing.",
"Running the following at /package-a",
"Running the following at /package-b",
]
`);
expect(run).toHaveBeenCalledTimes(2);
expect(run.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
"command": "npm_config_registry=https://registry.npmjs.org/ npm publish --tag latest",
"dir": "/package-a",
"dryRun": false,
}
`);
expect(run.mock.calls[1][0]).toMatchInlineSnapshot(`
Object {
"command": "npm_config_registry=https://registry.npmjs.org/ npm publish --tag latest",
"dir": "/package-b",
"dryRun": false,
}
`);
});
});