Skip to content

Commit c00b836

Browse files
committed
wip(git-ignore): defined very rough first pass of a lifter
1 parent e78b248 commit c00b836

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

src/vcs/git/ignore/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export {default as scaffold} from './scaffolder.js';
22
export {default as test} from './tester.js';
3+
export {default as lift} from './lifter.js';

src/vcs/git/ignore/lifter.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import writeIgnores from './scaffolder.js';
2+
3+
export default async function ({projectRoot, results: {vcsIgnore}}) {
4+
if (vcsIgnore) await writeIgnores({projectRoot, ...vcsIgnore});
5+
6+
return {};
7+
}

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

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {describe, it, expect, vi, afterEach} from 'vitest';
2+
import any from '@travi/any';
3+
4+
import writeIgnores from './scaffolder.js';
5+
import liftGitIgnore from './lifter.js';
6+
7+
vi.mock('./scaffolder.js');
8+
9+
describe('gitignore lifter', () => {
10+
const projectRoot = any.string();
11+
12+
afterEach(() => {
13+
vi.clearAllMocks();
14+
});
15+
16+
it('should write the provided ignores to the gitignore file', async () => {
17+
const ignoredDirectories = any.listOf(any.word);
18+
const ignoredFiles = any.listOf(any.word);
19+
20+
expect(
21+
await liftGitIgnore({projectRoot, results: {vcsIgnore: {directories: ignoredDirectories, files: ignoredFiles}}})
22+
).toEqual({});
23+
24+
expect(writeIgnores).toHaveBeenCalledWith({projectRoot, directories: ignoredDirectories, files: ignoredFiles});
25+
});
26+
27+
it('should not update the ignore file if no additional ignores are provided', async () => {
28+
expect(await liftGitIgnore({projectRoot, results: {}})).toEqual({});
29+
30+
expect(writeIgnores).not.toHaveBeenCalledWith({projectRoot});
31+
});
32+
});

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ Then(/^the base git files should not be present$/, async function () {
7272
});
7373

7474
Then('the additional ignores are added to the gitignore', async function () {
75-
// Write code here that turns the phrase above into concrete actions
76-
return 'pending';
75+
const gitIgnoreContent = await fs.readFile(`${process.cwd()}/.gitignore`, 'utf-8');
76+
77+
assert.equal(gitIgnoreContent, `${this.vcsIgnoreDirectories.join('\n')}\n\n${this.vcsIgnoreFiles.join('\n')}`);
7778
});
7879

7980
Then('the gitignore file is unchanged', async function () {

0 commit comments

Comments
 (0)