/livereload.js"); // remove any references to a port
}
}
- expect(code).toMatchSnapshot();
+ expect({code}).toMatchSnapshot();
});
// TODO various parameters
diff --git a/test/multi-entry/__snapshots__/test.js.snap b/test/multi-entry/__snapshots__/test.js.snap
index 0634627..5a7dfb6 100644
--- a/test/multi-entry/__snapshots__/test.js.snap
+++ b/test/multi-entry/__snapshots__/test.js.snap
@@ -1,125 +1,77 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`multi-entry 1`] = `
-[
- {
- "code": "const b = ()=>'batman';
-console.log(b());
-
-export { b };
-//# sourceMappingURL=batman.js.map
-",
- "fileName": "admin/batman.js",
- "map": SourceMap {
- "file": "batman.js",
- "mappings": "AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;",
- "names": [],
- "sources": [
- "../../admin/batman.js",
- ],
- "sourcesContent": [
- "export const b = ()=>'batman';
-console.log(b());
-",
- ],
- "version": 3,
- },
- "source": undefined,
- },
- {
- "code": undefined,
- "fileName": "admin/batman.js.map",
- "map": undefined,
- "source": "{"version":3,"file":"batman.js","sources":["../../admin/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": "admin/index.body.script0.js.js.map",
- "map": undefined,
- "source": "{"version":3,"file":"index.body.script0.js.js","sources":["../../app/admin-deps.js","../../admin/index.html.body.script0.js"],"sourcesContent":["export function adminDeps(){\\n return \\"robin!\\";\\n}\\n","\\n import {bootstrap} from \\"../app/app.js\\"\\n import {adminDeps} from \\"../app/admin-deps.js\\";\\n bootstrap(document.getElementById('root'), adminDeps());\\n "],"names":[],"mappings":";;AAAO,SAAS,SAAS,EAAE;AAC3B,IAAI,OAAO,QAAQ,CAAC;AACpB;;ACCY,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC"}",
- },
- {
- "code": undefined,
- "fileName": "admin/index.html",
- "map": undefined,
- "source": "
-
-
-
-
-
-
-
-",
- },
- {
- "code": "const bootstrap = (el,deps = [])=>{
- el.innerHtml = \`
- I'm "annoying" \${"in case we need to test \\\`string\\\` escaping."}. Hence this file \\'tries\\' to include all allowed forms of 'it'
- Deps: \${deps}
- \`;
-};
-
-export { bootstrap as b };
-//# sourceMappingURL=app.js.map
-",
- "fileName": "app.js",
- "map": SourceMap {
- "file": "app.js",
- "mappings": "AAAY,MAAC,SAAS,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,GAAG;AACzC,IAAI,EAAE,CAAC,SAAS,GAAG,CAAC;AACpB,4BAA4B,EAAE,8CAA8C,CAAC;AAC7E,mBAAmB,EAAE,IAAI,CAAC;AAC1B,IAAI,CAAC,CAAC;AACN;;;;",
- "names": [],
- "sources": [
- "../app/app.js",
- ],
- "sourcesContent": [
- "export const bootstrap = (el,deps = [])=>{
- el.innerHtml = \`
- I'm "annoying" \${"in case we need to test \\\`string\\\` escaping."}. Hence this file \\'tries\\' to include all allowed forms of 'it'
- Deps: \${deps}
- \`;
-}
-",
- ],
- "version": 3,
- },
- "source": undefined,
- },
- {
- "code": undefined,
- "fileName": "app.js.map",
- "map": undefined,
- "source": "{"version":3,"file":"app.js","sources":["../app/app.js"],"sourcesContent":["export const bootstrap = (el,deps = [])=>{\\n el.innerHtml = \`\\n I'm \\"annoying\\" \${\\"in case we need to test \\\\\`string\\\\\` escaping.\\"}. Hence this file \\\\'tries\\\\' to include all allowed forms of 'it'
\\n Deps: \${deps}
\\n \`;\\n}\\n"],"names":[],"mappings":"AAAY,MAAC,SAAS,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,GAAG;AACzC,IAAI,EAAE,CAAC,SAAS,GAAG,CAAC;AACpB,4BAA4B,EAAE,8CAA8C,CAAC;AAC7E,mBAAmB,EAAE,IAAI,CAAC;AAC1B,IAAI,CAAC,CAAC;AACN;;;;"}",
- },
- {
- "code": undefined,
- "fileName": "index.body.script.js.js.map",
- "map": undefined,
- "source": "{"version":3,"file":"index.body.script.js.js","sources":["../index.html.body.script.js"],"sourcesContent":["\\n import {bootstrap} from \\"./app/app.js\\"\\n bootstrap(document.getElementById('root'), \\"\\");\\n "],"names":[],"mappings":";;AAEY,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC"}",
- },
- {
- "code": undefined,
- "fileName": "index.html",
- "map": undefined,
- "source": "
-
-
-
-
-
-
-",
- },
-]
+ ####################
+ # admin/index.html #
+ ####################
+
+
+
+
+
+
+
+
+
+ ##############
+ # index.html #
+ ##############
+
+
+
+
+
+
+
+
+ ###################
+ # admin/batman.js #
+ ###################
+ const b = ()=>'batman';
+ console.log(b());
+
+ export { b };
+ //# sourceMappingURL=batman.js.map
+
+ #######################
+ # admin/batman.js.map #
+ #######################
+ {"version":3,"file":"batman.js","sources":["../../admin/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;;;;"}
+ ######################################
+ # admin/index.body.script0.js.js.map #
+ ######################################
+ {"version":3,"file":"index.body.script0.js.js","sources":["../../app/admin-deps.js","../../admin/index.html.body.script0.js"],"sourcesContent":["export function adminDeps(){\\n return \\"robin!\\";\\n}\\n","\\n import {bootstrap} from \\"../app/app.js\\"\\n import {adminDeps} from \\"../app/admin-deps.js\\";\\n bootstrap(document.getElementById('root'), adminDeps());\\n "],"names":[],"mappings":";;AAAO,SAAS,SAAS,EAAE;AAC3B,IAAI,OAAO,QAAQ,CAAC;AACpB;;ACCY,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC"}
+ ##########
+ # app.js #
+ ##########
+ const bootstrap = (el,deps = [])=>{
+ el.innerHtml = \`
+ I'm "annoying" \${"in case we need to test \\\`string\\\` escaping."}. Hence this file \\'tries\\' to include all allowed forms of 'it'
+ Deps: \${deps}
+ \`;
+ };
+
+ export { bootstrap as b };
+ //# sourceMappingURL=app.js.map
+
+ ##############
+ # app.js.map #
+ ##############
+ {"version":3,"file":"app.js","sources":["../app/app.js"],"sourcesContent":["export const bootstrap = (el,deps = [])=>{\\n el.innerHtml = \`\\n I'm \\"annoying\\" \${\\"in case we need to test \\\\\`string\\\\\` escaping.\\"}. Hence this file \\\\'tries\\\\' to include all allowed forms of 'it'
\\n Deps: \${deps}
\\n \`;\\n}\\n"],"names":[],"mappings":"AAAY,MAAC,SAAS,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,GAAG;AACzC,IAAI,EAAE,CAAC,SAAS,GAAG,CAAC;AACpB,4BAA4B,EAAE,8CAA8C,CAAC;AAC7E,mBAAmB,EAAE,IAAI,CAAC;AAC1B,IAAI,CAAC,CAAC;AACN;;;;"}
+ ###############################
+ # index.body.script.js.js.map #
+ ###############################
+ {"version":3,"file":"index.body.script.js.js","sources":["../index.html.body.script.js"],"sourcesContent":["\\n import {bootstrap} from \\"./app/app.js\\"\\n bootstrap(document.getElementById('root'), \\"\\");\\n "],"names":[],"mappings":";;AAEY,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC"}
`;
diff --git a/test/multi-entry/test.js b/test/multi-entry/test.js
index a8357d6..fe9ef1a 100644
--- a/test/multi-entry/test.js
+++ b/test/multi-entry/test.js
@@ -2,7 +2,7 @@ import {resolve, join, dirname} from "node:path";
import {test, expect} from "@jest/globals";
import { rollup } from "rollup";
-import {debugPrintOutput, getCode} from "../util/index.ts";
+import {debugPrintOutput, getCode, serializer} from "../util/index.ts";
import html from "../../src/index.ts";
@@ -12,6 +12,7 @@ process.chdir(join(__dirname, 'fixtures'));
test('multi-entry', async () => {
+ expect.addSnapshotSerializer(serializer);
const bundle = await rollup({
input: {
['index']: 'index.html',
@@ -24,7 +25,7 @@ test('multi-entry', async () => {
});
const code = await getCode(bundle);
debugPrintOutput('multi-entry',code);
- expect(code).toMatchSnapshot();
+ expect({code}).toMatchSnapshot();
});
// TODO various parameters
diff --git a/test/rewrite-url/__snapshots__/test.js.snap b/test/rewrite-url/__snapshots__/test.js.snap
index f3a5625..0cc4625 100644
--- a/test/rewrite-url/__snapshots__/test.js.snap
+++ b/test/rewrite-url/__snapshots__/test.js.snap
@@ -1,3 +1,59 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`rewrite-url 1`] = `undefined`;
+exports[`rewrite-url 1`] = `
+ ####################
+ # admin/index.html #
+ ####################
+
+
+
+
+
+
+
+
+ ##############
+ # index.html #
+ ##############
+
+
+
+
+
+
+
+
+ ################
+ # admin/app.js #
+ ################
+ const bootstrap = (el,deps = [])=>{
+ el.innerHtml = \`
+ load the app
+ \`;
+ };
+
+ export { bootstrap };
+ //# sourceMappingURL=app.js.map
+
+ ####################
+ # admin/app.js.map #
+ ####################
+ {"version":3,"file":"app.js","sources":["../../admin/app.js"],"sourcesContent":["export const bootstrap = (el,deps = [])=>{\\n el.innerHtml = \`\\n load the app
\\n \`;\\n}\\n"],"names":[],"mappings":"AAAY,MAAC,SAAS,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,GAAG;AACzC,IAAI,EAAE,CAAC,SAAS,GAAG,CAAC;AACpB;AACA,IAAI,CAAC,CAAC;AACN;;;;"}
+ #################
+ # RENDERED HTML #
+ #################
+
+
+
+
+
+
+
+
+ #############
+ # RESPONSES #
+ #############
+ 200 http://localhost/admin
+ 200 http://localhost/admin/app.js
+ 200 http://localhost/favicon.ico
+`;
diff --git a/test/rewrite-url/test.js b/test/rewrite-url/test.js
index d273b00..02387d4 100644
--- a/test/rewrite-url/test.js
+++ b/test/rewrite-url/test.js
@@ -1,7 +1,7 @@
import {resolve, join, dirname} from "node:path";
import {test, expect} from "@jest/globals";
-import {runBrowserTest} from "../util/index.ts";
+import {runBrowserTest, serializer} from "../util/index.ts";
import html from "../../src/index.ts";
@@ -11,6 +11,7 @@ process.chdir(join(__dirname, 'fixtures'));
test('rewrite-url', async () => {
+ expect.addSnapshotSerializer(serializer);
const out = await runBrowserTest({
input: {
['index']: 'index.html',
@@ -34,7 +35,7 @@ test('rewrite-url', async () => {
format: 'es', // iifi and cjs should be added to tests
sourcemap: true,// Test if #sourcemapUrl is not accidentally included in the html-output
});
- expect(out.code).toMatchSnapshot(); // Snapshot the result code
+ expect(out).toMatchSnapshot(); // Snapshot the result code
// const bundle = await rollup({
// input: {
diff --git a/test/templating/__snapshots__/test.js.snap b/test/templating/__snapshots__/test.js.snap
index 3363f1d..6ea0146 100644
--- a/test/templating/__snapshots__/test.js.snap
+++ b/test/templating/__snapshots__/test.js.snap
@@ -1,49 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`handlebars 1`] = `
-[
- {
- "code": "const b = ()=>'batman';
-console.log(b());
-
-export { b };
-//# sourceMappingURL=batman.js.map
-",
- "fileName": "batman.js",
- "map": SourceMap {
- "file": "batman.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.js.map",
- "map": undefined,
- "source": "{"version":3,"file":"batman.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": "
-
-
-
-
-
-
-",
- },
-]
+ ##############
+ # index.html #
+ ##############
+
+
+
+
+
+
+
+
+ #############
+ # batman.js #
+ #############
+ const b = ()=>'batman';
+ console.log(b());
+
+ export { b };
+ //# sourceMappingURL=batman.js.map
+
+ #################
+ # batman.js.map #
+ #################
+ {"version":3,"file":"batman.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;;;;"}
`;
diff --git a/test/templating/test.js b/test/templating/test.js
index d34d429..16e3fef 100644
--- a/test/templating/test.js
+++ b/test/templating/test.js
@@ -3,7 +3,7 @@ import {test, expect} from "@jest/globals";
import { rollup } from "rollup";
-import {debugPrintOutput, getCode} from "../util/index.ts";
+import {debugPrintOutput, getCode, serializer} from "../util/index.ts";
import html from "../../src/index.ts";
import handlebars from "handlebars";
@@ -13,10 +13,14 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
process.chdir(join(__dirname, 'fixtures'));
test('handlebars', async () => {
+ expect.addSnapshotSerializer(serializer);
const bundle = await rollup({
input: 'index.hbs',
plugins: [
html({
+ include: [
+ '**/*.(html|hbs)',// html or handlebars
+ ],
transform(src){
return handlebars.compile(src)({a:'a'})
}
@@ -25,7 +29,7 @@ test('handlebars', async () => {
});
const code = await getCode(bundle);
debugPrintOutput('handlebars',code);
- expect(code).toMatchSnapshot();
+ expect({code}).toMatchSnapshot();
});
diff --git a/test/url-plugin/__snapshots__/test.js.snap b/test/url-plugin/__snapshots__/test.js.snap
index 699c3c8..8b504a6 100644
--- a/test/url-plugin/__snapshots__/test.js.snap
+++ b/test/url-plugin/__snapshots__/test.js.snap
@@ -1,97 +1,55 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`url-plugin copied-assets 1`] = `
-[
- {
- "code": "const b = ()=>'batman';
-console.log(b());
-
-export { b };
-//# sourceMappingURL=batman.js.map
-",
- "fileName": "batman.js",
- "map": SourceMap {
- "file": "batman.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.js.map",
- "map": undefined,
- "source": "{"version":3,"file":"batman.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": "
-
-
-
-
-
-
-",
- },
-]
+ ##############
+ # index.html #
+ ##############
+
+
+
+
+
+
+
+
+ #############
+ # batman.js #
+ #############
+ const b = ()=>'batman';
+ console.log(b());
+
+ export { b };
+ //# sourceMappingURL=batman.js.map
+
+ #################
+ # batman.js.map #
+ #################
+ {"version":3,"file":"batman.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;;;;"}
`;
exports[`url-plugin inlined-assets 1`] = `
-[
- {
- "code": "const b = ()=>'batman';
-console.log(b());
-
-export { b };
-//# sourceMappingURL=batman.js.map
-",
- "fileName": "batman.js",
- "map": SourceMap {
- "file": "batman.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.js.map",
- "map": undefined,
- "source": "{"version":3,"file":"batman.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": "
-
-
-
-
-
-
-",
- },
-]
+ ##############
+ # index.html #
+ ##############
+
+
+
+
+
+
+
+
+ #############
+ # batman.js #
+ #############
+ const b = ()=>'batman';
+ console.log(b());
+
+ export { b };
+ //# sourceMappingURL=batman.js.map
+
+ #################
+ # batman.js.map #
+ #################
+ {"version":3,"file":"batman.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;;;;"}
`;
diff --git a/test/url-plugin/test.js b/test/url-plugin/test.js
index 250d5fb..dbdc058 100644
--- a/test/url-plugin/test.js
+++ b/test/url-plugin/test.js
@@ -4,7 +4,7 @@ import {test, expect} from "@jest/globals";
import { rollup } from "rollup";
import urlPlugin from "@rollup/plugin-url";
-import {debugPrintOutput, getCode} from "../util/index.ts";
+import {debugPrintOutput, getCode, serializer} from "../util/index.ts";
import html from "../../src/index.ts";
@@ -21,6 +21,7 @@ const defaultAssetInclude = [
];
describe("url-plugin", ()=>{
+ expect.addSnapshotSerializer(serializer);
test('copied-assets', async () => {
const bundle = await rollup({
input: 'index.html',
@@ -35,7 +36,7 @@ describe("url-plugin", ()=>{
});
const code = await getCode(bundle);
debugPrintOutput('copied-assets',code);
- expect(code).toMatchSnapshot();
+ expect({code}).toMatchSnapshot();
});
@@ -53,7 +54,7 @@ describe("url-plugin", ()=>{
});
const code = await getCode(bundle);
debugPrintOutput('inlined-assets',code);
- expect(code).toMatchSnapshot();
+ expect({code}).toMatchSnapshot();
});
})
diff --git a/test/util/browser-test.ts b/test/util/browser-test.ts
index 6b3755d..b3ec4e6 100644
--- a/test/util/browser-test.ts
+++ b/test/util/browser-test.ts
@@ -49,7 +49,7 @@ export async function runBrowserTest(
...test,
log: test.log ?? console.log,
onResult: (output)=>{
- testOutput = {...testOutput, ...output};
+ Object.assign(testOutput, output);
}
})]: [])
]
diff --git a/test/util/index.ts b/test/util/index.ts
index ce9b7f2..f294e5b 100644
--- a/test/util/index.ts
+++ b/test/util/index.ts
@@ -1,5 +1,7 @@
// TODO: this should be the main module used, other should be imported manually if exceptions are needed?
export * from "./browser-test.ts";
+export {defaultOutput} from "./default-output.ts";
+export {serializer} from "./test-serializer.ts";
export * from "./code-output.ts";
export * from "./print-code-output.ts";
diff --git a/test/util/serve-test.ts b/test/util/serve-test.ts
index e80eb15..36b9c30 100644
--- a/test/util/serve-test.ts
+++ b/test/util/serve-test.ts
@@ -133,6 +133,10 @@ export default function serveTest (options: RollupServeTestOptions ): Plugin {
let server : Server;
let bundle : OutputBundle = {};
+ const closeServer = async ()=>new Promise((resolve, reject)=>{
+ server.close((err)=>err?reject(err):resolve(undefined));
+ server = null as unknown as Server; // unset
+ });
const logTest = (msg: string, mode: 'info'|'warn' = 'info')=>{
if(isInDebugMode()){
@@ -217,9 +221,9 @@ export default function serveTest (options: RollupServeTestOptions ): Plugin {
function closeServerOnTermination () {
const terminationSignals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP']
terminationSignals.forEach(signal => {
- process.on(signal, () => {
+ process.on(signal, async () => {
if (server) {
- server.close()
+ await closeServer();
process.exit()
}
})
@@ -229,7 +233,7 @@ export default function serveTest (options: RollupServeTestOptions ): Plugin {
// release previous server instance if rollup is reloading configuration in watch mode
// @ts-ignore
if (server) {
- server.close()
+ closeServer()
} else {
closeServerOnTermination()
}
@@ -279,8 +283,9 @@ export default function serveTest (options: RollupServeTestOptions ): Plugin {
}
}
},
- closeBundle (){
+ async closeBundle(){
// Done with the bundle
+ await closeServer();
}
}
}
diff --git a/test/util/test-serializer.ts b/test/util/test-serializer.ts
new file mode 100644
index 0000000..b3f668f
--- /dev/null
+++ b/test/util/test-serializer.ts
@@ -0,0 +1,79 @@
+import type {runBrowserTest} from "./browser-test.ts";
+import type {expect} from "@jest/globals";
+import chalk from "chalk";
+
+type TestOutput = Awaited>;
+type Serializer = Parameters[0];
+
+function headerFor(name: string): string[]{
+ const hr = name.split('').map(()=>`#`).join('')
+ return [
+ `##${hr}##`,
+ `# ${name} #`,
+ `##${hr}##`,
+ ];
+}
+
+export const serializer: Serializer = {
+ test: (val: TestOutput)=> !!(
+ (val?.code && Array.isArray(val?.code))
+ || (val?.html && typeof(val?.html)==='string')
+ ),
+ serialize(val: TestOutput,
+ config,
+ indentation,
+ depth,
+ refs,
+ printer): string{
+ const indent = (config.indent||'')+(indentation+'');
+ let linesOut: string[] = [];
+
+ if(val.code){
+ const fileLines: string[][] = val.code.slice().sort(((a,b)=>{
+ const sortPropsA = [!a.fileName.endsWith('html'), a.fileName];
+ const sortPropsB = [!b.fileName.endsWith('html'), b.fileName];
+ for(let i = 0; i< 2;++i){
+ if(sortPropsA[i]sortPropsB[i]) return 1;
+ }
+ return 0;
+ })).map(({fileName, code, source})=>{
+ return [
+ ...headerFor(fileName),
+ ...((code||source).split('\n'))
+ ]
+ });
+
+ linesOut = linesOut.concat(...fileLines);
+ }
+
+ if(val.html){
+ linesOut = linesOut.concat([
+ ...headerFor("RENDERED HTML"),
+ ...(val.html.split('\n')),
+ ]);
+ }
+ if(val.errors?.length){
+ linesOut = linesOut.concat([
+ ...headerFor("ERRORS"),
+ ], ...val.errors.map(x=>x.split("\n")));
+ }
+ if(val.console?.length){
+ linesOut = linesOut.concat([
+ ...headerFor("CONSOLE"),
+ ], ...val.console.map(x=>x.split("\n")));
+ }
+ if(val.requestsFailed?.length){
+ linesOut = linesOut.concat([
+ ...headerFor("FAILED REQUESTS"),
+ ], ...val.requestsFailed.map(x=>x.split("\n")));
+ }
+ if(val.responses?.length){
+ linesOut = linesOut.concat([
+ ...headerFor("RESPONSES"),
+ ], ...val.responses.map(x=>x.split("\n")));
+ }
+
+ return linesOut.map(x=>`${indent}${x}`).join('\n');
+ },
+}
diff --git a/tsconfig.json b/tsconfig.json
index 8af2d8b..352232d 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -11,12 +11,12 @@
"sourceMap": true,
"strict": true,
"target": "ESNext",
- "module": "ESNext",
+ "module": "NodeNext",
"moduleResolution": "NodeNext",
"allowJs": true,
"allowImportingTsExtensions": true
},
- "exclude": ["dist", "node_modules", "test/types"],
+ "exclude": ["dist", "node_modules", "test/types","test/**/fixtures/*"],
"include": ["src/**/*", "types/**/*"],
"ts-node": {
"esm": true // from the top of https://typestrong.org/ts-node/docs/imports/
diff --git a/types/index.d.ts b/types/index.d.ts
deleted file mode 100644
index 0813177..0000000
--- a/types/index.d.ts
+++ /dev/null
@@ -1,86 +0,0 @@
-import type {Plugin, OutputChunk, OutputAsset, OutputBundle, TransformModuleJSON, } from 'rollup';
-import {FilterPattern} from "@rollup/pluginutils";
-import type {DefaultTreeAdapterMap} from "parse5";
-import {PreRenderedChunk} from "rollup";
-
-import type {LoadNodeCallback} from "./load.d.ts";
-export type * from "./load.d.ts"
-
-import type {ResolveCallback} from "./resolve.d.ts";
-export type * from "./resolve.d.ts"
-
-export interface RollupHtmlTransformContext {
- id?: string;
- // bundle: OutputBundle;
- // files: Record;
-}
-
-export interface RewriteUrlCallbackContext {
- from: string;
- rootPath: string;
-}
-export type RewriteUrlCallback = (relative: string, context: RewriteUrlCallbackContext) => string|Promise;
-export type TransformCallback = (source: string, transformContext: RollupHtmlTransformContext) => string|Promise;
-
-export interface RollupHtmlOptions {
- publicPath?: string;
- /**
- * Follows the same logic as rollup's [entryFileNames](https://rollupjs.org/configuration-options/#output-entryfilenames).
- */
- htmlFileNames?: string|((chunkInfo: PreRenderedChunk) => string);
-
- /**
- * Transform a source file passed into this plugin to HTML. For example: a handlebars transform
- * ```
- * transform(source){
- * return handlebars.compile(source)({myVar:'example'})
- * }
- * ```
- */
- transform?: TransformCallback;
-
- /**
- * Optional callback to rewrite how resources are referenced in the output HTML.
- * For example to rewrite urls to as paths from the root of your website:
- * ```
- * rewriteUrl(relative, {rootPath, from}){
- * return `/${rootPath}`;
- * }
- * ```
- */
- rewriteUrl?: RewriteUrlCallback;
-
- /**
- * Detect which references (,
) to resolve from a HTML node.
- * This rarely needs to be overloaded, but can be used to support non-native attributes used by custom-elements.
- *
- * Return false to skip any further processing on this node. Use the load function to add any resources from this node, and replace the import with a placeholder so the plugin knows where to inject the end result
- */
- load?: LoadNodeCallback;
- /**
- * Callback to filter which references actually need to be resolved. Here you can filter out:
- * - Links to extensions that don't need to be handled through rollup
- * - Resources that are external to the app (for example non-relative paths)
- * - Page navigation within the app
- *
- * Return a falsey value to skip this reference. Return true to resolve as is. (or string to transform the id)
- */
- resolve?: ResolveCallback;
-
- /**
- * [Pattern](https://github.com/micromatch/picomatch#globbing-features) to include
- */
- include?: FilterPattern;
- /**
- * [Pattern](https://github.com/micromatch/picomatch#globbing-features) to exclude
- */
- exclude?: FilterPattern
-}
-
-
-/**
- * A Rollup plugin which creates HTML files to serve Rollup bundles.
- * @param options - Plugin options.
- * @returns Plugin instance.
- */
-export default function html(options?: RollupHtmlOptions): Plugin;