From e7890b2427479ef759de1456db82bbdc153343e0 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Wed, 4 Mar 2020 21:44:30 +0300 Subject: [PATCH] test(run): add test broker in the latest rollup I found case where new rollup fails with run plugin. When entry point and dynamic import use the same module chunk.modules becomes empty. Run checks `chunk.modules[input]` for some reason which fails when chunk.modules is empty. --- packages/run/test/fixtures/dynamic.js | 2 ++ packages/run/test/fixtures/input-with-dynamic.js | 5 +++++ packages/run/test/fixtures/log.js | 1 + packages/run/test/test.js | 10 ++++++++++ 4 files changed, 18 insertions(+) create mode 100644 packages/run/test/fixtures/dynamic.js create mode 100644 packages/run/test/fixtures/input-with-dynamic.js create mode 100644 packages/run/test/fixtures/log.js diff --git a/packages/run/test/fixtures/dynamic.js b/packages/run/test/fixtures/dynamic.js new file mode 100644 index 000000000..c6463f84c --- /dev/null +++ b/packages/run/test/fixtures/dynamic.js @@ -0,0 +1,2 @@ +import { log } from './log.js'; +log(0) diff --git a/packages/run/test/fixtures/input-with-dynamic.js b/packages/run/test/fixtures/input-with-dynamic.js new file mode 100644 index 000000000..6ae636ab5 --- /dev/null +++ b/packages/run/test/fixtures/input-with-dynamic.js @@ -0,0 +1,5 @@ +import { log } from "./log.js"; +log(0); +(async () => { + await import("./dynamic.js"); +})(); diff --git a/packages/run/test/fixtures/log.js b/packages/run/test/fixtures/log.js new file mode 100644 index 000000000..bc12ab398 --- /dev/null +++ b/packages/run/test/fixtures/log.js @@ -0,0 +1 @@ +export const log = value => console.log(value); diff --git a/packages/run/test/test.js b/packages/run/test/test.js index a20e1441b..d8ce23196 100644 --- a/packages/run/test/test.js +++ b/packages/run/test/test.js @@ -83,6 +83,16 @@ test('detects changes - forks a new child process and kills older process', asyn t.is(mockChildProcess().kill.callCount, 1); }); +test.only('works when chunk is use in entry and dynamic import', async (t) => { + const bundle = await rollup({ + input: join(cwd, 'input-with-dynamic.js'), + plugins: [run()] + }); + await t.notThrowsAsync(async () => { + await bundle.write({ dir: join(cwd, 'output'), format: 'cjs' }); + }); +}); + test.after(async () => { await del(['output']); });