| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
import fs from 'node:fs'; |
| 3 |
import path from 'node:path'; |
| 4 |
import process from 'node:process'; |
| 5 |
|
| 6 |
const srcdir = process.env.SRCDIR || '.'; |
| 7 |
const libdir = path.resolve(srcdir, "pkg", "lib"); |
| 8 |
|
| 9 |
export const cockpitTestHtmlPlugin = ({ testFiles }) => ({ |
| 10 |
name: 'CockpitTestHtmlPlugin', |
| 11 |
setup(build) { |
| 12 |
build.onEnd(async () => { |
| 13 |
const data = fs.readFileSync(path.resolve(libdir, "qunit-template.html.in"), "utf8"); |
| 14 |
testFiles.forEach(file => { |
| 15 |
const test = path.parse(file).name; |
| 16 |
const builddir = file.split("/").map(() => "../").join(""); |
| 17 |
const output = data.toString() |
| 18 |
.replaceAll("%title%", test) |
| 19 |
.replaceAll("%builddir%", builddir) |
| 20 |
.replaceAll("%script%", test + '.js'); |
| 21 |
const outdir = './qunit/' + path.dirname(file); |
| 22 |
const outfile = test + ".html"; |
| 23 |
|
| 24 |
fs.mkdirSync(outdir, { recursive: true }); |
| 25 |
fs.writeFileSync(path.resolve(outdir, outfile), output); |
| 26 |
}); |
| 27 |
}); |
| 28 |
} |
| 29 |
}); |