forked from mozilla/web-ext
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.cli.run.js
137 lines (124 loc) · 3.83 KB
/
test.cli.run.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
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
import path from 'path';
import { writeFileSync } from 'fs';
import { describe, it } from 'mocha';
import { assert } from 'chai';
import {
minimalAddonPath,
fakeFirefoxPath,
withTempAddonDir,
execWebExt,
reportCommandErrors,
} from './common.js';
const EXPECTED_MESSAGE = 'Fake Firefox binary executed correctly.';
describe('web-ext run', () => {
it(
'accepts: --no-reload --watch-file --watch-files --source-dir ' +
'SRCDIR --firefox FXPATH --watch-ignored',
() =>
withTempAddonDir({ addonPath: minimalAddonPath }, (srcDir) => {
const watchedFile = path.join(srcDir, 'watchedFile.txt');
const watchedFilesArr = ['watchedFile1', 'watchedFile2'].map((file) =>
path.join(srcDir, file),
);
const watchIgnoredArr = ['ignoredFile1.txt', 'ignoredFile2.txt'].map(
(file) => path.join(srcDir, file),
);
const watchIgnoredFile = path.join(srcDir, 'ignoredFile3.txt');
writeFileSync(watchedFile, '');
watchedFilesArr.forEach((file) => writeFileSync(file, ''));
watchIgnoredArr.forEach((file) => writeFileSync(file, ''));
writeFileSync(watchIgnoredFile, '');
const argv = [
'run',
'--verbose',
'--no-reload',
'--source-dir',
srcDir,
'--watch-file',
watchedFile,
'--watch-files',
...watchedFilesArr,
'--firefox',
fakeFirefoxPath,
'--watch-ignored',
...watchIgnoredArr,
'--watch-ignored',
watchIgnoredFile,
];
const spawnOptions = {
env: {
EXPECTED_MESSAGE,
addonPath: srcDir,
// Add an environment var unrelated to the executed command to
// ensure we do clear the environment vars from them before
// yargs is validation the detected cli and env options.
// (See #793).
WEB_EXT_API_KEY: 'fake-api-key',
// Also include an environment var that misses the '_' separator
// between envPrefix and option name.
WEB_EXTAPI_SECRET: 'fake-secret',
},
};
const cmd = execWebExt(argv, spawnOptions);
return cmd.waitForExit.then(({ exitCode, stdout, stderr }) => {
if (stdout.indexOf(EXPECTED_MESSAGE) < 0) {
reportCommandErrors(
{
argv,
exitCode,
stdout,
stderr,
},
'The fake Firefox binary has not been executed',
);
} else if (exitCode !== 0) {
reportCommandErrors({
argv,
exitCode,
stdout,
stderr,
});
}
});
}),
);
it('should not accept: --watch-file <directory>', () =>
withTempAddonDir({ addonPath: minimalAddonPath }, (srcDir) => {
const argv = [
'run',
'--verbose',
'--source-dir',
srcDir,
'--watch-file',
srcDir,
'--firefox',
fakeFirefoxPath,
];
const spawnOptions = {
env: {
addonPath: srcDir,
},
};
return execWebExt(argv, spawnOptions).waitForExit.then(({ stderr }) => {
assert.match(stderr, /Invalid --watch-file value: .+ is not a file./);
});
}));
it('should not accept: --target INVALIDTARGET', async () => {
const argv = [
'run',
'--target',
'firefox-desktop',
'--target',
'firefox-android',
'--target',
'chromium',
'--target',
'not-supported',
];
return execWebExt(argv, {}).waitForExit.then(({ exitCode, stderr }) => {
assert.notEqual(exitCode, 0);
assert.match(stderr, /Invalid values/);
assert.match(stderr, /Given: "not-supported"/);
});
});
});