Skip to content

Commit 2d53486

Browse files
authored
feat: install @types/node (#99)
1 parent c79938c commit 2d53486

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/generator.ts

+16
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ export class Generator {
214214
files.set(`playwright/index.${extension}`, jsTemplate);
215215
}
216216

217+
if (!this._hasDependency('@types/node')) {
218+
commands.push({
219+
name: 'Installing Types',
220+
command: packageManager.installDevDependency(`@types/node`),
221+
});
222+
}
223+
217224
const browsersSuffix = this.options.browser ? ' ' + this.options.browser.join(' ') : '';
218225
if (answers.installPlaywrightBrowsers) {
219226
commands.push({
@@ -225,6 +232,15 @@ export class Generator {
225232
return { files, commands };
226233
}
227234

235+
private _hasDependency(pkg: string) {
236+
try {
237+
const packageJSON = JSON.parse(fs.readFileSync(path.join(this.rootDir, 'package.json'), 'utf-8'));
238+
return packageJSON.dependencies?.[pkg] || packageJSON.devDependencies?.[pkg] || packageJSON.optionalDependencies?.[pkg];
239+
} catch (e) {
240+
return false;
241+
}
242+
}
243+
228244
private _patchGitIgnore() {
229245
const gitIgnorePath = path.join(this.rootDir, '.gitignore');
230246
let gitIgnore = '';

tests/integration.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ test('should generate a project in the current directory', async ({ run, package
3232
if (packageManager === 'npm') {
3333
expect(stdout).toContain('Initializing NPM project (npm init -y)…');
3434
expect(stdout).toContain('Installing Playwright Test (npm install --save-dev @playwright/test)…');
35+
expect(stdout).toContain('Installing Types (npm install --save-dev @types/node)…');
3536
} else if (packageManager === 'yarn') {
3637
expect(stdout).toContain('Initializing Yarn project (yarn init -y)…');
3738
expect(stdout).toContain('Installing Playwright Test (yarn add --dev @playwright/test)…');
39+
expect(stdout).toContain('Installing Types (yarn add --dev @types/node)…');
3840
} else if (packageManager === 'pnpm') {
3941
expect(stdout).toContain('pnpm init'); // pnpm command outputs name in different case, hence we are not testing the whole string
4042
expect(stdout).toContain('Installing Playwright Test (pnpm add --save-dev @playwright/test)…');
43+
expect(stdout).toContain('Installing Types (pnpm add --save-dev @types/node)…');
4144
}
4245
expect(stdout).toContain('npx playwright install' + process.platform === 'linux' ? ' --with-deps' : '');
4346
});

0 commit comments

Comments
 (0)