diff --git a/src/generator.ts b/src/generator.ts index d4227e9..427e593 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import path from 'path'; import fs from 'fs'; +import path from 'path'; -import { prompt } from 'enquirer'; import colors from 'ansi-colors'; +import { prompt } from 'enquirer'; import ini from 'ini'; -import { executeCommands, createFiles, executeTemplate, Command, languageToFileExtension, getFileExtensionCT } from './utils'; import { type PackageManager, determinePackageManager } from './packageManager'; +import { Command, createFiles, executeCommands, executeTemplate, getFileExtensionCT, languageToFileExtension } from './utils'; export type PromptOptions = { testDir: string, @@ -271,7 +271,9 @@ export class Generator { let gitIgnore = ''; if (fs.existsSync(gitIgnorePath)) gitIgnore = fs.readFileSync(gitIgnorePath, 'utf-8').trimEnd() + '\n'; - const valuesToAdd = { + + let thisIsTheFirstLineWeAreAdding = true; + const valuesToAdd = { 'node_modules/': /^node_modules\/?/m, '/test-results/': /^\/?test-results\/?$/m, '/playwright-report/': /^\/playwright-report\/?$/m, @@ -280,6 +282,11 @@ export class Generator { }; Object.entries(valuesToAdd).forEach(([value, regex]) => { if (!gitIgnore.match(regex)) { + if (thisIsTheFirstLineWeAreAdding) { + gitIgnore += `\n# Playwright\n`; + thisIsTheFirstLineWeAreAdding = false; + } + gitIgnore += `${value}\n`; } }); diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index a10c1f7..0156561 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { test, expect, packageManagerToNpxCommand, assertLockFilesExist } from './baseFixtures'; -import path from 'path'; -import fs from 'fs'; import childProcess from 'child_process'; +import fs from 'fs'; +import path from 'path'; +import { assertLockFilesExist, expect, packageManagerToNpxCommand, test } from './baseFixtures'; const validGitignore = [ + '# Playwright', 'node_modules/', '/test-results/', '/playwright-report/', @@ -120,7 +121,7 @@ test('should not duplicate gitignore entries', async ({ run, dir }) => { test('should install with "npm ci" in GHA when using npm with package-lock enabled', async ({ dir, run, packageManager }) => { test.skip(packageManager !== 'npm'); - + await run([], { installGitHubActions: true, testDir: 'tests', language: 'JavaScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: true }); expect(fs.existsSync(path.join(dir, '.github/workflows/playwright.yml'))).toBeTruthy();