Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

5 changes: 0 additions & 5 deletions mise.toml

This file was deleted.

10 changes: 4 additions & 6 deletions packages/cli/snap-tests/command-doc/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

vitepress v<semver>

build complete in <variable>ms.


- building client + server bundles...
✓ building client + server bundles...
- rendering pages...
✓ rendering pages...
build complete in <variable>ms.


> vite doc build # build documentation again should hit the cache
✓ cache hit, replaying

vitepress v<semver>

build complete in <variable>ms.


- building client + server bundles...
✓ building client + server bundles...
- rendering pages...
✓ rendering pages...
build complete in <variable>ms.

10 changes: 5 additions & 5 deletions packages/cli/snap-tests/replay-logs-chronological-order/snap.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> vite run build 2>&1 # initial run, create the cache
> vite run build # initial run, create the cache
$ node build.js
[build.js] --------------------------------
[build.js] start
Expand Down Expand Up @@ -108,7 +108,7 @@ Task Details:
→ Cache miss: no previous cache entry found
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

> vite run build 2>&1 # should hit the cache
> vite run build # should hit the cache
$ node build.js (✓ cache hit, replaying)
[build.js] --------------------------------
[build.js] start
Expand Down Expand Up @@ -218,7 +218,7 @@ Task Details:
→ Cache hit - output replayed - <variable>ms saved
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

> vite run build 2>&1 # should hit the cache and make sure the replay order is chronological
> vite run build # should hit the cache and make sure the replay order is chronological
$ node build.js (✓ cache hit, replaying)
[build.js] --------------------------------
[build.js] start
Expand Down Expand Up @@ -328,7 +328,7 @@ Task Details:
→ Cache hit - output replayed - <variable>ms saved
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

> vite run build 2>&1 # should hit the cache and make sure the replay order is chronological again
> vite run build # should hit the cache and make sure the replay order is chronological again
$ node build.js (✓ cache hit, replaying)
[build.js] --------------------------------
[build.js] start
Expand Down Expand Up @@ -438,7 +438,7 @@ Task Details:
→ Cache hit - output replayed - <variable>ms saved
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

> vite run build 2>&1 # should hit the cache and make sure the replay order is chronological again
> vite run build # should hit the cache and make sure the replay order is chronological again
$ node build.js (✓ cache hit, replaying)
[build.js] --------------------------------
[build.js] start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"VITE_DISABLE_AUTO_INSTALL": "1"
},
"commands": [
"vite run build 2>&1 # initial run, create the cache",
"vite run build 2>&1 # should hit the cache",
"vite run build 2>&1 # should hit the cache and make sure the replay order is chronological",
"vite run build 2>&1 # should hit the cache and make sure the replay order is chronological again",
"vite run build 2>&1 # should hit the cache and make sure the replay order is chronological again"
"vite run build # initial run, create the cache",
"vite run build # should hit the cache",
"vite run build # should hit the cache and make sure the replay order is chronological",
"vite run build # should hit the cache and make sure the replay order is chronological again",
"vite run build # should hit the cache and make sure the replay order is chronological again"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,12 @@ packages:

[1]> vp add --filter app test-vite-plus-package-optional --save-catalog-name v1 # should error because save-catalog-name is not supported at pnpm@9
Running: pnpm --filter app add --save-catalog-name=v1 test-vite-plus-package-optional

 ERROR  Unknown option: 'save-catalog-name'
Did you mean 'save-optional'? Use "--config.unknown=value" to force an unknown option.
For help, run: pnpm help add

[1]> vp add --filter=./packages/utils test-vite-plus-package-optional -O --save-catalog v2 # should error because save-catalog is not supported at pnpm@9
Running: pnpm --filter ./packages/utils add --save-optional --save-catalog test-vite-plus-package-optional v2

 ERROR  Unknown option: 'save-catalog'
Did you mean 'save-exact', or 'save-prod'? Use "--config.unknown=value" to force an unknown option.
For help, run: pnpm help add
1 change: 0 additions & 1 deletion packages/global/snap-tests/command-add-pnpm9/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ Done in <variable>ms using pnpm v<semver>

[1]> vp add testnpm2 test-vite-plus-install --allow-build=test-vite-plus-install # should error because allow-build is not supported at pnpm@9
Running: pnpm add --allow-build=test-vite-plus-install testnpm2 test-vite-plus-install

 ERROR  Unknown option: 'allow-build'
For help, run: pnpm help add

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ up to date in <variable>ms

> vp up -D --filter app -- --no-audit && cat packages/app/package.json # should update dev dependencies in app
Running: npm update --workspace app --include=dev --no-audit
npm warn workspaces app in filter set, but no workspace folder present

up to date in <variable>ms
{
Expand All @@ -45,10 +46,10 @@ up to date in <variable>ms
}
}

npm warn workspaces app in filter set, but no workspace folder present

> vp update --filter "*" -- --no-audit && cat packages/app/package.json packages/utils/package.json # should update in all packages
Running: npm update --workspace * --no-audit
npm warn workspaces app in filter set, but no workspace folder present
npm warn workspaces @vite-plus-test/utils in filter set, but no workspace folder present

up to date in <variable>ms
{
Expand All @@ -69,11 +70,10 @@ up to date in <variable>ms
}
}

npm warn workspaces app in filter set, but no workspace folder present
npm warn workspaces @vite-plus-test/utils in filter set, but no workspace folder present

> vp update -r --no-save -- --no-audit && cat package.json packages/app/package.json # should update recursively without saving
Running: npm update --include-workspace-root --workspaces --no-save --no-audit
npm warn workspaces app in filter set, but no workspace folder present
npm warn workspaces @vite-plus-test/utils in filter set, but no workspace folder present

