Skip to content

Commit

Permalink
move mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Feb 21, 2020
1 parent e0d062c commit e20c780
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions packages/kbn-optimizer/src/optimizer/cache_keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,27 @@ import { REPO_ROOT, createAbsolutePathSerializer } from '@kbn/dev-utils';
import { reformatJestDiff, getOptimizerCacheKey, diffCacheKey } from './cache_keys';
import { OptimizerConfig } from './optimizer_config';

jest.mock('./get_changes.ts');
jest.mock('./get_mtimes.ts');
jest.mock('./get_changes.ts', () => ({
getChanges: async () =>
new Map([
['/foo/bar/a', 'modified'],
['/foo/bar/b', 'modified'],
['/foo/bar/c', 'deleted'],
]),
}));

jest.mock('./get_mtimes.ts', () => ({
getMtimes: async (paths: string[]) => new Map(paths.map(path => [path, 12345])),
}));

jest.mock('execa');

jest.mock('fs', () => {
const realFs = jest.requireActual('fs');
jest.spyOn(realFs, 'readFile');
return realFs;
});

expect.addSnapshotSerializer(createAbsolutePathSerializer());

jest.requireMock('execa').mockImplementation(async (cmd: string, args: string[], opts: object) => {
Expand All @@ -54,21 +67,6 @@ jest.requireMock('execa').mockImplementation(async (cmd: string, args: string[],
};
});

jest
.requireMock('./get_mtimes.ts')
.getMtimes.mockImplementation(
async (paths: string[]) => new Map(paths.map(path => [path, 12345]))
);

jest.requireMock('./get_changes.ts').getChanges.mockImplementation(
async () =>
new Map([
['/foo/bar/a', 'modified'],
['/foo/bar/b', 'modified'],
['/foo/bar/c', 'deleted'],
])
);

describe('getOptimizerCacheKey()', () => {
it('uses latest commit, bootstrap cache, and changed files to create unique value', async () => {
jest
Expand Down

0 comments on commit e20c780

Please sign in to comment.