From a55f585fcfebb905b74d02fa736f3e90343b6baa Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 17 Feb 2025 16:04:19 +0100 Subject: [PATCH 1/4] execute one after another --- .github/workflows/ci.yml | 5 +++-- playwright.config.ts | 6 +++--- tests/baseFixtures.ts | 11 +++++------ tests/integration.spec.ts | 12 +++++++++++- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index feff784..22fefbc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,11 +19,12 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: 'npm' - - run: npm i -g yarn@latest - run: npm i -g yarn@1 - run: npm i -g pnpm@8 - run: npm ci - run: npx playwright install-deps - run: npm run build - run: npx tsc --noEmit - - run: npm run test + - run: npm run test -- --project=npm --project=pnpm --project=yarn-classic + - run: yarn set version stable + - run: npm run test -- --project=yarn-berry diff --git a/playwright.config.ts b/playwright.config.ts index 18fbc68..ecc95da 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -35,13 +35,13 @@ export default defineConfig({ { name: 'yarn-classic', use: { - packageManager: 'npx yarn@1' + packageManager: 'yarn-classic' } }, { - name: 'yarn', + name: 'yarn-berry', use: { - packageManager: 'yarn' + packageManager: 'yarn-berry' } }, { diff --git a/tests/baseFixtures.ts b/tests/baseFixtures.ts index be5dbe9..c43ad29 100644 --- a/tests/baseFixtures.ts +++ b/tests/baseFixtures.ts @@ -20,7 +20,7 @@ import path from 'path'; import fs from 'fs'; import type { PromptOptions } from '../src/generator'; -export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'npx yarn@1'; +export type PackageManager = 'npm' | 'pnpm' | 'yarn-classic' | 'yarn-berry'; export type TestFixtures = { packageManager: PackageManager; @@ -82,7 +82,7 @@ export const test = base.extend({ cwd: dir, env: { ...process.env, - 'npm_config_user_agent': packageManager === 'yarn' ? 'yarn' : packageManager === 'pnpm' ? 'pnpm/0.0.0' : undefined, + 'npm_config_user_agent': packageManager.startsWith('yarn') ? 'yarn' : packageManager === 'pnpm' ? 'pnpm/0.0.0' : undefined, 'TEST_OPTIONS': JSON.stringify(options), }, }); @@ -94,7 +94,7 @@ export function assertLockFilesExist(dir: string, packageManager: PackageManager expect(fs.existsSync(path.join(dir, 'package.json'))).toBeTruthy(); if (packageManager === 'npm') expect(fs.existsSync(path.join(dir, 'package-lock.json'))).toBeTruthy(); - else if (packageManager === 'yarn') + else if (packageManager.startsWith('yarn')) expect(fs.existsSync(path.join(dir, 'yarn.lock'))).toBeTruthy(); else if (packageManager === 'pnpm') expect(fs.existsSync(path.join(dir, 'pnpm-lock.yaml'))).toBeTruthy(); @@ -104,10 +104,9 @@ export function packageManagerToNpxCommand(packageManager: PackageManager): stri switch (packageManager) { case 'npm': return 'npx'; - case 'yarn': + case 'yarn-classic': + case 'yarn-berry': return 'yarn'; - case 'npx yarn@1': - return 'npx yarn@1'; case 'pnpm': return 'pnpm dlx'; } diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index 865b737..0b099b8 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -115,7 +115,7 @@ test('should generate in the root of pnpm workspace', async ({ run, packageManag }); test('should generate in the root of yarn workspaces', async ({ run, packageManager }) => { - test.skip(packageManager !== 'npx yarn@1'); + test.skip(packageManager !== 'yarn-classic'); const dir = test.info().outputDir; fs.mkdirSync(dir, { recursive: true }); @@ -168,3 +168,13 @@ test('should install with "npm i" in GHA when using npm with package-lock disabl expect(workflowContent).toContain('run: npm i'); expect(workflowContent).not.toContain('run: npm ci'); }); + +test('is proper yarn classic', async ({ packageManager }) => { + test.skip(packageManager !== 'yarn-classic'); + expect(childProcess.execSync('yarn --version', { encoding: 'utf-8' })).toMatch(/^1\./); +}); + +test('is proper yarn berry', async ({ packageManager }) => { + test.skip(packageManager !== 'yarn-berry'); + expect(childProcess.execSync('yarn --version', { encoding: 'utf-8' })).toMatch(/^4\./); +}); \ No newline at end of file From 6ff3c095d65f20106abcdcf03ca29181362846c9 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 17 Feb 2025 16:09:29 +0100 Subject: [PATCH 2/4] fix tsc --- tests/component-testing.spec.ts | 4 ++-- tests/integration.spec.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/component-testing.spec.ts b/tests/component-testing.spec.ts index 35de7e6..4430aef 100644 --- a/tests/component-testing.spec.ts +++ b/tests/component-testing.spec.ts @@ -18,7 +18,7 @@ import path from 'path'; import fs from 'fs'; test('should be able to generate and run a CT React project', async ({ run, dir, exec, packageManager }) => { - test.skip(packageManager === 'yarn'); + test.skip(packageManager === 'yarn-classic' || packageManager === 'yarn-berry'); test.slow(); await run(['--ct'], { installGitHubActions: true, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: true, framework: 'react' }); { @@ -32,7 +32,7 @@ test('should be able to generate and run a CT React project', async ({ run, dir, expect(fs.readFileSync(path.join(dir, '.github/workflows/playwright.yml'), 'utf8')).toContain('test-ct'); } - await exec(packageManager, [(packageManager === 'yarn' ? 'add' : 'install'), 'react', 'react-dom']); + await exec(packageManager, [((packageManager === 'yarn-classic' || packageManager === 'yarn-berry') ? 'add' : 'install'), 'react', 'react-dom']); fs.mkdirSync(path.join(dir, 'src')); fs.writeFileSync(path.join(dir, 'src/App.tsx'), 'export default () => <>Learn React;'); diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index 0b099b8..cd28738 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -28,7 +28,7 @@ const validGitignore = [ ].join('\n'); test('should generate a project in the current directory', async ({ run, dir, packageManager }) => { - test.skip(packageManager === 'yarn'); + test.skip(packageManager === 'yarn-classic' || packageManager === 'yarn-berry'); test.slow(); const { stdout } = await run([], { installGitHubActions: true, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: true }); expect(fs.existsSync(path.join(dir, 'tests/example.spec.ts'))).toBeTruthy(); @@ -44,7 +44,7 @@ test('should generate a project in the current directory', async ({ run, dir, pa expect(stdout).toContain('Initializing NPM project (npm init -y)…'); expect(stdout).toContain('Installing Playwright Test (npm install --save-dev @playwright/test)…'); expect(stdout).toContain('Installing Types (npm install --save-dev @types/node)…'); - } else if (packageManager === 'yarn') { + } else if (packageManager === 'yarn-classic') { expect(stdout).toContain('Initializing Yarn project (yarn init -y)…'); expect(stdout).toContain('Installing Playwright Test (yarn add --dev @playwright/test)…'); expect(stdout).toContain('Installing Types (yarn add --dev @types/node)…'); @@ -57,7 +57,7 @@ test('should generate a project in the current directory', async ({ run, dir, pa }); test('should generate a project in a given directory', async ({ run, dir, packageManager }) => { - test.skip(packageManager === 'yarn'); + test.skip(packageManager === 'yarn-classic' || packageManager === 'yarn-berry'); await run(['foobar'], { installGitHubActions: true, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: true }); expect(fs.existsSync(path.join(dir, 'foobar/tests/example.spec.ts'))).toBeTruthy(); expect(fs.existsSync(path.join(dir, 'foobar/package.json'))).toBeTruthy(); From 79d853d2b8f8c931357d811bc1e8ea2ee0695fe7 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 17 Feb 2025 16:14:48 +0100 Subject: [PATCH 3/4] use yarn --- tests/integration.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index cd28738..4c6eff5 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -128,9 +128,9 @@ test('should generate in the root of yarn workspaces', async ({ run, packageMana for (const pkg of ['foo', 'bar']) { const packageDir = path.join(dir, 'packages', pkg); fs.mkdirSync(packageDir, { recursive: true }); - childProcess.execSync(`${packageManager} init -y`, { cwd: packageDir }); + childProcess.execSync(`yarn init -y`, { cwd: packageDir }); } - childProcess.execSync(`${packageManager} install`, { cwd: dir }); + childProcess.execSync(`yarn install`, { cwd: dir }); await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false }); assertLockFilesExist(dir, packageManager); From 97aa4bd1af33355160364b98f6e93a9bdf8b1434 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 19 Feb 2025 14:25:26 +0100 Subject: [PATCH 4/4] use --grep --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22fefbc..4cb0ef8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,6 @@ jobs: - run: npx playwright install-deps - run: npm run build - run: npx tsc --noEmit - - run: npm run test -- --project=npm --project=pnpm --project=yarn-classic + - run: npm run test -- --grep-invert yarn-berry - run: yarn set version stable - - run: npm run test -- --project=yarn-berry + - run: npm run test -- --grep yarn-berry