chore: switch to jest for testing

This commit is contained in:
2024-02-21 00:04:36 +01:00
parent 3b540d0c48
commit e46f668ac8
47 changed files with 50329 additions and 839 deletions

View File

@@ -0,0 +1,78 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`basic inline-script 1`] = `
[
{
"code": undefined,
"fileName": "script.body.script.js-e3b82208.js.map",
"map": undefined,
"source": "{"version":3,"file":"script.body.script.js-e3b82208.js","sources":["../batman.js","../script.html.body.script.js"],"sourcesContent":["export const b = ()=>'batman';\\nconsole.log(b());\\n","\\n import {b} from \\"./batman.js\\";\\n document.body.appendChild(\\n document.createTextNode(\`Inline script including \${b()}\`)\\n );\\n "],"names":[],"mappings":"AAAO,MAAM,CAAC,GAAG,IAAI,QAAQ,CAAC;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;ACCJ,QAAQ,CAAC,IAAI,CAAC,WAAW;AACrC,gBAAgB,QAAQ,CAAC,cAAc,CAAC,CAAC,wBAAwB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACzE,aAAa"}",
},
{
"code": undefined,
"fileName": "script.html",
"map": undefined,
"source": "<html><head>
</head>
<body>
<script type="module">const b = ()=>'batman';
console.log(b());
document.body.appendChild(
document.createTextNode(\`Inline script including \${b()}\`)
);
//# sourceMappingURL=script.body.script.js-e3b82208.js.map
</script>
</body></html>",
},
]
`;
exports[`basic simple 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>
</head>
<body>
<script src="batman-c7fa228c.js" type="module"></script>
</body></html>",
},
]
`;

View File

@@ -1,86 +0,0 @@
# Snapshot report for `test/basic/test.js`
The actual snapshot is saved in `test.js.snap`.
Generated by [AVA](https://avajs.dev).
## simple
> 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>␊
</head>␊
<body>␊
<script src="batman-c7fa228c.js" type="module"></script>␊
</body></html>`,
},
]
## inline-script
> Snapshot 1
[
{
code: undefined,
fileName: 'script.body.script.js-e3b82208.js.map',
map: undefined,
source: '{"version":3,"file":"script.body.script.js-e3b82208.js","sources":["../batman.js","../script.html.body.script.js"],"sourcesContent":["export const b = ()=>\'batman\';\\nconsole.log(b());\\n","\\n import {b} from \\"./batman.js\\";\\n document.body.appendChild(\\n document.createTextNode(`Inline script including ${b()}`)\\n );\\n "],"names":[],"mappings":"AAAO,MAAM,CAAC,GAAG,IAAI,QAAQ,CAAC;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;ACCJ,QAAQ,CAAC,IAAI,CAAC,WAAW;AACrC,gBAAgB,QAAQ,CAAC,cAAc,CAAC,CAAC,wBAAwB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACzE,aAAa"}',
},
{
code: undefined,
fileName: 'script.html',
map: undefined,
source: `<html><head>␊
</head>␊
<body>␊
<script type="module">const b = ()=>'batman';␊
console.log(b());␊
document.body.appendChild(␊
document.createTextNode(\`Inline script including ${b()}\`)␊
);␊
//# sourceMappingURL=script.body.script.js-e3b82208.js.map␊
</script>␊
</body></html>`,
},
]

Binary file not shown.

View File

@@ -1,6 +1,7 @@
import {join, dirname} from "node:path";
import test from "ava";
import {test, expect} from "@jest/globals";
import { rollup } from "rollup";
import {debugPrintOutput, getCode} from "../util/index.ts";
@@ -16,35 +17,37 @@ import {fileURLToPath} from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
process.chdir(join(__dirname, 'fixtures'));
test.serial('simple', async (t) => {
const bundle = await rollup({
input: 'index.html',
plugins: [
html({
}),
]
describe("basic", ()=> {
test('simple', async () => {
const bundle = await rollup({
input: 'index.html',
plugins: [
html({}),
]
});
const code = await getCode(bundle, output);
await bundle.close();
debugPrintOutput('simple', code);
expect(code).toMatchSnapshot();
});
const code = await getCode(bundle, output);
debugPrintOutput('simple',code);
t.snapshot(code);
});
test.serial('inline-script', async (t) => {
const bundle = await rollup({
input: 'script.html',
plugins: [
html({
}),
]
test('inline-script', async () => {
const bundle = await rollup({
input: 'script.html',
plugins: [
html({}),
]
});
const code = await getCode(bundle, output);
await bundle.close();
debugPrintOutput('inline-script', code);
expect(code).toMatchSnapshot();
});
const code = await getCode(bundle, output);
debugPrintOutput('inline-script',code);
t.snapshot(code);
});
// TODO various parameters
// - format: cjs, iifi, ...
// - sourcemap: inline, false, (and the various exotic sourcemap options)
// Watch mode tests would be its own dir
// ...
});