|
| 1 | +const path = require('path'); |
| 2 | +const { writeFileSync, readFileSync } = require('fs'); |
| 3 | +const { execSync } = require('child_process'); |
| 4 | + |
| 5 | +function main() { |
| 6 | + { |
| 7 | + const targetFilePath = path.join(__dirname, 'remove-debugger-test1.ts'); |
| 8 | + writeFileSync(targetFilePath, `function hello() { debugger; }`); |
| 9 | + |
| 10 | + execSync( |
| 11 | + `npx --yes @hypermod/cli@latest --packages javascript#remove-debugger ${targetFilePath}`, |
| 12 | + { stdio: 'inherit' }, |
| 13 | + ); |
| 14 | + |
| 15 | + const targetFileOutput = readFileSync(targetFilePath, 'utf-8'); |
| 16 | + const expectedFileOutput = `function hello() {}`; |
| 17 | + |
| 18 | + if (targetFileOutput !== expectedFileOutput) { |
| 19 | + throw new Error( |
| 20 | + `Expected ${targetFileOutput} to equal ${expectedFileOutput}`, |
| 21 | + ); |
| 22 | + } |
| 23 | + |
| 24 | + console.log('RESULT -------------'); |
| 25 | + console.log('Correctly removed debugger statement'); |
| 26 | + } |
| 27 | + |
| 28 | + { |
| 29 | + const targetFilePath = path.join(__dirname, 'remove-unused-vars-test2.ts'); |
| 30 | + writeFileSync(targetFilePath, `function hello() { var a = 1; debugger; }`); |
| 31 | + |
| 32 | + execSync( |
| 33 | + `npx --yes @hypermod/cli@latest --packages javascript#remove-unused-vars --experimental-loader ${targetFilePath}`, |
| 34 | + { stdio: 'inherit' }, |
| 35 | + ); |
| 36 | + |
| 37 | + const targetFileOutput = readFileSync(targetFilePath, 'utf-8'); |
| 38 | + const expectedFileOutput = `function hello() { debugger; }`; |
| 39 | + |
| 40 | + if (targetFileOutput !== expectedFileOutput) { |
| 41 | + throw new Error( |
| 42 | + `Expected ${targetFileOutput} to equal ${expectedFileOutput}`, |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + console.log('RESULT -------------'); |
| 47 | + console.log('Correctly removed unused var statement'); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +main(); |
0 commit comments