From 149b4c464dfff960f819585e7dbe4f1ff29ecb63 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Mon, 3 Jun 2024 09:47:27 +0200 Subject: [PATCH 1/7] fix: dont duplicate .gitignore entries --- src/generator.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index e8152d1..1559a17 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -258,12 +258,12 @@ 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/', '/test-results/', '/playwright-report/', '/blob-report/', '/playwright/.cache/']; + valuesToAdd.forEach(value => { + if (!gitIgnore.includes(value)) { + gitIgnore += `${value}\n`; + } + }); fs.writeFileSync(gitIgnorePath, gitIgnore); } From 7a3bd98e4c9d3987733862b1899ac70d09641b5c Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Tue, 4 Jun 2024 09:45:09 +0200 Subject: [PATCH 2/7] use regex instead of string.includes --- src/generator.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index 1559a17..f48b059 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -258,9 +258,15 @@ export class Generator { let gitIgnore = ''; if (fs.existsSync(gitIgnorePath)) gitIgnore = fs.readFileSync(gitIgnorePath, 'utf-8').trimEnd() + '\n'; - const valuesToAdd = ['node_modules/', '/test-results/', '/playwright-report/', '/blob-report/', '/playwright/.cache/']; - valuesToAdd.forEach(value => { - if (!gitIgnore.includes(value)) { + 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`; } }); From 113797adb166825d48d948a57d03f28c4ddd50ed Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Tue, 4 Jun 2024 16:09:38 +0200 Subject: [PATCH 3/7] fix inconsistencies --- src/generator.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index f48b059..7bd6604 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -259,11 +259,11 @@ export class Generator { if (fs.existsSync(gitIgnorePath)) gitIgnore = fs.readFileSync(gitIgnorePath, 'utf-8').trimEnd() + '\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 + '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)) { From 3dc1bf1f326f047dccb5b90f9769da725827fa09 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Sat, 6 Jul 2024 14:19:06 +0200 Subject: [PATCH 4/7] start with testing gitignore --- tests/integration.spec.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index 059d3bd..a0e60c5 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -18,6 +18,8 @@ import path from 'path'; import fs from 'fs'; import childProcess from 'child_process'; +const validGitignore = 'node_modules/\n/test-results/\n/playwright-report/\n/blob-report/\n/playwright/.cache/\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 }); @@ -29,6 +31,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' })).toMatch(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)…'); @@ -101,3 +104,11 @@ test('should generate in the root of pnpm workspace', async ({ run, packageManag expect(fs.existsSync(path.join(dir, 'package.json'))).toBeTruthy(); expect(fs.existsSync(path.join(dir, 'playwright.config.ts'))).toBeTruthy(); }); + +test('should not duplicate gitignore entries', async ({ run, dir }) => { + await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false }); + expect(fs.readFileSync(path.join(dir, '.gitignore'), { encoding: 'utf8' })).toMatch(validGitignore); + + await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false }); + expect(fs.readFileSync(path.join(dir, '.gitignore'), { encoding: 'utf8' })).toMatch(validGitignore); +}) From c8dc45b18fac2f5f03e06d178e92ca42df92c067 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Mon, 8 Jul 2024 07:42:06 +0200 Subject: [PATCH 5/7] implement suggestions --- tests/integration.spec.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index a0e60c5..5ee34e0 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -18,7 +18,13 @@ import path from 'path'; import fs from 'fs'; import childProcess from 'child_process'; -const validGitignore = 'node_modules/\n/test-results/\n/playwright-report/\n/blob-report/\n/playwright/.cache/\n'; +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(); @@ -106,8 +112,7 @@ test('should generate in the root of pnpm workspace', async ({ run, packageManag }); test('should not duplicate gitignore entries', async ({ run, dir }) => { - await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false }); - expect(fs.readFileSync(path.join(dir, '.gitignore'), { encoding: 'utf8' })).toMatch(validGitignore); + 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' })).toMatch(validGitignore); From bf7e331599cbef650bdf7abefabc975c2442d653 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Mon, 8 Jul 2024 16:09:10 +0200 Subject: [PATCH 6/7] implement suggestions --- src/generator.ts | 2 +- tests/integration.spec.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index 028bc92..d4227e9 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -273,7 +273,7 @@ export class Generator { gitIgnore = fs.readFileSync(gitIgnorePath, 'utf-8').trimEnd() + '\n'; const valuesToAdd = { 'node_modules/': /^node_modules\/?/m, - '/test-results/': /^test-results\/?$/m, + '/test-results/': /^\/?test-results\/?$/m, '/playwright-report/': /^\/playwright-report\/?$/m, '/blob-report/': /^\/blob-report\/?$/m, '/playwright/.cache/': /^\/playwright\/\.cache\/?$/m diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index 4206240..afc86dc 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -37,7 +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' })).toMatch(validGitignore); + 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)…'); @@ -115,7 +115,7 @@ 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' })).toMatch(validGitignore); + 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 }) => { From 83b89d46b0a029b995870424f8a76b12533a9c3a Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 8 Jul 2024 16:41:50 +0200 Subject: [PATCH 7/7] Update tests/integration.spec.ts --- tests/integration.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index afc86dc..a10c1f7 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -19,7 +19,7 @@ import fs from 'fs'; import childProcess from 'child_process'; const validGitignore = [ - 'node_modules', + 'node_modules/', '/test-results/', '/playwright-report/', '/blob-report/',