Skip to content

Commit 031789f

Browse files
authored
test: add pnpm in pnp mode (#154)
* test: add pnpm in pnp mode * update pnpm * skip this test * add comment
1 parent 097ca5f commit 031789f

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
node-version: ${{ matrix.node-version }}
2121
cache: 'npm'
2222
- run: npm i -g yarn@1
23-
- run: npm i -g pnpm@8
23+
- run: npm i -g pnpm@10
2424
- run: npm ci
2525
- run: npx playwright install-deps
2626
- run: npm run build

playwright.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,11 @@ export default defineConfig<TestFixtures>({
5050
packageManager: 'pnpm'
5151
}
5252
},
53+
{
54+
name: 'pnpm-pnp',
55+
use: {
56+
packageManager: 'pnpm-pnp'
57+
}
58+
},
5359
]
5460
});

tests/baseFixtures.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import path from 'path';
2020
import fs from 'fs';
2121
import type { PromptOptions } from '../src/generator';
2222

23-
export type PackageManager = 'npm' | 'pnpm' | 'yarn-classic' | 'yarn-berry';
23+
export type PackageManager = 'npm' | 'pnpm' | 'pnpm-pnp' | 'yarn-classic' | 'yarn-berry';
2424

2525
const userAgents: Record<PackageManager, string | undefined> = {
2626
'yarn-classic': 'yarn/1.22.10',
2727
'yarn-berry': 'yarn/4.0.0',
2828
pnpm: 'pnpm/0.0.0',
29+
'pnpm-pnp': 'pnpm/0.0.0',
2930
npm: undefined,
3031
};
3132

@@ -59,9 +60,11 @@ function spawnAsync(cmd: string, args: string[], options?: SpawnOptionsWithoutSt
5960

6061
export const test = base.extend<TestFixtures>({
6162
packageManager: ['npm', { option: true }],
62-
dir: async ({}, use, testInfo) => {
63+
dir: async ({ packageManager }, use, testInfo) => {
6364
const dir = testInfo.outputDir;
6465
fs.mkdirSync(dir, { recursive: true });
66+
if (packageManager === 'pnpm-pnp')
67+
fs.writeFileSync(path.join(dir, '.npmrc'), 'node-linker=pnp');
6568
await use(dir);
6669
},
6770
exec: async ({ dir }, use, testInfo) => {
@@ -102,7 +105,7 @@ export function assertLockFilesExist(dir: string, packageManager: PackageManager
102105
expect(fs.existsSync(path.join(dir, 'package-lock.json'))).toBeTruthy();
103106
else if (packageManager.startsWith('yarn'))
104107
expect(fs.existsSync(path.join(dir, 'yarn.lock'))).toBeTruthy();
105-
else if (packageManager === 'pnpm')
108+
else if (packageManager.startsWith('pnpm'))
106109
expect(fs.existsSync(path.join(dir, 'pnpm-lock.yaml'))).toBeTruthy();
107110
}
108111

@@ -114,6 +117,7 @@ export function packageManagerToNpxCommand(packageManager: PackageManager): stri
114117
case 'yarn-berry':
115118
return 'yarn';
116119
case 'pnpm':
120+
case 'pnpm-pnp':
117121
return 'pnpm dlx';
118122
}
119123
}

tests/integration.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test('should generate a project in the current directory', async ({ run, dir, pa
4848
expect(stdout).toContain('Initializing Yarn project (yarn init -y)…');
4949
expect(stdout).toContain('Installing Playwright Test (yarn add --dev @playwright/test)…');
5050
expect(stdout).toContain('Installing Types (yarn add --dev @types/node)…');
51-
} else if (packageManager === 'pnpm') {
51+
} else if (packageManager === 'pnpm' || packageManager === 'pnpm-pnp') {
5252
expect(stdout).toContain('pnpm init'); // pnpm command outputs name in different case, hence we are not testing the whole string
5353
expect(stdout).toContain('Installing Playwright Test (pnpm add --save-dev @playwright/test)…');
5454
expect(stdout).toContain('Installing Types (pnpm add --save-dev @types/node)…');
@@ -98,7 +98,12 @@ test('should generate be able to run JS examples successfully', async ({ run, di
9898
});
9999

100100
test('should generate in the root of pnpm workspace', async ({ run, packageManager, exec }) => {
101-
test.skip(packageManager !== 'pnpm');
101+
test.skip(packageManager !== 'pnpm' && packageManager !== 'pnpm-pnp');
102+
103+
// not sure what's going wrong. removing pnpm-workspace.yaml would help, as discussed in https://github.com/pnpm/pnpm/issues/4129#issuecomment-2830362402.
104+
// but I don't understand PNPM enough to know whether that make the test meaningless.
105+
// disabling for now.
106+
test.fail(packageManager === 'pnpm-pnp', 'something is broken here');
102107

103108
const dir = test.info().outputDir;
104109
fs.mkdirSync(dir, { recursive: true });

0 commit comments

Comments
 (0)