1
1
import fs from 'node:fs'
2
- import { execSync } from 'node:child_process '
2
+ import { inject } from 'vitest '
3
3
import { createTeardown } from 'fs-teardown'
4
4
import { fromTemp } from '../support/utils'
5
- import * as packageJson from '../../package.json'
5
+
6
+ const tarballPath = inject ( 'tarballPath' )
6
7
7
8
const fsMock = createTeardown ( {
8
9
rootDir : fromTemp ( 'worker-script-auto-update' ) ,
@@ -38,15 +39,8 @@ describe(
38
39
} ) ,
39
40
} )
40
41
41
- // Pack the current state of the "msw" package.
42
- execSync ( `pnpm pack --pack-destination ${ fsMock . resolve ( '.' ) } ` , {
43
- stdio : [ null , null , 'inherit' ] ,
44
- } )
45
-
46
42
// Install "msw" from the tarball into the dummy project.
47
- const installCommand = await fsMock . exec (
48
- `npm install msw-${ packageJson . version } .tgz` ,
49
- )
43
+ const installCommand = await fsMock . exec ( `npm install ${ tarballPath } ` )
50
44
expect ( installCommand . stderr ) . toBe ( '' )
51
45
52
46
// Asset the worker script has been created/updated.
@@ -65,13 +59,7 @@ describe(
65
59
} ) ,
66
60
} )
67
61
68
- execSync ( `pnpm pack --pack-destination ${ fsMock . resolve ( '.' ) } ` , {
69
- stdio : [ null , null , 'inherit' ] ,
70
- } )
71
-
72
- const installCommand = await fsMock . exec (
73
- `npm install msw-${ packageJson . version } .tgz` ,
74
- )
62
+ const installCommand = await fsMock . exec ( `npm install ${ tarballPath } ` )
75
63
/**
76
64
* @note Cannot assert on the empty stderr because npm
77
65
* writes to stderr if there's a new version of npm available.
0 commit comments