Skip to content

Commit

Permalink
Fix skip reason and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Jan 31, 2021
1 parent 30aea4a commit 533c5fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/tasks/gitInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const setGitInfo = async (ctx, task) => {
const changedFiles = [...new Set(results.flat())];
ctx.log.debug(changedFiles);
if (changedFiles.every(matchesFile)) {
ctx.skipReason = '--skip-files';
ctx.skipReason = '--ignore-changed-files';
return skipBuild(ctx, task);
}
}
Expand Down
19 changes: 18 additions & 1 deletion bin/tasks/gitInfo.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { getCommitAndBranch } from '../git/getCommitAndBranch';
import { getBaselineCommits, getSlug, getVersion } from '../git/git';
import { getBaselineCommits, getSlug, getVersion, getChangedFiles } from '../git/git';
import { setGitInfo } from './gitInfo';

jest.mock('../git/getCommitAndBranch');
jest.mock('../git/git');

const log = { debug: jest.fn() };

const client = { runQuery: jest.fn() };
client.runQuery.mockReturnValue({ skipBuild: true });

describe('setGitInfo', () => {
it('sets the git info on context', async () => {
getCommitAndBranch.mockReturnValue({ commit: '123asdf', branch: 'something' });
Expand Down Expand Up @@ -39,4 +42,18 @@ describe('setGitInfo', () => {
slug: 'org/repo',
});
});

it('skips build when --ignore-changed-files matches all changed files', async () => {
getCommitAndBranch.mockReturnValue({ commit: '123asdf', branch: 'something' });
getBaselineCommits.mockReturnValue(['asd2344', 'foobar1']);
getChangedFiles.mockReturnValue(['foo.js', 'bar/baz.js']);
getVersion.mockReturnValue('Git v1.0.0');
getSlug.mockReturnValue('user/repo');
const ctx = { log, client, options: { ownerName: 'org', ignoreChangedFiles: '**/*.js' } };
await setGitInfo(ctx, {});
expect(getChangedFiles).toHaveBeenCalledWith('asd2344', '123asdf');
expect(getChangedFiles).toHaveBeenCalledWith('foobar1', '123asdf');
expect(ctx.skip).toBe(true);
expect(ctx.skipReason).toBe('--ignore-changed-files');
});
});
4 changes: 2 additions & 2 deletions bin/ui/tasks/gitInfo.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const Pending = () => pending({});
export const Success = () => success({ git, options });
export const NoBaselines = () => success({ git: { ...git, baselineCommits: [] }, options });
export const Skipping = () => skippingBuild({ git, skipReason: '--skip' });
export const SkippingFiles = () => skippingBuild({ git, skipReason: '--skip-files' });
export const SkippingFiles = () => skippingBuild({ git, skipReason: '--ignore-changed-files' });
export const Skipped = () => skippedForCommit({ git, skipReason: '--skip' });
export const SkippedFiles = () => skippedForCommit({ git, skipReason: '--skip-files' });
export const SkippedFiles = () => skippedForCommit({ git, skipReason: '--ignore-changed-files' });
export const SkipFailed = () => skipFailed();

0 comments on commit 533c5fd

Please sign in to comment.