Skip to content

Commit b3c4f47

Browse files
committed
Merge branch 'master' of github.com:form8ion/project into beta
2 parents a9dc92b + d006c32 commit b3c4f47

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
lines changed

src/vcs/git/ignore/writer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {promises as fs} from 'node:fs';
22

33
export default function ({projectRoot, files = [], directories = []}) {
4-
return fs.writeFile(`${projectRoot}/.gitignore`, `${directories.join('\n')}\n\n${files.join('\n')}`);
4+
return fs.appendFile(`${projectRoot}/.gitignore`, `\n${directories.join('\n')}\n\n${files.join('\n')}`);
55
}

src/vcs/git/ignore/writer.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ describe('gitignore writer', () => {
1616

1717
await write({projectRoot, directories, files});
1818

19-
expect(fs.writeFile).toHaveBeenCalledWith(
19+
expect(fs.appendFile).toHaveBeenCalledWith(
2020
`${projectRoot}/.gitignore`,
21-
`${directories.join('\n')}\n\n${files.join('\n')}`
21+
`\n${directories.join('\n')}\n\n${files.join('\n')}`
2222
);
2323
});
2424

2525
it('should not throw an error if directories nor files are provided', async () => {
2626
await write({projectRoot});
2727

28-
expect(fs.writeFile).toHaveBeenCalledWith(`${projectRoot}/.gitignore`, '\n\n');
28+
expect(fs.appendFile).toHaveBeenCalledWith(`${projectRoot}/.gitignore`, '\n\n\n');
2929
});
3030
});

test/integration/features/git.feature

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ Feature: Git Repository
77

88
Scenario: to be versioned
99
Given the project should be versioned in git
10+
And a language scaffolder is chosen
1011
When the project is scaffolded
1112
Then the directory is initialized as a git repository
1213
And the base git files should be present
14+
And the ignores are defined in the gitignore
1315

1416
Scenario: to be versioned and hosted
1517
Given the project should be versioned in git
@@ -19,14 +21,16 @@ Feature: Git Repository
1921

2022
Scenario: already versioned
2123
Given the project root is already initialized as a git repository
24+
And a language scaffolder is chosen
2225
When the project is scaffolded
2326
Then the base git files should be present
24-
And the gitignore file is unchanged
27+
And the additional ignores are added to the gitignore
2528

2629
@wip
2730
Scenario: already versioned without an existing gitignore
2831
Given the project root is already initialized as a git repository
32+
And a language scaffolder is chosen
2933
But there is no preexisting gitignore
3034
When the project is scaffolded
3135
Then the base git files should be present
32-
And the gitignore file is unchanged
36+
And the gitignore file is added

test/integration/features/step_definitions/common-steps.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ When(/^the project is scaffolded$/, async function () {
8989
});
9090

9191
When('the project is lifted', async function () {
92+
this.existingVcsIgnoredFiles = any.listOf(any.word);
93+
this.existingVcsIgnoredDirectories = any.listOf(any.word);
94+
9295
await Promise.all([
9396
fs.writeFile(`${process.cwd()}/README.md`, this.existingReadmeContent || ''),
9497
fs.writeFile(
9598
`${process.cwd()}/.gitignore`,
96-
(this.existingVcsIgnoredFiles && this.existingVcsIgnoredDirectories)
97-
? `${this.existingVcsIgnoredDirectories.join('\n')}\n\n${this.existingVcsIgnoredFiles.join('\n')}`
98-
: ''
99+
`${this.existingVcsIgnoredDirectories.join('\n')}\n\n${this.existingVcsIgnoredFiles.join('\n')}`
99100
)
100101
]);
101102

test/integration/features/step_definitions/language-steps.js

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ function generateBadgeWithNoLink() {
2020

2121
Given('a language scaffolder is chosen', async function () {
2222
this.setAnswerFor(questionNames.PROJECT_LANGUAGE, any.word());
23+
this.vcsIgnoreDirectories = any.listOf(any.word, {min: 1});
24+
this.vcsIgnoreFiles = any.listOf(any.word, {min: 1});
2325

2426
this.languageScaffolderResults = {
2527
badges: {
@@ -35,6 +37,10 @@ Given('a language scaffolder is chosen', async function () {
3537
[any.word()]: generateFullBadge(),
3638
[any.word()]: generateBadgeWithNoLink()
3739
}
40+
},
41+
vcsIgnore: {
42+
directories: this.vcsIgnoreDirectories,
43+
files: this.vcsIgnoreFiles
3844
}
3945
};
4046
});

test/integration/features/step_definitions/vcs/git-steps.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,24 @@ Then(/^the base git files should not be present$/, async function () {
8484
assert.isFalse(await fileExists(`${process.cwd()}/.gitignore`));
8585
});
8686

87+
Then('the ignores are defined in the gitignore', async function () {
88+
const gitIgnoreContent = await fs.readFile(`${process.cwd()}/.gitignore`, 'utf-8');
89+
90+
assert.include(gitIgnoreContent, `${this.vcsIgnoreDirectories.join('\n')}\n\n${this.vcsIgnoreFiles.join('\n')}`);
91+
});
92+
8793
Then('the additional ignores are added to the gitignore', async function () {
8894
const gitIgnoreContent = await fs.readFile(`${process.cwd()}/.gitignore`, 'utf-8');
8995

90-
assert.equal(gitIgnoreContent, `${this.vcsIgnoreDirectories.join('\n')}\n\n${this.vcsIgnoreFiles.join('\n')}`);
96+
assert.equal(
97+
gitIgnoreContent,
98+
`${this.existingVcsIgnoredDirectories.join('\n')}
99+
100+
${this.existingVcsIgnoredFiles.join('\n')}
101+
${this.vcsIgnoreDirectories.join('\n')}
102+
103+
${this.vcsIgnoreFiles.join('\n')}`
104+
);
91105
});
92106

93107
Then('the gitignore file is unchanged', async function () {
@@ -96,3 +110,10 @@ Then('the gitignore file is unchanged', async function () {
96110
`${this.existingVcsIgnoredDirectories.join('\n')}\n\n${this.existingVcsIgnoredFiles.join('\n')}`
97111
);
98112
});
113+
114+
Then('the gitignore file is added', async function () {
115+
assert.equal(
116+
await fs.readFile(`${process.cwd()}/.gitignore`, 'utf-8'),
117+
`${this.vcsIgnoreDirectories.join('\n')}\n\n${this.vcsIgnoreFiles.join('\n')}`
118+
);
119+
});

0 commit comments

Comments
 (0)