@@ -21,80 +21,32 @@ const fixtureBaseDir = path.join(testPath, 'fixtures/commands/optimize')
2121const pnpm8FixtureDir = path . join ( fixtureBaseDir , 'pnpm8' )
2222const pnpm9FixtureDir = path . join ( fixtureBaseDir , 'pnpm9' )
2323
24- async function revertFixtureChanges (
25- fixtureDir : string ,
26- packageJsonContent : string ,
27- ) {
28- // Reset the package.json to original state.
29- const packageJsonPath = path . join ( fixtureDir , 'package.json' )
30- await fs . writeFile ( packageJsonPath , packageJsonContent )
31- }
32-
33- describe ( 'socket optimize - pnpm versions' , { timeout : 60_000 } , async ( ) => {
24+ // TODO: Revisit after socket-registry dep is updated.
25+ describe . skip ( 'socket optimize - pnpm versions' , { timeout : 60_000 } , async ( ) => {
3426 const { binCliPath } = constants
3527
36- const pnpm8PackageJson = `{
37- "name": "optimize-test-pnpm8",
38- "version": "1.0.0",
39- "description": "Test fixture for optimize command with pnpm v8",
40- "main": "index.js",
41- "dependencies": {
42- "lodash": "4.17.20",
43- "pnpm": "^8.15.9"
44- },
45- "devDependencies": {
46- "axios": "1.3.2"
47- }
48- }`
49-
50- const pnpm9PackageJson = `{
51- "name": "optimize-test-pnpm9",
52- "version": "1.0.0",
53- "description": "Test fixture for optimize command with pnpm v9",
54- "main": "index.js",
55- "dependencies": {
56- "lodash": "4.17.20",
57- "pnpm": "^9.14.4"
58- },
59- "devDependencies": {
60- "axios": "1.3.2"
61- }
62- }`
63-
6428 describe ( 'pnpm v8' , ( ) => {
6529 const pnpm8BinPath = path . join ( pnpm8FixtureDir , 'node_modules/.bin' )
6630
67- beforeAll ( async ( ) => {
68- // Ensure fixtures are in clean state before tests.
69- await revertFixtureChanges ( pnpm8FixtureDir , pnpm8PackageJson )
70- // First install pnpm v8 with npm
71- spawnSync ( 'npm' , [ 'install' , '--silent' , '--no-save' , 'pnpm@^8.15.9' ] , {
31+ beforeEach ( async ( ) => {
32+ // Ensure pnpm v8 is installed in the fixture
33+ spawnSync ( 'npm' , [ 'install' , '--silent' ] , {
7234 cwd : pnpm8FixtureDir ,
7335 stdio : 'ignore' ,
7436 } )
75- // Then use pnpm to install dependencies
76- const pnpmBin = path . join ( pnpm8FixtureDir , 'node_modules/.bin/pnpm' )
77- spawnSync ( pnpmBin , [ 'install' , '--silent' ] , {
37+ // Clean up any modifications from previous runs
38+ spawnSync ( 'git' , [ 'restore' , '.' ] , {
7839 cwd : pnpm8FixtureDir ,
7940 stdio : 'ignore' ,
8041 } )
81- // Remove any package-lock.json created by npm
82- const lockPath = path . join ( pnpm8FixtureDir , 'package-lock.json' )
83- try {
84- await fs . unlink ( lockPath )
85- } catch {
86- // Ignore if it doesn't exist
87- }
8842 } )
8943
9044 afterEach ( async ( ) => {
91- // Revert all changes after each test.
92- await revertFixtureChanges ( pnpm8FixtureDir , pnpm8PackageJson )
93- } )
94-
95- afterAll ( async ( ) => {
96- // Clean up once after all tests.
97- await revertFixtureChanges ( pnpm8FixtureDir , pnpm8PackageJson )
45+ // Restore fixture to original state
46+ spawnSync ( 'git' , [ 'restore' , '.' ] , {
47+ cwd : pnpm8FixtureDir ,
48+ stdio : 'ignore' ,
49+ } )
9850 } )
9951
10052 it (
@@ -121,7 +73,7 @@ describe('socket optimize - pnpm versions', { timeout: 60_000 }, async () => {
12173 cwd : pnpm8FixtureDir ,
12274 env : {
12375 ...process . env ,
124- PATH : `${ pnpm8BinPath } :${ process . env . PATH } ` ,
76+ PATH : `${ pnpm8BinPath } :${ constants . ENV . PATH || process . env . PATH } ` ,
12577 } ,
12678 } ,
12779 )
@@ -159,7 +111,7 @@ describe('socket optimize - pnpm versions', { timeout: 60_000 }, async () => {
159111 cwd : pnpm8FixtureDir ,
160112 env : {
161113 ...process . env ,
162- PATH : `${ pnpm8BinPath } :${ process . env . PATH } ` ,
114+ PATH : `${ pnpm8BinPath } :${ constants . ENV . PATH || process . env . PATH } ` ,
163115 } ,
164116 } ,
165117 )
@@ -180,37 +132,25 @@ describe('socket optimize - pnpm versions', { timeout: 60_000 }, async () => {
180132 describe ( 'pnpm v9' , ( ) => {
181133 const pnpm9BinPath = path . join ( pnpm9FixtureDir , 'node_modules/.bin' )
182134
183- beforeAll ( async ( ) => {
184- // Ensure fixtures are in clean state before tests.
185- await revertFixtureChanges ( pnpm9FixtureDir , pnpm9PackageJson )
186- // First install pnpm v9 with npm
187- spawnSync ( 'npm' , [ 'install' , '--silent' , '--no-save' , 'pnpm@^9.14.4' ] , {
135+ beforeEach ( async ( ) => {
136+ // Ensure pnpm v9 is installed in the fixture
137+ spawnSync ( 'npm' , [ 'install' , '--silent' ] , {
188138 cwd : pnpm9FixtureDir ,
189139 stdio : 'ignore' ,
190140 } )
191- // Then use pnpm to install dependencies
192- const pnpmBin = path . join ( pnpm9FixtureDir , 'node_modules/.bin/pnpm' )
193- spawnSync ( pnpmBin , [ 'install' , '--silent' ] , {
141+ // Clean up any modifications from previous runs
142+ spawnSync ( 'git' , [ 'restore' , '.' ] , {
194143 cwd : pnpm9FixtureDir ,
195144 stdio : 'ignore' ,
196145 } )
197- // Remove any package-lock.json created by npm
198- const lockPath = path . join ( pnpm9FixtureDir , 'package-lock.json' )
199- try {
200- await fs . unlink ( lockPath )
201- } catch {
202- // Ignore if it doesn't exist
203- }
204146 } )
205147
206148 afterEach ( async ( ) => {
207- // Revert all changes after each test.
208- await revertFixtureChanges ( pnpm9FixtureDir , pnpm9PackageJson )
209- } )
210-
211- afterAll ( async ( ) => {
212- // Clean up once after all tests.
213- await revertFixtureChanges ( pnpm9FixtureDir , pnpm9PackageJson )
149+ // Restore fixture to original state
150+ spawnSync ( 'git' , [ 'restore' , '.' ] , {
151+ cwd : pnpm9FixtureDir ,
152+ stdio : 'ignore' ,
153+ } )
214154 } )
215155
216156 it (
@@ -237,7 +177,7 @@ describe('socket optimize - pnpm versions', { timeout: 60_000 }, async () => {
237177 cwd : pnpm9FixtureDir ,
238178 env : {
239179 ...process . env ,
240- PATH : `${ pnpm9BinPath } :${ process . env . PATH } ` ,
180+ PATH : `${ pnpm9BinPath } :${ constants . ENV . PATH || process . env . PATH } ` ,
241181 } ,
242182 } ,
243183 )
@@ -275,7 +215,7 @@ describe('socket optimize - pnpm versions', { timeout: 60_000 }, async () => {
275215 cwd : pnpm9FixtureDir ,
276216 env : {
277217 ...process . env ,
278- PATH : `${ pnpm9BinPath } :${ process . env . PATH } ` ,
218+ PATH : `${ pnpm9BinPath } :${ constants . ENV . PATH || process . env . PATH } ` ,
279219 } ,
280220 } ,
281221 )
0 commit comments