Skip to content

Commit 61c9596

Browse files
author
Daniel Del Core
committed
Adds cli integration test action/script
1 parent d68d0e8 commit 61c9596

File tree

5 files changed

+79
-6
lines changed

5 files changed

+79
-6
lines changed

.changeset/fifty-apes-travel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hypermod/cli': patch
3+
---
4+
5+
Experimental loader will now install deps relative to the CLI source files
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Test
2+
3+
on:
4+
schedule:
5+
- cron: '0 3 * * 1-5'
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
strategy:
12+
matrix:
13+
node-version: [16.x]
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Use Node.js ${{ matrix.node-version }}
18+
uses: actions/setup-node@v1
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
- run: node scripts/cli-integration-test.js

packages/cli/src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { mergeConfigs } from './utils/merge-configs';
1717
import { getConfigPrompt, getMultiConfigPrompt } from './prompt';
1818

1919
const ExperimentalModuleLoader = () => ({
20-
install: async (packageName: string) => await installPackage(packageName),
20+
install: async (packageName: string) =>
21+
await installPackage(packageName, { cwd: __dirname }),
2122
require: (packageName: string) => require(packageName),
2223
getInfo: (packageName: string) => ({
2324
location: require.resolve(packageName),

scripts/cli-integration-test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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();

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,11 +3568,6 @@ color-name@~1.1.4:
35683568
resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz"
35693569
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
35703570

3571-
colors@1.4.0:
3572-
version "1.4.0"
3573-
resolved "https://packages.atlassian.com/api/npm/npm-remote/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
3574-
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
3575-
35763571
combined-stream@^1.0.8:
35773572
version "1.0.8"
35783573
resolved "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz"

0 commit comments

Comments
 (0)