Skip to content

Commit 42acdf0

Browse files
authored
feat: section header when appending existing .gitignore (#132)
* chore: changes from formatting on save * style: separate addition of `playwright` entries
1 parent 34403ed commit 42acdf0

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/generator.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import path from 'path';
1716
import fs from 'fs';
17+
import path from 'path';
1818

19-
import { prompt } from 'enquirer';
2019
import colors from 'ansi-colors';
20+
import { prompt } from 'enquirer';
2121
import ini from 'ini';
2222

23-
import { executeCommands, createFiles, executeTemplate, Command, languageToFileExtension, getFileExtensionCT } from './utils';
2423
import { type PackageManager, determinePackageManager } from './packageManager';
24+
import { Command, createFiles, executeCommands, executeTemplate, getFileExtensionCT, languageToFileExtension } from './utils';
2525

2626
export type PromptOptions = {
2727
testDir: string,
@@ -271,7 +271,9 @@ export class Generator {
271271
let gitIgnore = '';
272272
if (fs.existsSync(gitIgnorePath))
273273
gitIgnore = fs.readFileSync(gitIgnorePath, 'utf-8').trimEnd() + '\n';
274-
const valuesToAdd = {
274+
275+
let thisIsTheFirstLineWeAreAdding = true;
276+
const valuesToAdd = {
275277
'node_modules/': /^node_modules\/?/m,
276278
'/test-results/': /^\/?test-results\/?$/m,
277279
'/playwright-report/': /^\/playwright-report\/?$/m,
@@ -280,6 +282,11 @@ export class Generator {
280282
};
281283
Object.entries(valuesToAdd).forEach(([value, regex]) => {
282284
if (!gitIgnore.match(regex)) {
285+
if (thisIsTheFirstLineWeAreAdding) {
286+
gitIgnore += `\n# Playwright\n`;
287+
thisIsTheFirstLineWeAreAdding = false;
288+
}
289+
283290
gitIgnore += `${value}\n`;
284291
}
285292
});

tests/integration.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { test, expect, packageManagerToNpxCommand, assertLockFilesExist } from './baseFixtures';
17-
import path from 'path';
18-
import fs from 'fs';
1916
import childProcess from 'child_process';
17+
import fs from 'fs';
18+
import path from 'path';
19+
import { assertLockFilesExist, expect, packageManagerToNpxCommand, test } from './baseFixtures';
2020

2121
const validGitignore = [
22+
'# Playwright',
2223
'node_modules/',
2324
'/test-results/',
2425
'/playwright-report/',
@@ -120,7 +121,7 @@ test('should not duplicate gitignore entries', async ({ run, dir }) => {
120121

121122
test('should install with "npm ci" in GHA when using npm with package-lock enabled', async ({ dir, run, packageManager }) => {
122123
test.skip(packageManager !== 'npm');
123-
124+
124125
await run([], { installGitHubActions: true, testDir: 'tests', language: 'JavaScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: true });
125126
expect(fs.existsSync(path.join(dir, '.github/workflows/playwright.yml'))).toBeTruthy();
126127

0 commit comments

Comments
 (0)