From ae59532f12f3ef0d71275b08d006bf67d181a152 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Sat, 4 Mar 2017 16:14:56 -0500 Subject: [PATCH] Delete MeteorDynamicImportCache database before running tests. Also run the tests a third time without deleting the database, to exercise the caching logic. --- tools/tests/apps/dynamic-import/tests.js | 15 +++++++++++++++ tools/tests/dynamic-import.js | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/tools/tests/apps/dynamic-import/tests.js b/tools/tests/apps/dynamic-import/tests.js index 0905ce7386..03a9b39d03 100644 --- a/tools/tests/apps/dynamic-import/tests.js +++ b/tools/tests/apps/dynamic-import/tests.js @@ -1,6 +1,21 @@ import assert from "assert"; describe("dynamic import(...)", function () { + if (global.indexedDB) { + const saveCache = process.env.METEOR_SAVE_DYNAMIC_IMPORT_CACHE; + if (! (saveCache && JSON.parse(saveCache))) { + it("cleared the IndexedDB cache", function () { + return new Promise((resolve, reject) => { + const deleteRequest = + global.indexedDB.deleteDatabase("MeteorDynamicImportCache"); + deleteRequest.onerror = + deleteRequest.onblocked = + deleteRequest.onsuccess = resolve; + }); + }); + } + } + it("import same module both statically and dynamically", function () { import moment from "moment"; return import("./imports/date").then(date => { diff --git a/tools/tests/dynamic-import.js b/tools/tests/dynamic-import.js index e667952907..fc80941d39 100644 --- a/tools/tests/dynamic-import.js +++ b/tools/tests/dynamic-import.js @@ -13,6 +13,13 @@ selftest.define("dynamic import(...) in production", function () { s.cd("dynamic-import-test-app-prod", run.bind(s, true)); }); +selftest.define("dynamic import(...) with cache", function () { + const s = new Sandbox(); + s.createApp("dynamic-import-test-app-cache", "dynamic-import"); + s.set("METEOR_SAVE_DYNAMIC_IMPORT_CACHE", "true"); + s.cd("dynamic-import-test-app-cache", run.bind(s, true)); +}); + function run(isProduction) { const sandbox = this; const args = [