[@kbn/optimizer] prevent error when all bundles are cached (#57871)

This commit is contained in:
Spencer 2020-02-18 10:57:15 -07:00 committed by GitHub
parent c07ff7174e
commit a838e6392a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View file

@ -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,
@ -42,7 +42,7 @@ beforeEach(async () => {
});
});
afterEach(async () => {
afterAll(async () => {
await del(TMP_DIR);
});
@ -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",
]
`);
});

View file

@ -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');
}