Skip to content

Commit 0d34ece

Browse files
committed
feat(tools): ignore pnpm install unstable ouutput
and ignore cwd too
1 parent 15bb6ca commit 0d34ece

10 files changed

Lines changed: 621 additions & 486 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ jobs:
143143

144144
- name: Run CLI E2E tests
145145
run: |
146-
pnpm run --filter=@voidzero-dev/vite-plus --filter=@voidzero-dev/global test
146+
pnpm run --filter=@voidzero-dev/vite-plus --filter=@voidzero-dev/global snap-test
147147
git diff --exit-code
148148
149149
install-e2e-test:

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"install-global-cli": "npm install -g ./packages/global",
1010
"typecheck": "tsc -b tsconfig.json",
1111
"lint": "vite lint",
12-
"test": "pnpm -r test",
12+
"test": "vitest run && pnpm -r snap-test",
1313
"prepare": "husky"
1414
},
1515
"devDependencies": {
@@ -20,7 +20,8 @@
2020
"husky": "^9.1.7",
2121
"lint-staged": "^16.1.6",
2222
"oxlint": "catalog:",
23-
"typescript": "catalog:"
23+
"typescript": "catalog:",
24+
"vitest": "catalog:"
2425
},
2526
"lint-staged": {
2627
"*.@(js|ts|tsx|yml|yaml|md|json|html|toml)": [

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"build": "pnpm run build:binding && pnpm run build:ts",
2323
"build:binding": "napi build --package-json-path ../package.json --cwd binding --platform --release --esm",
2424
"build:ts": "tsdown",
25-
"test": "snap-test"
25+
"snap-test": "snap-test"
2626
},
2727
"files": [
2828
"bin",

packages/global/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"scripts": {
2020
"dev": "tsdown --watch",
2121
"build": "tsdown",
22-
"test": "snap-test"
22+
"snap-test": "snap-test"
2323
},
2424
"dependencies": {
2525
"oxlint": "catalog:",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`replaceUnstableOutput > replace unstable cwd 1`] = `"<cwd>/foo.txt"`;
4+
5+
exports[`replaceUnstableOutput > replace unstable pnpm install output 1`] = `
6+
"Scope: all <variable> workspace projects
7+
Packages: +<variable>
8+
+<repeat>
9+
Progress: resolved <variable>, reused <variable>, downloaded <variable>, added <variable>, done"
10+
`;
11+
12+
exports[`replaceUnstableOutput > replace unstable pnpm install output 2`] = `
13+
"Scope: all <variable> workspace projects
14+
Lockfile is up to date, resolution step is skipped
15+
Already up to date
16+
17+
╭ Warning ───────────────────────────────────────────────────────────────────────────────────╮
18+
│ │
19+
│ Ignored build scripts: esbuild. │
20+
│ Run "pnpm approve-builds" to pick which dependencies should be allowed to run scripts. │
21+
│ │
22+
╰────────────────────────────────────────────────────────────────────────────────────────────╯
23+
24+
Done in <variable>ms using pnpm v<semver>"
25+
`;
26+
27+
exports[`replaceUnstableOutput > replace unstable semver version 1`] = `
28+
"v1.0.0
29+
v1.0.0-beta.1
30+
v1.0.0-beta.1+build.1
31+
1.0.0
32+
1.0.0-beta.1
33+
1.0.0-beta.1+build.1"
34+
`;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { tmpdir } from 'node:os';
2+
3+
import { describe, expect, test } from 'vitest';
4+
5+
import { replaceUnstableOutput } from '../utils.ts';
6+
7+
describe('replaceUnstableOutput', () => {
8+
test('replace unstable semver version', () => {
9+
const output = `
10+
v1.0.0
11+
v1.0.0-beta.1
12+
v1.0.0-beta.1+build.1
13+
1.0.0
14+
1.0.0-beta.1
15+
1.0.0-beta.1+build.1
16+
`;
17+
expect(replaceUnstableOutput(output.trim())).toMatchSnapshot();
18+
});
19+
20+
test('replace unstable pnpm install output', () => {
21+
const outputs = [
22+
`
23+
Scope: all 6 workspace projects
24+
Packages: +312
25+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26+
Progress: resolved 462, reused 324, downloaded 0, added 312, done
27+
`,
28+
`
29+
Scope: all 2 workspace projects
30+
Lockfile is up to date, resolution step is skipped
31+
Already up to date
32+
33+
╭ Warning ───────────────────────────────────────────────────────────────────────────────────╮
34+
│ │
35+
│ Ignored build scripts: esbuild. │
36+
│ Run "pnpm approve-builds" to pick which dependencies should be allowed to run scripts. │
37+
│ │
38+
╰────────────────────────────────────────────────────────────────────────────────────────────╯
39+
40+
Done in 171ms using pnpm v10.16.1
41+
`,
42+
];
43+
for (const output of outputs) {
44+
expect(replaceUnstableOutput(output.trim())).toMatchSnapshot();
45+
}
46+
});
47+
48+
test('replace unstable cwd', () => {
49+
const cwd = tmpdir();
50+
const output = `${cwd}/foo.txt`;
51+
expect(replaceUnstableOutput(output.trim(), cwd)).toMatchSnapshot();
52+
});
53+
});

packages/tools/src/snap-test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import fs from 'node:fs';
66
import { tmpdir } from 'node:os';
77
import path from 'node:path';
88

9+
import { replaceUnstableOutput } from './utils.ts';
10+
911
// Create a unique temporary directory for testing
1012
const tempTmpDir = `${tmpdir()}/vite-plus-test-${randomUUID()}`;
1113
fs.mkdirSync(tempTmpDir, { recursive: true });
@@ -43,24 +45,19 @@ function runTestCase(name: string) {
4345
VITE_PLUS_CLI_TEST: '1',
4446
};
4547
env['PATH'] = [
46-
...env['PATH']!.split(path.delimiter),
4748
// Extend PATH to include the package's bin directory
48-
path.resolve('bin')
49+
path.resolve('bin'),
50+
...env['PATH']!.split(path.delimiter),
4951
].join(path.delimiter);
5052

5153
const newSnap: string[] = [];
5254

5355
for (const command of steps.commands) {
5456
newSnap.push(`> ${command}`);
5557
const output = cp.execSync(command, { env, cwd: caseTmpDir, encoding: 'utf-8' });
56-
newSnap.push(replaceUnstableOutput(output));
58+
newSnap.push(replaceUnstableOutput(output, caseTmpDir));
5759
}
5860
const newSnapContent = newSnap.join('\n');
5961

6062
fs.writeFileSync(`${casesDir}/${name}/snap.txt`, newSnapContent);
6163
}
62-
63-
function replaceUnstableOutput(output: string) {
64-
return output.replace(/\d+(?:\.\d+)?s|\d+ms/, '<variable>ms')
65-
.replace(/with \d+ rules using \d+ threads/, 'with <variable> rules using <variable> threads');
66-
}

packages/tools/src/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export function replaceUnstableOutput(output: string, cwd?: string) {
2+
if (cwd) {
3+
output = output.replaceAll(cwd, '<cwd>');
4+
}
5+
return output
6+
// semver version
7+
.replaceAll(/ (v)?\d+\.\d+\.\d+(?:-.*)?/g, ' $1<semver>')
8+
// oxlint
9+
.replaceAll(/\d+(?:\.\d+)?s|\d+ms/g, '<variable>ms')
10+
.replaceAll(/with \d+ rules using \d+ threads/g, 'with <variable> rules using <variable> threads')
11+
// pnpm
12+
.replaceAll(/Packages: \+\d+/g, 'Packages: +<variable>')
13+
.replaceAll(
14+
/Progress: resolved \d+, reused \d+, downloaded \d+, added \d+, done/g,
15+
'Progress: resolved <variable>, reused <variable>, downloaded <variable>, added <variable>, done',
16+
)
17+
.replaceAll(/Scope: all \d+ workspace projects/g, 'Scope: all <variable> workspace projects')
18+
.replaceAll(/\++\n/g, '+<repeat>\n');
19+
}

0 commit comments

Comments
 (0)