Skip to content

Commit f784376

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

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

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

+39-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ describe('rollup-plugin-import-meta-assets', () => {
237237
error = e;
238238
}
239239

240-
expect(error.message).to.eq(
241-
`Unable to resolve "/absolute-path.svg" from "/home/loic/git/web/packages/rollup-plugin-import-meta-assets/test/fixtures/bad-url-entrypoint.js"`,
240+
expect(error.message).to.match(
241+
/Unable to resolve "[/\\]absolute-path.svg" from ".*[/\\]bad-url-entrypoint.js"/,
242242
);
243243
});
244244

@@ -296,4 +296,41 @@ describe('rollup-plugin-import-meta-assets', () => {
296296
expectAsset(output, 'snapshots/four.svg', 'four.svg', 'assets/four-lJVunLww.svg'),
297297
]);
298298
});
299+
300+
it('respects the rollup resolution', async () => {
301+
const config = {
302+
input: { 'simple-bundle-switched': require.resolve('./fixtures/simple-entrypoint.js') },
303+
plugins: [
304+
importMetaAssets(),
305+
{
306+
resolveId(source, importer) {
307+
if (source == './one.svg') {
308+
return path.resolve(path.dirname(importer), 'two.svg');
309+
}
310+
if (source == './two.svg') {
311+
return path.resolve(path.dirname(importer), 'one.svg');
312+
}
313+
if (source === './three.svg') {
314+
return {
315+
id: source,
316+
external: true,
317+
};
318+
}
319+
return undefined;
320+
},
321+
},
322+
],
323+
};
324+
325+
const bundle = await rollup.rollup(config);
326+
const { output } = await bundle.generate(outputConfig);
327+
328+
expect(output.length).to.equal(5);
329+
expectChunk(output, 'snapshots/simple-bundle-switched.js', 'simple-bundle-switched.js', [
330+
expectAsset(output, 'snapshots/two.svg', 'two.svg', 'assets/two--yckvrYd.svg'),
331+
expectAsset(output, 'snapshots/one.svg', 'one.svg', 'assets/one-ZInu4dBJ.svg'),
332+
expectAsset(output, 'snapshots/four.svg', 'four.svg', 'assets/four-lJVunLww.svg'),
333+
expectAsset(output, 'snapshots/five', 'five', 'assets/five-Z74_0e9C'),
334+
]);
335+
});
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)