Skip to content

Commit 42b17cc

Browse files
committed
Add test for throwing if there are no files found
1 parent 1caee89 commit 42b17cc

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function importModule(name) {
2+
return import(`./module-dir-c/${name}.js`);
3+
}

β€Žpackages/dynamic-import-vars/test/rollup-plugin-dynamic-import-vars.test.jsβ€Ž

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,29 @@ test('dynamic imports assertions', async (t) => {
204204
);
205205
t.snapshot(output[0].code);
206206
});
207+
208+
test("doesn't throw if no files in dir when option isn't set", async (t) => {
209+
let thrown = false;
210+
try {
211+
await rollup({
212+
input: 'fixture-no-files.js',
213+
plugins: [dynamicImportVars()]
214+
});
215+
} catch (_) {
216+
thrown = true;
217+
}
218+
t.false(thrown);
219+
});
220+
221+
test('throws if no files in dir when option is set', async (t) => {
222+
let thrown = false;
223+
try {
224+
await rollup({
225+
input: 'fixture-no-files.js',
226+
plugins: [dynamicImportVars({ errorWhenNoFilesFound: true })]
227+
});
228+
} catch (_) {
229+
thrown = true;
230+
}
231+
t.true(thrown);
232+
});

β€Žpackages/dynamic-import-vars/test/snapshots/rollup-plugin-dynamic-import-vars.test.js.mdβ€Ž

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,25 @@ Generated by [AVA](https://avajs.dev).
234234
␊
235235
export { importModule };␊
236236
`
237+
238+
## no files in dir
239+
240+
> Snapshot 1
241+
242+
`function __variableDynamicImportRuntime0__(path) {␊
243+
switch (path) {␊
244+
␊
245+
default: return new Promise(function(resolve, reject) {␊
246+
(typeof queueMicrotask === 'function' ? queueMicrotask : setTimeout)(␊
247+
reject.bind(null, new Error("Unknown variable dynamic import: " + path))␊
248+
);␊
249+
})␊
250+
}␊
251+
}␊
252+
␊
253+
function importModule(name) {␊
254+
return __variableDynamicImportRuntime0__(\`./module-dir-c/${name}.js\`);␊
255+
}␊
256+
␊
257+
export { importModule };␊
258+
`
Binary file not shown.

0 commit comments

Comments
Β (0)