up to date in <variable>ms
{
Expand All @@ -98,9 +98,6 @@ up to date in <variable>ms
}
}

npm warn workspaces app in filter set, but no workspace folder present
npm warn workspaces @vite-plus-test/utils in filter set, but no workspace folder present

> vp update --workspace --filter app @vite-plus-test/utils -- --no-audit && cat packages/app/package.json # should update workspace dependency
Running: npm update --workspace app --no-audit @vite-plus-test/utils

Expand Down
9 changes: 4 additions & 5 deletions packages/global/snap-tests/command-update-npm10/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ Running: npm install --save-optional --no-audit testnpm2@<semver>
added 1 package in <variable>ms
Warning: npm doesn't support --latest flag. Updating within semver range only.
Running: npm update --no-optional --no-audit
npm warn config optional Use `--omit=optional` to exclude optional dependencies, or
npm warn config `--include=optional` to include them.
npm warn config
npm warn config Default value does install optional deps unless otherwise omitted.

changed 1 package in <variable>ms
{
Expand All @@ -99,11 +103,6 @@ changed 1 package in <variable>ms
}
}

npm warn config optional Use `--omit=optional` to exclude optional dependencies, or
npm warn config `--include=optional` to include them.
npm warn config
npm warn config Default value does install optional deps unless otherwise omitted.

> vp update -- --no-audit && cat package.json # should update all packages but won't change the package.json
Running: npm update --no-audit

Expand Down
6 changes: 5 additions & 1 deletion packages/tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
"devDependencies": {
"@oxc-node/cli": "catalog:",
"@oxc-node/core": "catalog:",
"@types/semver": "catalog:",
"@std/yaml": "catalog:",
"@types/semver": "catalog:",
"minimatch": "catalog:",
"semver": "catalog:"
},
"scripts": {
"snap-test": "tool snap-test"
},
"dependencies": {
"@yarnpkg/fslib": "catalog:",
"@yarnpkg/shell": "catalog:"
}
}
78 changes: 51 additions & 27 deletions packages/tools/src/snap-test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import cp from 'node:child_process';
import { npath } from '@yarnpkg/fslib';
import { execute } from '@yarnpkg/shell';
import { randomUUID } from 'node:crypto';
import fs from 'node:fs';
import fs, { readFileSync } from 'node:fs';
import fsPromises from 'node:fs/promises';
import { open } from 'node:fs/promises';
import { cpus, tmpdir } from 'node:os';
import path from 'node:path';
import { debuglog, parseArgs, promisify } from 'node:util';
import { debuglog, parseArgs } from 'node:util';

import { isPassThroughEnv, replaceUnstableOutput } from './utils';

const debug = debuglog('vite-plus/snap-test');
const cpExec = promisify(cp.exec);
const exec = async (command: string, options: cp.ExecOptionsWithStringEncoding) =>
cpExec(
command,
process.platform === 'win32' ? { ...options, shell: 'pwsh.exe' } : options,
);

// Remove comments (starting with ' #') from command strings
// `@yarnpkg/shell` doesn't parse comments.
// This doesn't handle all edge cases (such as ' #' in quoted strings), but is good enough for our test cases.
function stripComments(command: string): string {
if (command.trim().startsWith('#')) {
return '';
}
const commentStart = command.indexOf(' #');
return commentStart === -1 ? command : command.slice(0, commentStart);
Comment thread
branchseer marked this conversation as resolved.
}

/**
* Run tasks with limited concurrency based on CPU count.
Expand Down Expand Up @@ -142,26 +149,43 @@ async function runTestCase(name: string, tempTmpDir: string, casesDir: string) {

const newSnap: string[] = [];

const cwd = npath.toPortablePath(caseTmpDir);
for (const command of steps.commands) {
debug('running command: %s, cwd: %s, env: %o', command, caseTmpDir, env);
try {
const { stdout, stderr } = await exec(command, { env, cwd: caseTmpDir, encoding: 'utf-8' });
newSnap.push(`> ${command}`);
if (stdout) {
newSnap.push(replaceUnstableOutput(stdout, caseTmpDir));
}
if (stderr) {
newSnap.push(replaceUnstableOutput(stderr, caseTmpDir));
}
} catch (error: any) {
// add error exit code to the command
newSnap.push(`[${error.code}]> ${command}`);
if (error.stdout) {
newSnap.push(replaceUnstableOutput(error.stdout, caseTmpDir));
}
if (error.stderr) {
newSnap.push(replaceUnstableOutput(error.stderr, caseTmpDir));
}

// While `@yarnpkg/shell` supports capturing output via in-memory `Writable` streams,
// it seems not to have stable ordering of stdout/stderr chunks.
// To ensure stable ordering, we redirect outputs to a file instead.
const outputStreamPath = path.join(caseTmpDir, 'output.log');
const outputStream = await open(outputStreamPath, 'w');

const exitCode = await execute(stripComments(command), [], {
env,
cwd,
stdin: null,
// Declared to be `Writable` but `FileHandle` works too.
// @ts-expect-error
stderr: outputStream,
// @ts-expect-error
stdout: outputStream,
glob: {
// Disable glob expansion. Pass args like '--filter=*' as-is.
isGlobPattern: () => false,
match: async () => [],
},
});

await outputStream.close();

const output = readFileSync(outputStreamPath, 'utf-8');
Comment thread
branchseer marked this conversation as resolved.

let commandLine = `> ${command}`;
if (exitCode !== 0) {
commandLine = `[${exitCode}]` + commandLine;
}
newSnap.push(commandLine);
if (output.length > 0) {
newSnap.push(replaceUnstableOutput(output, caseTmpDir));
}
}
const newSnapContent = newSnap.join('\n');
Expand Down
Loading
Loading