Skip to content

Commit 2ddac25

Browse files
committed
refactor(snap-test): extract npm global prefix dir name into constant
1 parent 3f5913d commit 2ddac25

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/tools/src/snap-test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ function selectShard<T>(items: T[], index: number, total: number): T[] {
9090
return items.slice(start, start + chunkSize);
9191
}
9292

93+
const NPM_GLOBAL_PREFIX_DIR = 'npm-global-lib-for-snap-tests';
94+
9395
export async function snapTest() {
9496
const { positionals, values } = parseArgs({
9597
allowPositionals: true,
@@ -113,7 +115,7 @@ export async function snapTest() {
113115
fs.mkdirSync(tempTmpDir, { recursive: true });
114116
// Pre-create the npm global prefix directory so tests using npm global
115117
// operations (link, outdated -g, etc.) don't fail with ENOENT.
116-
fs.mkdirSync(path.join(tempTmpDir, 'npm-global-lib-for-snap-tests', 'lib'), { recursive: true });
118+
fs.mkdirSync(path.join(tempTmpDir, NPM_GLOBAL_PREFIX_DIR, 'lib'), { recursive: true });
117119

118120
// Clean up stale .node-version and package.json in the system temp directory.
119121
// vite-plus walks up the directory tree to resolve Node.js versions, so leftover
@@ -359,7 +361,7 @@ async function runTestCase(name: string, tempTmpDir: string, casesDir: string, b
359361
// Skip `vp install` inside `vp migrate` — snap tests don't need real installs
360362
VP_SKIP_INSTALL: '1',
361363
// make sure npm install global packages to the temporary directory
362-
NPM_CONFIG_PREFIX: path.join(tempTmpDir, 'npm-global-lib-for-snap-tests'),
364+
NPM_CONFIG_PREFIX: path.join(tempTmpDir, NPM_GLOBAL_PREFIX_DIR),
363365

364366
// A test case can override/unset environment variables above.
365367
// For example, VP_CLI_TEST/CI can be unset to test the real-world outputs.

0 commit comments

Comments
 (0)