[@kbn/optimizer] prevent error when all bundles are cached (#57871)
This commit is contained in:
parent
c07ff7174e
commit
a838e6392a
|
@ -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",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue