-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
command.executableSubcommand.lookup.test.js
105 lines (91 loc) · 3.5 KB
/
command.executableSubcommand.lookup.test.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
93
94
95
96
97
98
99
100
101
102
103
104
105
const childProcess = require('child_process');
const path = require('path');
// Calling node explicitly so pm works without file suffix cross-platform.
const testOrSkipOnWindows = (process.platform === 'win32') ? test.skip : test;
const pm = path.join(__dirname, './fixtures/pm');
test('when subcommand file missing then error', (done) => {
childProcess.exec(`node ${pm} list`, function(_error, stdout, stderr) {
if (process.platform === 'win32') {
// Get uncaught thrown error on Windows
expect(stderr.length).toBeGreaterThan(0);
} else {
expect(stderr).toBe('error: pm-list(1) does not exist, try --help\n');
}
done();
});
});
test('when alias subcommand file missing then error', (done) => {
childProcess.exec(`node ${pm} lst`, function(_error, stdout, stderr) {
if (process.platform === 'win32') {
// Get uncaught thrown error on Windows
expect(stderr.length).toBeGreaterThan(0);
} else {
expect(stderr).toBe('error: pm-list(1) does not exist, try --help\n');
}
done();
});
});
test('when subcommand file has no suffix then lookup succeeds', (done) => {
childProcess.exec(`node ${pm} install`, function(_error, stdout, stderr) {
expect(stdout).toBe('install\n');
done();
});
});
test('when alias subcommand file has no suffix then lookup succeeds', (done) => {
childProcess.exec(`node ${pm} i`, function(_error, stdout, stderr) {
expect(stdout).toBe('install\n');
done();
});
});
test('when subcommand target executablefile has no suffix then lookup succeeds', (done) => {
childProcess.exec(`node ${pm} specifyInstall`, function(_error, stdout, stderr) {
expect(stdout).toBe('install\n');
done();
});
});
test('when subcommand file suffix .js then lookup succeeds', (done) => {
childProcess.exec(`node ${pm} publish`, function(_error, stdout, stderr) {
expect(stdout).toBe('publish\n');
done();
});
});
test('when alias subcommand file suffix .js then lookup succeeds', (done) => {
childProcess.exec(`node ${pm} p`, function(_error, stdout, stderr) {
expect(stdout).toBe('publish\n');
done();
});
});
test('when subcommand target executablefile has suffix .js then lookup succeeds', (done) => {
childProcess.exec(`node ${pm} specifyPublish`, function(_error, stdout, stderr) {
expect(stdout).toBe('publish\n');
done();
});
});
testOrSkipOnWindows('when subcommand file is symlink then lookup succeeds', (done) => {
const pmlink = path.join(__dirname, 'fixtures', 'pmlink');
childProcess.exec(`node ${pmlink} install`, function(_error, stdout, stderr) {
expect(stdout).toBe('install\n');
done();
});
});
testOrSkipOnWindows('when subcommand file is double symlink then lookup succeeds', (done) => {
const pmlink = path.join(__dirname, 'fixtures', 'another-dir', 'pm');
childProcess.exec(`node ${pmlink} install`, function(_error, stdout, stderr) {
expect(stdout).toBe('install\n');
done();
});
});
test('when subcommand suffix is .ts then lookup succeeds', (done) => {
jest.setTimeout(20000); // Extend timeout for GitHub Actions
const binLinkTs = path.join(__dirname, 'fixtures-ts', 'pm.ts');
childProcess.execFile('node', ['-r', 'ts-node/register', binLinkTs, 'install'], function(_error, stdout, stderr) {
expect(stdout).toBe('install\n');
done();
});
});
test('when subsubcommand then lookup sub-sub-command', (done) => {
childProcess.exec(`node ${pm} cache clear`, function(_error, stdout, stderr) {
expect(stdout).toBe('cache-clear\n');
done();
});
});