Skip to content

Commit

Permalink
[@kbn/optimizer] prevent error when all bundles are cached (#57871)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer authored and spalger committed Feb 18, 2020
1 parent f4b65dc commit 6a9ffe5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const MOCK_REPO_DIR = Path.resolve(TMP_DIR, 'mock_repo');

expect.addSnapshotSerializer(createAbsolutePathSerializer(MOCK_REPO_DIR));

beforeEach(async () => {
beforeAll(async () => {
await del(TMP_DIR);
await cpy('**/*', MOCK_REPO_DIR, {
cwd: MOCK_REPO_SRC,
Expand All @@ -42,7 +42,7 @@ beforeEach(async () => {
});
});

afterEach(async () => {
afterAll(async () => {
await del(TMP_DIR);
});

Expand Down Expand Up @@ -153,3 +153,32 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
]
`);
});

it('uses cache on second run and exist cleanly', async () => {
const config = OptimizerConfig.create({
repoRoot: MOCK_REPO_DIR,
pluginScanDirs: [Path.resolve(MOCK_REPO_DIR, 'plugins')],
maxWorkerCount: 1,
});

const msgs = await runOptimizer(config)
.pipe(
tap(state => {
if (state.event?.type === 'worker stdio') {
// eslint-disable-next-line no-console
console.log('worker', state.event.stream, state.event.chunk.toString('utf8'));
}
}),
toArray()
)
.toPromise();

expect(msgs.map(m => m.state.phase)).toMatchInlineSnapshot(`
Array [
"initializing",
"initializing",
"initializing",
"initialized",
]
`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export function handleOptimizerCompletion(config: OptimizerConfig) {
return;
}

if (prevState?.phase === 'initialized' && prevState.onlineBundles.length === 0) {
// all bundles cached
return;
}

if (prevState?.phase === 'issue') {
throw createFailError('webpack issue');
}
Expand Down

0 comments on commit 6a9ffe5

Please sign in to comment.