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
16 changes: 16 additions & 0 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ export class Generator {
files.set(`playwright/index.${extension}`, jsTemplate);
}

if (!this._hasDependency('@types/node')) {
commands.push({
name: 'Installing Types',
command: packageManager.installDevDependency(`@types/node`),
});
}

const browsersSuffix = this.options.browser ? ' ' + this.options.browser.join(' ') : '';
if (answers.installPlaywrightBrowsers) {
commands.push({
Expand All @@ -225,6 +232,15 @@ export class Generator {
return { files, commands };
}

private _hasDependency(pkg: string) {
try {
const packageJSON = JSON.parse(fs.readFileSync(path.join(this.rootDir, 'package.json'), 'utf-8'));
return packageJSON.dependencies?.[pkg] || packageJSON.devDependencies?.[pkg] || packageJSON.optionalDependencies?.[pkg];
} catch (e) {
return false;
}
}

private _patchGitIgnore() {
const gitIgnorePath = path.join(this.rootDir, '.gitignore');
let gitIgnore = '';
Expand Down
3 changes: 3 additions & 0 deletions tests/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ test('should generate a project in the current directory', async ({ run, package
if (packageManager === 'npm') {
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') {
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)…');
} else if (packageManager === 'pnpm') {
expect(stdout).toContain('pnpm init'); // pnpm command outputs name in different case, hence we are not testing the whole string
expect(stdout).toContain('Installing Playwright Test (pnpm add --save-dev @playwright/test)…');
expect(stdout).toContain('Installing Types (pnpm add --save-dev @types/node)…');
}
expect(stdout).toContain('npx playwright install' + process.platform === 'linux' ? ' --with-deps' : '');
});
Expand Down