Skip to content

Commit

Permalink
test: add rollup resolve test
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Oct 10, 2024
1 parent fe8fbb0 commit 1e29291
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/rollup-plugin-import-meta-assets/test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,43 @@ describe('rollup-plugin-import-meta-assets', () => {
expectAsset(output, 'snapshots/two.svg', 'two.svg', 'assets/two--yckvrYd.svg'),
expectAsset(output, 'snapshots/three.svg', 'three.svg', 'assets/three-CDdgprDC.svg'),
expectAsset(output, 'snapshots/four.svg', 'four.svg', 'assets/four-lJVunLww.svg'),

it('respects the rollup resolution', async () => {
const config = {
input: { 'simple-bundle-switched': require.resolve('./fixtures/simple-entrypoint.js') },
plugins: [
importMetaAssets(),
{
resolveId(source, importer) {
if (source == './one.svg') {
return path.resolve(path.dirname(importer), 'two.svg');
}
if (source == './two.svg') {
return path.resolve(path.dirname(importer), 'one.svg');
}
if (source === './three.svg') {
return {
id: source,
external: true,
};
}
return undefined;
},
},
],
};

const bundle = await rollup.rollup(config);
const { output } = await bundle.generate(outputConfig);

expect(output.length).to.equal(5);
expectChunk(output, 'snapshots/simple-bundle-switched.js', 'simple-bundle-switched.js', [
expectAsset(output, 'snapshots/two.svg', 'two.svg', 'assets/two--yckvrYd.svg'),
expectAsset(output, 'snapshots/one.svg', 'one.svg', 'assets/one-ZInu4dBJ.svg'),
expectAsset(output, 'snapshots/four.svg', 'four.svg', 'assets/four-lJVunLww.svg'),
expectAsset(output, 'snapshots/five', 'five', 'assets/five-Z74_0e9C'),
]);
}),
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const justUrlObject = new URL(new URL('assets/two--yckvrYd.svg', import.meta.url).href, import.meta.url);
const href = new URL(new URL('assets/one-ZInu4dBJ.svg', import.meta.url).href, import.meta.url).href;
const pathname = new URL('./three.svg', import.meta.url).pathname;
const searchParams = new URL(new URL('assets/four-lJVunLww.svg', import.meta.url).href, import.meta.url).searchParams;
const noExtension = new URL(new URL('assets/five-Z74_0e9C', import.meta.url).href, import.meta.url);

console.log({
justUrlObject,
href,
pathname,
searchParams,
noExtension,
});

0 comments on commit 1e29291

Please sign in to comment.