mirror-cockpit-project-cockpit/pkg/lib/esbuild-test-html-plugin.js
Allison Karlitskaya 78d5d35b38
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Differential ShellCheck / shellcheck (push) Waiting to run
Cockpit manifests / validate-manifests (push) Waiting to run
Cockpit manifests / validate-schemas (push) Waiting to run
esbuild-test-html-plugin: drop %builddir% expand
This got removed from the template with e51cf81cd2 ("unit tests: Don't
load cockpit.js in the qunit HTML template") but we've been deadcode
expanding it ever since.  Drop it.
2026-11-03 10:46:22 +01:00

22 lines
925 B
JavaScript

// SPDX-License-Identifier: LGPL-2.1-or-later
import fs from 'node:fs';
import path from 'node:path';
export const cockpitTestHtmlPlugin = ({ testFiles }) => ({
name: 'CockpitTestHtmlPlugin',
setup(build) {
build.onEnd(async () => {
const data = fs.readFileSync(path.resolve(import.meta.dirname, "qunit-template.html.in"), "utf8");
testFiles.forEach(file => {
const test = path.parse(file).name;
const output = data.toString()
.replaceAll("%title%", test)
.replaceAll("%script%", test + '.js');
const outdir = path.join(build.initialOptions.outdir, path.dirname(file));
const outfile = test + ".html";
fs.mkdirSync(outdir, { recursive: true });
fs.writeFileSync(path.resolve(outdir, outfile), output);
});
});
}
});