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/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,18 @@ export class Generator {
let gitIgnore = '';
if (fs.existsSync(gitIgnorePath))
gitIgnore = fs.readFileSync(gitIgnorePath, 'utf-8').trimEnd() + '\n';
if (!gitIgnore.includes('node_modules'))
gitIgnore += 'node_modules/\n';
gitIgnore += '/test-results/\n';
gitIgnore += '/playwright-report/\n';
gitIgnore += '/blob-report/\n';
gitIgnore += '/playwright/.cache/\n';
const valuesToAdd = {
'node_modules/': /^node_modules\/?/m,
'/test-results/': /^\/?test-results\/?$/m,
'/playwright-report/': /^\/playwright-report\/?$/m,
'/blob-report/': /^\/blob-report\/?$/m,
'/playwright/.cache/': /^\/playwright\/\.cache\/?$/m
};
Object.entries(valuesToAdd).forEach(([value, regex]) => {
if (!gitIgnore.match(regex)) {
gitIgnore += `${value}\n`;
}
});
fs.writeFileSync(gitIgnorePath, gitIgnore);
}

Expand Down
16 changes: 16 additions & 0 deletions tests/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import path from 'path';
import fs from 'fs';
import childProcess from 'child_process';

const validGitignore = [
'node_modules/',
'/test-results/',
'/playwright-report/',
'/blob-report/',
'/playwright/.cache/',
].join('\n');

test('should generate a project in the current directory', async ({ run, dir, packageManager }) => {
test.slow();
const { stdout } = await run([], { installGitHubActions: true, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: true });
Expand All @@ -29,6 +37,7 @@ test('should generate a project in the current directory', async ({ run, dir, pa
expect(playwrightConfigContent).toContain('tests');
expect(fs.existsSync(path.join(dir, '.github/workflows/playwright.yml'))).toBeTruthy();
expect(fs.existsSync(path.join(dir, '.gitignore'))).toBeTruthy();
expect(fs.readFileSync(path.join(dir, '.gitignore'), { encoding: 'utf8' }).trim()).toBe(validGitignore);
if (packageManager === 'npm') {
expect(stdout).toContain('Initializing NPM project (npm init -y)…');
expect(stdout).toContain('Installing Playwright Test (npm install --save-dev @playwright/test)…');
Expand Down Expand Up @@ -102,6 +111,13 @@ test('should generate in the root of pnpm workspace', async ({ run, packageManag
expect(fs.existsSync(path.join(dir, 'playwright.config.ts'))).toBeTruthy();
});

test('should not duplicate gitignore entries', async ({ run, dir }) => {
fs.writeFileSync(path.join(dir, '.gitignore'), validGitignore);

await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false });
expect(fs.readFileSync(path.join(dir, '.gitignore'), { encoding: 'utf8' }).trim()).toBe(validGitignore);
})

test('should install with "npm ci" in GHA when using npm with package-lock enabled', async ({ dir, run, packageManager }) => {
test.skip(packageManager !== 'npm');

Expand Down