-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcli-integration-test.js
56 lines (45 loc) · 1.61 KB
/
cli-integration-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
const path = require('path');
const { writeFileSync, readFileSync } = require('fs');
const { execSync } = require('child_process');
function main() {
{
const targetFilePath = path.join(__dirname, 'remove-debugger-test1.ts');
writeFileSync(targetFilePath, `function hello() { debugger; }`);
execSync(
`npx --yes @hypermod/cli@latest --packages javascript#remove-debugger --verbose="0" ${targetFilePath}`,
{ stdio: 'inherit' },
);
const targetFileOutput = readFileSync(targetFilePath, 'utf-8');
const expectedFileOutput = `function hello() {}`;
if (targetFileOutput !== expectedFileOutput) {
throw new Error(
`Expected ${targetFileOutput} to equal ${expectedFileOutput}`,
);
}
console.log('RESULT -------------');
console.log('Correctly removed debugger statement');
}
{
const targetFilePath = path.join(__dirname, 'remove-unused-vars-test2.ts');
writeFileSync(
targetFilePath,
`export function hello() { var a = 1; debugger; }`,
);
execSync(
`npx --yes @hypermod/cli@latest --packages javascript#remove-unused-vars --experimental-loader --verbose="0" ${targetFilePath}`,
{ stdio: 'inherit' },
);
const targetFileOutput = readFileSync(targetFilePath, 'utf-8');
const expectedFileOutput = `export function hello() {
debugger;
}`;
if (targetFileOutput !== expectedFileOutput) {
throw new Error(
`Expected ${targetFileOutput} to equal ${expectedFileOutput}`,
);
}
console.log('RESULT -------------');
console.log('Correctly removed unused var statement');
}
}
main();