forked from yarnpkg/yarn
/
workspace.js
57 lines (46 loc) 路 1.88 KB
/
workspace.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
/* @flow */
jest.mock('../../src/util/child');
import {BufferReporter} from '../../src/reporters/index.js';
import {run as workspace} from '../../src/cli/commands/workspace.js';
import * as reporters from '../../src/reporters/index.js';
import Config from '../../src/config.js';
import path from 'path';
import {NODE_BIN_PATH, YARN_BIN_PATH} from '../../src/constants';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'workspace');
const spawn: $FlowFixMe = require('../../src/util/child').spawn;
beforeEach(() => spawn.mockClear());
async function runWorkspace(
flags: Object,
args: Array<string>,
name: string,
checkSteps?: ?(config: Config, reporter: BufferReporter) => ?Promise<void>,
): Promise<void> {
const cwd = path.join(fixturesLoc, name);
const reporter = new reporters.BufferReporter({stdout: null, stdin: null});
try {
const config = await Config.create({cwd}, reporter);
await workspace(config, reporter, flags, args);
if (checkSteps) {
await checkSteps(config, reporter);
}
} catch (err) {
throw new Error(`${err && err.stack}`);
}
}
test('workspace run command', (): Promise<void> => {
return runWorkspace({}, ['workspace-1', 'run', 'script'], 'run-basic', config => {
expect(spawn).toHaveBeenCalledWith(NODE_BIN_PATH, [YARN_BIN_PATH, 'run', 'script'], {
stdio: 'inherit',
cwd: path.join(fixturesLoc, 'run-basic', 'packages', 'workspace-child-1'),
});
});
});
test('workspace run command forwards raw arguments', (): Promise<void> => {
return runWorkspace({}, ['workspace-1', 'run', 'script', 'arg1', '--flag1'], 'run-basic', config => {
expect(spawn).toHaveBeenCalledWith(NODE_BIN_PATH, [YARN_BIN_PATH, 'run', 'script', 'arg1', '--flag1'], {
stdio: 'inherit',
cwd: path.join(fixturesLoc, 'run-basic', 'packages', 'workspace-child-1'),
});
});
});