import {join, dirname} from "node:path"; import {test, expect} from "@jest/globals"; import { rollup } from "rollup"; import urlPlugin from "@rollup/plugin-url"; import {debugPrintOutput, getCode, serializer} from "../util/index.ts"; import html from "../../src/index.ts"; import {fileURLToPath} from "node:url"; const __dirname = dirname(fileURLToPath(import.meta.url)); process.chdir(join(__dirname, 'fixtures')); const defaultAssetInclude = [ '**/*.(png|jpg|jpeg|gif|ico|svg)',// images, svg '**/*.(woff|woff2|eot|ttf|otf)',// fonts '**/*.(webm|mp4)',// video ]; describe("url-plugin", ()=>{ expect.addSnapshotSerializer(serializer); test('copied-assets', async () => { const bundle = await rollup({ input: 'index.html', plugins: [ html({ }), urlPlugin({ include: defaultAssetInclude, limit: 0,// Never inline something }), ], }); const code = await getCode(bundle); debugPrintOutput('copied-assets',code); expect({code}).toMatchSnapshot(); }); test('inlined-assets', async () => { const bundle = await rollup({ input: 'index.html', plugins: [ html({ }), urlPlugin({ include: defaultAssetInclude, limit: Number.MAX_SAFE_INTEGER,// Always inline things }), ] }); const code = await getCode(bundle); debugPrintOutput('inlined-assets',code); expect({code}).toMatchSnapshot(); }); }) // TODO various parameters // - format: cjs, iifi, ... // - sourcemap: inline, false, (and the various exotic sourcemap options) // Watch mode tests would be its own dir // ...