Skip to content

Commit

Permalink
wip(git-ignore): defined very rough first pass of a lifter
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Dec 27, 2023
1 parent e78b248 commit c00b836
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/vcs/git/ignore/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export {default as scaffold} from './scaffolder.js';
export {default as test} from './tester.js';
export {default as lift} from './lifter.js';
7 changes: 7 additions & 0 deletions src/vcs/git/ignore/lifter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import writeIgnores from './scaffolder.js';

export default async function ({projectRoot, results: {vcsIgnore}}) {
if (vcsIgnore) await writeIgnores({projectRoot, ...vcsIgnore});

return {};
}
32 changes: 32 additions & 0 deletions src/vcs/git/ignore/lifter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {describe, it, expect, vi, afterEach} from 'vitest';
import any from '@travi/any';

import writeIgnores from './scaffolder.js';
import liftGitIgnore from './lifter.js';

vi.mock('./scaffolder.js');

describe('gitignore lifter', () => {
const projectRoot = any.string();

afterEach(() => {
vi.clearAllMocks();
});

it('should write the provided ignores to the gitignore file', async () => {
const ignoredDirectories = any.listOf(any.word);
const ignoredFiles = any.listOf(any.word);

expect(
await liftGitIgnore({projectRoot, results: {vcsIgnore: {directories: ignoredDirectories, files: ignoredFiles}}})
).toEqual({});

expect(writeIgnores).toHaveBeenCalledWith({projectRoot, directories: ignoredDirectories, files: ignoredFiles});
});

it('should not update the ignore file if no additional ignores are provided', async () => {
expect(await liftGitIgnore({projectRoot, results: {}})).toEqual({});

expect(writeIgnores).not.toHaveBeenCalledWith({projectRoot});
});
});
5 changes: 3 additions & 2 deletions test/integration/features/step_definitions/vcs/git-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ Then(/^the base git files should not be present$/, async function () {
});

Then('the additional ignores are added to the gitignore', async function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
const gitIgnoreContent = await fs.readFile(`${process.cwd()}/.gitignore`, 'utf-8');

assert.equal(gitIgnoreContent, `${this.vcsIgnoreDirectories.join('\n')}\n\n${this.vcsIgnoreFiles.join('\n')}`);
});

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

0 comments on commit c00b836

Please sign in to comment.