chore: switch to jest for testing
This commit is contained in:
97
test/url-plugin/__snapshots__/test.js.snap
Normal file
97
test/url-plugin/__snapshots__/test.js.snap
Normal file
@@ -0,0 +1,97 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`url-plugin copied-assets 1`] = `
|
||||
[
|
||||
{
|
||||
"code": "const b = ()=>'batman';
|
||||
console.log(b());
|
||||
|
||||
export { b };
|
||||
//# sourceMappingURL=batman-c7fa228c.js.map
|
||||
",
|
||||
"fileName": "batman-c7fa228c.js",
|
||||
"map": SourceMap {
|
||||
"file": "batman-c7fa228c.js",
|
||||
"mappings": "AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;",
|
||||
"names": [],
|
||||
"sources": [
|
||||
"../batman.js",
|
||||
],
|
||||
"sourcesContent": [
|
||||
"export const b = ()=>'batman';
|
||||
console.log(b());
|
||||
",
|
||||
],
|
||||
"version": 3,
|
||||
},
|
||||
"source": undefined,
|
||||
},
|
||||
{
|
||||
"code": undefined,
|
||||
"fileName": "batman-c7fa228c.js.map",
|
||||
"map": undefined,
|
||||
"source": "{"version":3,"file":"batman-c7fa228c.js","sources":["../batman.js"],"sourcesContent":["export const b = ()=>'batman';\\nconsole.log(b());\\n"],"names":[],"mappings":"AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;"}",
|
||||
},
|
||||
{
|
||||
"code": undefined,
|
||||
"fileName": "index.html",
|
||||
"map": undefined,
|
||||
"source": "<html><head>
|
||||
<link rel="icon" href="fb585fdb6db313c9.svg">
|
||||
</head>
|
||||
<body>
|
||||
<script src="batman-c7fa228c.js" type="module"></script>
|
||||
|
||||
|
||||
</body></html>",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`url-plugin inlined-assets 1`] = `
|
||||
[
|
||||
{
|
||||
"code": "const b = ()=>'batman';
|
||||
console.log(b());
|
||||
|
||||
export { b };
|
||||
//# sourceMappingURL=batman-c7fa228c.js.map
|
||||
",
|
||||
"fileName": "batman-c7fa228c.js",
|
||||
"map": SourceMap {
|
||||
"file": "batman-c7fa228c.js",
|
||||
"mappings": "AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;",
|
||||
"names": [],
|
||||
"sources": [
|
||||
"../batman.js",
|
||||
],
|
||||
"sourcesContent": [
|
||||
"export const b = ()=>'batman';
|
||||
console.log(b());
|
||||
",
|
||||
],
|
||||
"version": 3,
|
||||
},
|
||||
"source": undefined,
|
||||
},
|
||||
{
|
||||
"code": undefined,
|
||||
"fileName": "batman-c7fa228c.js.map",
|
||||
"map": undefined,
|
||||
"source": "{"version":3,"file":"batman-c7fa228c.js","sources":["../batman.js"],"sourcesContent":["export const b = ()=>'batman';\\nconsole.log(b());\\n"],"names":[],"mappings":"AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;"}",
|
||||
},
|
||||
{
|
||||
"code": undefined,
|
||||
"fileName": "index.html",
|
||||
"map": undefined,
|
||||
"source": "<html><head>
|
||||
<link rel="icon" href="data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2032%2032%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%20%20%3Cpath%20style%3D%22fill%3Anone%3Bstroke%3A%2300ff0d%3Bstroke-width%3A5%3Bstroke-linecap%3Asquare%3Bstroke-linejoin%3Amiter%3Bstroke-dasharray%3Anone%3Bstroke-opacity%3A1%22%20d%3D%22M4.1%2014.72%2016%2026.31%2028.38%205.09%22%2F%3E%3C%2Fsvg%3E">
|
||||
</head>
|
||||
<body>
|
||||
<script src="batman-c7fa228c.js" type="module"></script>
|
||||
|
||||
|
||||
</body></html>",
|
||||
},
|
||||
]
|
||||
`;
|
||||
@@ -1,105 +0,0 @@
|
||||
# Snapshot report for `test/url-plugin/test.js`
|
||||
|
||||
The actual snapshot is saved in `test.js.snap`.
|
||||
|
||||
Generated by [AVA](https://avajs.dev).
|
||||
|
||||
## copied-assets
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
[
|
||||
{
|
||||
code: `const b = ()=>'batman';␊
|
||||
console.log(b());␊
|
||||
␊
|
||||
export { b };␊
|
||||
//# sourceMappingURL=batman-c7fa228c.js.map␊
|
||||
`,
|
||||
fileName: 'batman-c7fa228c.js',
|
||||
map: SourceMap {
|
||||
file: 'batman-c7fa228c.js',
|
||||
mappings: 'AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;',
|
||||
names: [],
|
||||
sources: [
|
||||
'../batman.js',
|
||||
],
|
||||
sourcesContent: [
|
||||
`export const b = ()=>'batman';␊
|
||||
console.log(b());␊
|
||||
`,
|
||||
],
|
||||
version: 3,
|
||||
},
|
||||
source: undefined,
|
||||
},
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'batman-c7fa228c.js.map',
|
||||
map: undefined,
|
||||
source: '{"version":3,"file":"batman-c7fa228c.js","sources":["../batman.js"],"sourcesContent":["export const b = ()=>\'batman\';\\nconsole.log(b());\\n"],"names":[],"mappings":"AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;"}',
|
||||
},
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'index.html',
|
||||
map: undefined,
|
||||
source: `<html><head>␊
|
||||
<link rel="icon" href="fb585fdb6db313c9.svg">␊
|
||||
</head>␊
|
||||
<body>␊
|
||||
<script src="batman-c7fa228c.js" type="module"></script>␊
|
||||
␊
|
||||
␊
|
||||
</body></html>`,
|
||||
},
|
||||
]
|
||||
|
||||
## inlined-assets
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
[
|
||||
{
|
||||
code: `const b = ()=>'batman';␊
|
||||
console.log(b());␊
|
||||
␊
|
||||
export { b };␊
|
||||
//# sourceMappingURL=batman-c7fa228c.js.map␊
|
||||
`,
|
||||
fileName: 'batman-c7fa228c.js',
|
||||
map: SourceMap {
|
||||
file: 'batman-c7fa228c.js',
|
||||
mappings: 'AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;',
|
||||
names: [],
|
||||
sources: [
|
||||
'../batman.js',
|
||||
],
|
||||
sourcesContent: [
|
||||
`export const b = ()=>'batman';␊
|
||||
console.log(b());␊
|
||||
`,
|
||||
],
|
||||
version: 3,
|
||||
},
|
||||
source: undefined,
|
||||
},
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'batman-c7fa228c.js.map',
|
||||
map: undefined,
|
||||
source: '{"version":3,"file":"batman-c7fa228c.js","sources":["../batman.js"],"sourcesContent":["export const b = ()=>\'batman\';\\nconsole.log(b());\\n"],"names":[],"mappings":"AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;"}',
|
||||
},
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'index.html',
|
||||
map: undefined,
|
||||
source: `<html><head>␊
|
||||
<link rel="icon" href="data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2032%2032%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%20%20%3Cpath%20style%3D%22fill%3Anone%3Bstroke%3A%2300ff0d%3Bstroke-width%3A5%3Bstroke-linecap%3Asquare%3Bstroke-linejoin%3Amiter%3Bstroke-dasharray%3Anone%3Bstroke-opacity%3A1%22%20d%3D%22M4.1%2014.72%2016%2026.31%2028.38%205.09%22%2F%3E%3C%2Fsvg%3E">␊
|
||||
</head>␊
|
||||
<body>␊
|
||||
<script src="batman-c7fa228c.js" type="module"></script>␊
|
||||
␊
|
||||
␊
|
||||
</body></html>`,
|
||||
},
|
||||
]
|
||||
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
import {join, dirname} from "node:path";
|
||||
import {test, expect} from "@jest/globals";
|
||||
|
||||
import test from "ava";
|
||||
import { rollup } from "rollup";
|
||||
import urlPlugin from "@rollup/plugin-url";
|
||||
|
||||
@@ -25,40 +25,43 @@ const defaultAssetInclude = [
|
||||
'**/*.(webm|mp4)',// video
|
||||
];
|
||||
|
||||
test.serial('copied-assets', async (t) => {
|
||||
const bundle = await rollup({
|
||||
input: 'index.html',
|
||||
plugins: [
|
||||
html({
|
||||
}),
|
||||
urlPlugin({
|
||||
include: defaultAssetInclude,
|
||||
limit: 0,// Never inline something
|
||||
}),
|
||||
],
|
||||
describe("url-plugin", ()=>{
|
||||
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, output);
|
||||
debugPrintOutput('copied-assets',code);
|
||||
expect(code).toMatchSnapshot();
|
||||
});
|
||||
const code = await getCode(bundle, output);
|
||||
debugPrintOutput('copied-assets',code);
|
||||
t.snapshot(code);
|
||||
});
|
||||
|
||||
|
||||
test.serial('inlined-assets', async (t) => {
|
||||
const bundle = await rollup({
|
||||
input: 'index.html',
|
||||
plugins: [
|
||||
html({
|
||||
}),
|
||||
urlPlugin({
|
||||
include: defaultAssetInclude,
|
||||
limit: Number.MAX_SAFE_INTEGER,// Always inline things
|
||||
}),
|
||||
]
|
||||
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, output);
|
||||
debugPrintOutput('inlined-assets',code);
|
||||
expect(code).toMatchSnapshot();
|
||||
});
|
||||
const code = await getCode(bundle, output);
|
||||
debugPrintOutput('inlined-assets',code);
|
||||
t.snapshot(code);
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
// TODO various parameters
|
||||
// - format: cjs, iifi, ...
|
||||
|
||||
Reference in New Issue
Block a user