Repository navigation
Expand file tree
/
Copy pathversionSelectionFallback.test.ts
More file actions
59 lines (54 loc) · 2.39 KB
/
Copy pathversionSelectionFallback.test.ts
File metadata and controls
59 lines (54 loc) · 2.39 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
jest.mock('@microsoft/rush/lib/start', () => ({}));
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { DaemonLauncherUnavailableError } from '@rushstack/rush-daemon/lib/VersionSelectedDaemonLauncher';
import * as connectionOptions from '../daemonConnectionOptions';
import { launchClientAsync } from '../launchClient';
it('uses the native version selector when no compatible foreign daemon launcher exists', async () => {
const folder: string = fs.mkdtempSync(path.join(os.tmpdir(), 'rush-client-version-fallback-'));
const originalArgv: string[] = process.argv;
const originalEnvironment: NodeJS.ProcessEnv = process.env;
fs.writeFileSync(
path.join(folder, 'rush.json'),
JSON.stringify({
rushVersion: '5.178.1',
pnpmVersion: '10.27.0',
projects: []
})
);
const selection = jest
.spyOn(connectionOptions, 'getDaemonConnectionOptionsAsync')
.mockRejectedValue(new DaemonLauncherUnavailableError('5.178.1', 'No compatible request-launch APIs.'));
const output = jest.spyOn(process.stderr, 'write').mockReturnValue(true);
jest.spyOn(process, 'cwd').mockReturnValue(folder);
process.argv = [process.execPath, 'rush-client', 'build', '--to', 'project'];
process.env = { ...originalEnvironment, CI: 'false', RUSH_DAEMON: '1', RUSH_REPORTER: 'legacy' };
delete process.env.RUSH_PREVIEW_VERSION;
try {
await launchClientAsync(false);
expect(process.argv[1]).toBe(
path.join(path.dirname(require.resolve('@microsoft/rush/package.json')), 'bin/rush')
);
expect(selection).toHaveBeenCalledWith(
folder,
'5.178.1',
expect.objectContaining({ RUSH_DAEMON: '1' }),
true
);
expect(Object.isFrozen(selection.mock.calls[0][2])).toBe(true);
expect(process.argv.slice(2)).toEqual(['build', '--to', 'project']);
expect(process.env.RUSH_DAEMON).toBeUndefined();
expect(output).toHaveBeenCalledWith(
'rush-client: Cannot launch selected Rush 5.178.1: No compatible request-launch APIs. ' +
'Use native Rush instead; using in-process Rush.\n'
);
} finally {
process.argv = originalArgv;
process.env = originalEnvironment;
jest.restoreAllMocks();
fs.rmSync(folder, { recursive: true });
}
});