Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/packageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ class Yarn implements PackageManager {
name = 'Yarn'
cli = 'yarn'
private workspace: boolean
private classic = false;

constructor(rootDir: string) {
constructor(rootDir: string, version?: string) {
this.workspace = this.isWorkspace(rootDir);
if (version)
this.classic = version.startsWith('0') || version.startsWith('1');
}

private isWorkspace(rootDir: string) {
Expand Down Expand Up @@ -81,7 +84,7 @@ class Yarn implements PackageManager {
}

installDevDependency(name: string): string {
return `yarn add --dev ${this.workspace ? '-W ' : ''}${name}`
return `yarn add --dev ${(this.workspace && this.classic) ? '-W ' : ''}${name}`
}

runPlaywrightTest(args: string): string {
Expand Down Expand Up @@ -132,10 +135,13 @@ class PNPM implements PackageManager {
}

export function determinePackageManager(rootDir: string): PackageManager {
if (process.env.npm_config_user_agent) {
if (process.env.npm_config_user_agent.includes('yarn'))
return new Yarn(rootDir);
if (process.env.npm_config_user_agent.includes('pnpm'))
const userAgent = process.env.npm_config_user_agent;
if (userAgent) {
if (userAgent.includes('yarn')) {
const yarnVersion = userAgent.match(/yarn\/(\d+\.\d+\.\d+)/)?.[1];
return new Yarn(rootDir, yarnVersion);
}
if (userAgent.includes('pnpm'))
return new PNPM(rootDir);
}
return new NPM();
Expand Down
9 changes: 8 additions & 1 deletion tests/baseFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ import type { PromptOptions } from '../src/generator';

export type PackageManager = 'npm' | 'pnpm' | 'yarn-classic' | 'yarn-berry';

const userAgents: Record<PackageManager, string | undefined> = {
'yarn-classic': 'yarn/1.22.10',
'yarn-berry': 'yarn/4.0.0',
pnpm: 'pnpm/0.0.0',
npm: undefined,
};

export type TestFixtures = {
packageManager: PackageManager;
dir: string;
Expand Down Expand Up @@ -82,7 +89,7 @@ export const test = base.extend<TestFixtures>({
cwd: dir,
env: {
...process.env,
'npm_config_user_agent': packageManager.startsWith('yarn') ? 'yarn' : packageManager === 'pnpm' ? 'pnpm/0.0.0' : undefined,
npm_config_user_agent: userAgents[packageManager],
'TEST_OPTIONS': JSON.stringify(options),
},
});
Expand Down
7 changes: 4 additions & 3 deletions tests/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 !== 'yarn-classic');
test.skip(packageManager !== 'yarn-berry' && packageManager !== 'yarn-classic');
Comment thread
Skn0tt marked this conversation as resolved.

const dir = test.info().outputDir;
fs.mkdirSync(dir, { recursive: true });
Expand All @@ -130,12 +130,13 @@ test('should generate in the root of yarn workspaces', async ({ run, packageMana
fs.mkdirSync(packageDir, { recursive: true });
childProcess.execSync(`yarn init -y`, { cwd: packageDir });
}
childProcess.execSync(`yarn install`, { cwd: dir });
childProcess.execSync(`yarn install`, { cwd: dir, stdio: 'inherit', env: { ...process.env, YARN_ENABLE_IMMUTABLE_INSTALLS: 'false', YARN_ENABLE_HARDENED_MODE: '0' } });

await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false });
assertLockFilesExist(dir, packageManager);
expect(fs.existsSync(path.join(dir, 'tests/example.spec.ts'))).toBeTruthy();
expect(fs.existsSync(path.join(dir, 'node_modules/playwright'))).toBeTruthy();
const writesNodeModules = packageManager === 'yarn-classic';
expect(fs.existsSync(path.join(dir, 'node_modules/playwright'))).toBe(writesNodeModules);
Comment thread
mxschmitt marked this conversation as resolved.
expect(fs.existsSync(path.join(dir, 'playwright.config.ts'))).toBeTruthy();
});

Expand Down