Skip to content

Commit 1e29291

Browse files
author
Loïc Mangeonjean
committed
test: add rollup resolve test
1 parent fe8fbb0 commit 1e29291

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

packages/rollup-plugin-import-meta-assets/test/integration.test.js

+37
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,43 @@ describe('rollup-plugin-import-meta-assets', () => {
294294
expectAsset(output, 'snapshots/two.svg', 'two.svg', 'assets/two--yckvrYd.svg'),
295295
expectAsset(output, 'snapshots/three.svg', 'three.svg', 'assets/three-CDdgprDC.svg'),
296296
expectAsset(output, 'snapshots/four.svg', 'four.svg', 'assets/four-lJVunLww.svg'),
297+
298+
it('respects the rollup resolution', async () => {
299+
const config = {
300+
input: { 'simple-bundle-switched': require.resolve('./fixtures/simple-entrypoint.js') },
301+
plugins: [
302+
importMetaAssets(),
303+
{
304+
resolveId(source, importer) {
305+
if (source == './one.svg') {
306+
return path.resolve(path.dirname(importer), 'two.svg');
307+
}
308+
if (source == './two.svg') {
309+
return path.resolve(path.dirname(importer), 'one.svg');
310+
}
311+
if (source === './three.svg') {
312+
return {
313+
id: source,
314+
external: true,
315+
};
316+
}
317+
return undefined;
318+
},
319+
},
320+
],
321+
};
322+
323+
const bundle = await rollup.rollup(config);
324+
const { output } = await bundle.generate(outputConfig);
325+
326+
expect(output.length).to.equal(5);
327+
expectChunk(output, 'snapshots/simple-bundle-switched.js', 'simple-bundle-switched.js', [
328+
expectAsset(output, 'snapshots/two.svg', 'two.svg', 'assets/two--yckvrYd.svg'),
329+
expectAsset(output, 'snapshots/one.svg', 'one.svg', 'assets/one-ZInu4dBJ.svg'),
330+
expectAsset(output, 'snapshots/four.svg', 'four.svg', 'assets/four-lJVunLww.svg'),
331+
expectAsset(output, 'snapshots/five', 'five', 'assets/five-Z74_0e9C'),
332+
]);
333+
}),
297334
]);
298335
});
299336
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const justUrlObject = new URL(new URL('assets/two--yckvrYd.svg', import.meta.url).href, import.meta.url);
2+
const href = new URL(new URL('assets/one-ZInu4dBJ.svg', import.meta.url).href, import.meta.url).href;
3+
const pathname = new URL('./three.svg', import.meta.url).pathname;
4+
const searchParams = new URL(new URL('assets/four-lJVunLww.svg', import.meta.url).href, import.meta.url).searchParams;
5+
const noExtension = new URL(new URL('assets/five-Z74_0e9C', import.meta.url).href, import.meta.url);
6+
7+
console.log({
8+
justUrlObject,
9+
href,
10+
pathname,
11+
searchParams,
12+
noExtension,
13+
});

0 commit comments

Comments
 (0)