From 5ee3a9b875d568f2045ae871dc6c2ad1ddd0c617 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Tue, 23 Jul 2024 16:30:29 -0700 Subject: [PATCH] fix(bundle-source): Recognize default metadata --- packages/bundle-source/cache.js | 6 +++--- packages/bundle-source/src/bundle-source.js | 2 +- packages/bundle-source/test/cache.test.js | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 packages/bundle-source/test/cache.test.js diff --git a/packages/bundle-source/cache.js b/packages/bundle-source/cache.js index 74220fa760..9c0b612ef5 100644 --- a/packages/bundle-source/cache.js +++ b/packages/bundle-source/cache.js @@ -2,7 +2,7 @@ import { makePromiseKit } from '@endo/promise-kit'; import { makeReadPowers } from '@endo/compartment-mapper/node-powers.js'; -import bundleSource from './src/index.js'; +import bundleSource, { DEFAULT_MODULE_FORMAT } from './src/bundle-source.js'; import { makeFileReader, makeAtomicFileWriter } from './src/fs.js'; const { Fail, quote: q } = assert; @@ -167,8 +167,8 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { ) => { await null; const { - noTransforms: expectedNoTransforms, - format: expectedFormat, + noTransforms: expectedNoTransforms = false, + format: expectedFormat = DEFAULT_MODULE_FORMAT, conditions: expectedConditions = [], } = options; expectedConditions.sort(); diff --git a/packages/bundle-source/src/bundle-source.js b/packages/bundle-source/src/bundle-source.js index 7eb9517263..ce184350bf 100644 --- a/packages/bundle-source/src/bundle-source.js +++ b/packages/bundle-source/src/bundle-source.js @@ -1,5 +1,5 @@ // @ts-check -const DEFAULT_MODULE_FORMAT = 'endoZipBase64'; +export const DEFAULT_MODULE_FORMAT = 'endoZipBase64'; export const SUPPORTED_FORMATS = [ 'getExport', 'nestedEvaluate', diff --git a/packages/bundle-source/test/cache.test.js b/packages/bundle-source/test/cache.test.js new file mode 100644 index 0000000000..d2b72873d4 --- /dev/null +++ b/packages/bundle-source/test/cache.test.js @@ -0,0 +1,18 @@ +import url from 'url'; +import test from '@endo/ses-ava/prepare-endo.js'; +import { makeNodeBundleCache } from '../cache.js'; + +test('cache can capture and verify metadata', async t => { + const dest = url.fileURLToPath(new URL('../bundles/', import.meta.url)); + const entry = url.fileURLToPath( + new URL('../demo/meaning.js', import.meta.url), + ); + const cache = await makeNodeBundleCache( + dest, + {}, + specifier => import(specifier), + ); + await cache.validateOrAdd(entry, 'cache-test-meaning', t.log); + await cache.validate('cache-test-meaning', undefined, t.log); + t.pass(); +});