chore: switch to jest for testing
This commit is contained in:
47
test/watch/__snapshots__/test.js.snap
Normal file
47
test/watch/__snapshots__/test.js.snap
Normal file
@@ -0,0 +1,47 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`watch 1`] = `
|
||||
[
|
||||
{
|
||||
"code": undefined,
|
||||
"fileName": "index.html",
|
||||
"map": undefined,
|
||||
"source": "<html><head>
|
||||
</head>
|
||||
<body>
|
||||
<script src="watched-file.js" type="module"></script>
|
||||
|
||||
|
||||
</body></html>",
|
||||
},
|
||||
{
|
||||
"code": "const a = 2; // If i show up as a changed file, then the watch test has gone wrong!
|
||||
|
||||
export { a };
|
||||
//# sourceMappingURL=watched-file.js.map
|
||||
",
|
||||
"fileName": "watched-file.js",
|
||||
"map": SourceMap {
|
||||
"file": "watched-file.js",
|
||||
"mappings": "AACgB,MAAC,CAAC,GAAG,EAAE;;;;",
|
||||
"names": [],
|
||||
"sources": [
|
||||
"../watched-file.js",
|
||||
],
|
||||
"sourcesContent": [
|
||||
"
|
||||
export const a = 2; // If i show up as a changed file, then the watch test has gone wrong!
|
||||
",
|
||||
],
|
||||
"version": 3,
|
||||
},
|
||||
"source": undefined,
|
||||
},
|
||||
{
|
||||
"code": undefined,
|
||||
"fileName": "watched-file.js.map",
|
||||
"map": undefined,
|
||||
"source": "{"version":3,"file":"watched-file.js","sources":["../watched-file.js"],"sourcesContent":["\\n export const a = 2; // If i show up as a changed file, then the watch test has gone wrong!\\n "],"names":[],"mappings":"AACgB,MAAC,CAAC,GAAG,EAAE;;;;"}",
|
||||
},
|
||||
]
|
||||
`;
|
||||
@@ -1,53 +0,0 @@
|
||||
# Snapshot report for `test/watch/test.js`
|
||||
|
||||
The actual snapshot is saved in `test.js.snap`.
|
||||
|
||||
Generated by [AVA](https://avajs.dev).
|
||||
|
||||
## watch
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
[
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'index.html',
|
||||
map: undefined,
|
||||
source: `<html><head>␊
|
||||
</head>␊
|
||||
<body>␊
|
||||
<script src="watched-file-8c4729c5.js" type="module"></script>␊
|
||||
␊
|
||||
␊
|
||||
</body></html>`,
|
||||
},
|
||||
{
|
||||
code: `const a = 2; // If i show up as a changed file, then the watch test has gone wrong!␊
|
||||
␊
|
||||
export { a };␊
|
||||
//# sourceMappingURL=watched-file-8c4729c5.js.map␊
|
||||
`,
|
||||
fileName: 'watched-file-8c4729c5.js',
|
||||
map: SourceMap {
|
||||
file: 'watched-file-8c4729c5.js',
|
||||
mappings: 'AACgB,MAAC,CAAC,GAAG,EAAE;;;;',
|
||||
names: [],
|
||||
sources: [
|
||||
'../watched-file.js',
|
||||
],
|
||||
sourcesContent: [
|
||||
`␊
|
||||
export const a = 2; // If i show up as a changed file, then the watch test has gone wrong!␊
|
||||
`,
|
||||
],
|
||||
version: 3,
|
||||
},
|
||||
source: undefined,
|
||||
},
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'watched-file-8c4729c5.js.map',
|
||||
map: undefined,
|
||||
source: '{"version":3,"file":"watched-file-8c4729c5.js","sources":["../watched-file.js"],"sourcesContent":["\\n export const a = 2; // If i show up as a changed file, then the watch test has gone wrong!\\n "],"names":[],"mappings":"AACgB,MAAC,CAAC,GAAG,EAAE;;;;"}',
|
||||
},
|
||||
]
|
||||
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 * as rollup from "rollup";
|
||||
import {debugPrintOutput, getCode} from "../util/index.ts";
|
||||
import {resolve} from "node:path";
|
||||
@@ -12,6 +12,10 @@ const output = {
|
||||
dir: 'output', // Output all files
|
||||
format: 'es', // iifi and cjs should be added to tests
|
||||
sourcemap: true,// Test if #sourcemapUrl is not accidentally included in the html-output
|
||||
// Prevent hashes from being added (and screw up the snapshots)
|
||||
chunkFileNames: '[name].js',
|
||||
entryFileNames: '[name].[extname]',
|
||||
assetFileNames: '[name].[extname]',
|
||||
};
|
||||
|
||||
import {fileURLToPath} from "node:url";
|
||||
@@ -20,7 +24,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
process.chdir(join(__dirname, 'fixtures'));
|
||||
|
||||
|
||||
test.serial('watch', async (t) => {
|
||||
test('watch', async () => {
|
||||
const origContent = `
|
||||
export const a = 1; // DO NOT CHANGE ME HERE, but in ../test.js
|
||||
`;
|
||||
@@ -56,25 +60,26 @@ test.serial('watch', async (t) => {
|
||||
await writeFile(path, origContent, {encoding: 'utf-8'});
|
||||
|
||||
// Assert the output is what we exapect;
|
||||
t.snapshot(code);
|
||||
expect(code).toMatchSnapshot();
|
||||
|
||||
watcher
|
||||
},
|
||||
];
|
||||
const log = console.log;
|
||||
|
||||
await new Promise((resolve, reject)=>{
|
||||
watcher.on('event', async (event) => {
|
||||
const {result} = event;
|
||||
switch (event.code) {
|
||||
case "START":
|
||||
t.log(`WATCH STARTED`);
|
||||
log(`WATCH STARTED`);
|
||||
break;
|
||||
case "BUNDLE_START":
|
||||
t.log(`REBUILDING...`);
|
||||
log(`REBUILDING...`);
|
||||
|
||||
break;
|
||||
case "BUNDLE_END":
|
||||
t.log(`Rebuilt...`);
|
||||
log(`Rebuilt...`);
|
||||
const cb = steps.shift();
|
||||
|
||||
const generated = await result.generate(output);
|
||||
@@ -94,4 +99,6 @@ test.serial('watch', async (t) => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
await watcher.close();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user