Skip to content

Commit

Permalink
Update kbn-optimizer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Apr 8, 2020
1 parent 3f17e0a commit 98c767e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// eslint-disable-next-line no-console
console.log(`core entry point`);

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
(msg.event?.type === 'bundle cached' || msg.event?.type === 'bundle not cached') &&
msg.state.phase === 'initializing'
);
assert('produce two bundle cache events while initializing', bundleCacheStates.length === 2);
assert('produce three bundle cache events while initializing', bundleCacheStates.length === 3);

const initializedStates = msgs.filter(msg => msg.state.phase === 'initialized');
assert('produce at least one initialized event', initializedStates.length >= 1);
Expand All @@ -101,12 +101,12 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {

const runningStates = msgs.filter(msg => msg.state.phase === 'running');
assert(
'produce two or three "running" states',
runningStates.length === 2 || runningStates.length === 3
'produce four or five "running" states',
runningStates.length === 4 || runningStates.length === 5
);

const bundleNotCachedEvents = msgs.filter(msg => msg.event?.type === 'bundle not cached');
assert('produce two "bundle not cached" events', bundleNotCachedEvents.length === 2);
assert('produce three "bundle not cached" events', bundleNotCachedEvents.length === 3);

const successStates = msgs.filter(msg => msg.state.phase === 'success');
assert(
Expand All @@ -124,6 +124,13 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
);
assert('produce zero unexpected states', otherStates.length === 0, otherStates);

expect(
Fs.readFileSync(
Path.resolve(MOCK_REPO_DIR, 'src/core/public/target/public/core.standalone.js'),
'utf8'
)
).toMatchSnapshot('core bundle');

expect(
Fs.readFileSync(Path.resolve(MOCK_REPO_DIR, 'plugins/foo/target/public/foo.plugin.js'), 'utf8')
).toMatchSnapshot('foo bundle');
Expand Down Expand Up @@ -198,6 +205,7 @@ it('uses cache on second run and exist cleanly', async () => {
"initializing",
"initializing",
"initializing",
"initializing",
"initialized",
"success",
]
Expand Down
30 changes: 30 additions & 0 deletions packages/kbn-optimizer/src/integration_tests/bundle_cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ it('emits "bundle cached" event when everything is updated', async () => {

expect(cacheEvents).toMatchInlineSnapshot(`
Array [
Object {
"bundle": <Bundle>,
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"type": "bundle cached",
Expand Down Expand Up @@ -128,6 +133,11 @@ it('emits "bundle not cached" event when cacheKey is up to date but caching is d
"reason": "cache disabled",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"reason": "cache disabled",
"type": "bundle not cached",
},
]
`);
});
Expand Down Expand Up @@ -168,6 +178,11 @@ it('emits "bundle not cached" event when optimizerCacheKey is missing', async ()
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
]
`);
});
Expand Down Expand Up @@ -213,6 +228,11 @@ it('emits "bundle not cached" event when optimizerCacheKey is outdated, includes
"reason": "optimizer cache key mismatch",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
]
`);
});
Expand Down Expand Up @@ -251,6 +271,11 @@ it('emits "bundle not cached" event when cacheKey is missing', async () => {
"reason": "missing cache key",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
]
`);
});
Expand Down Expand Up @@ -286,6 +311,11 @@ it('emits "bundle not cached" event when cacheKey is outdated', async () => {

expect(cacheEvents).toMatchInlineSnapshot(`
Array [
Object {
"bundle": <Bundle>,
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"diff": "- Expected
Expand Down
10 changes: 9 additions & 1 deletion packages/kbn-optimizer/src/optimizer/get_bundles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { getBundles } from './get_bundles';

expect.addSnapshotSerializer(createAbsolutePathSerializer('/repo'));

it('returns a bundle for each plugin', () => {
it('returns a bundle for core and each plugin', () => {
expect(
getBundles(
[
Expand All @@ -47,6 +47,14 @@ it('returns a bundle for each plugin', () => {
).map(b => b.toSpec())
).toMatchInlineSnapshot(`
Array [
Object {
"contextDir": <absolute path>/src/core,
"entry": "./public/entry_point",
"id": "core",
"outputDir": <absolute path>/src/core/public/target/public,
"sourceRoot": <absolute path>,
"type": "standalone",
},
Object {
"contextDir": <absolute path>/plugins/foo,
"entry": "./public/index",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) {

output: {
path: bundle.outputDir,
filename: '[name].plugin.js',
filename: `[name].${bundle.type}.js`,
publicPath: PUBLIC_PATH_PLACEHOLDER,
devtoolModuleFilenameTemplate: info =>
`/${bundle.type}:${bundle.id}/${Path.relative(
Expand Down

0 comments on commit 98c767e

Please sign in to comment.