forked from ProjectEvergreen/www.greenwoodjs.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web-test-runner.config.js
67 lines (60 loc) · 1.74 KB
/
web-test-runner.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { defaultReporter } from "@web/test-runner";
import fs from "fs";
import { greenwoodPluginImportRaw } from "@greenwood/plugin-import-raw";
import { junitReporter } from "@web/test-runner-junit-reporter";
import path from "path";
const rawResource = greenwoodPluginImportRaw()[0].provider({});
export default {
files: "./src/**/*.spec.js",
nodeResolve: true,
reporters: [
defaultReporter({ reportTestResults: true, reportTestProgress: true }),
junitReporter({
outputPath: "./reports/test-results.xml",
}),
],
coverage: true,
coverageConfig: {
reportDir: "./reports",
},
plugins: [
{
name: "import-raw",
async transform(context) {
const { url } = context.request;
if (url.endsWith("?type=raw")) {
const contents = fs.readFileSync(new URL(`.${url}`, import.meta.url), "utf-8");
const response = await rawResource.intercept(null, null, new Response(contents));
const body = await response.text();
return {
body,
headers: { "Content-Type": "application/javascript" },
};
}
},
},
{
name: "css-modules",
async transform(context) {
const url = new URL(`.${context.request.url}`, import.meta.url);
if (url.href.endsWith("module.css")) {
return {
body: "export default {};",
headers: {
"Content-Type": "text/javascript",
},
};
}
},
},
],
middleware: [
function rewriteIndex(context, next) {
const { url } = context.request;
if (url.indexOf("/assets") === 0) {
context.request.url = path.join(process.cwd(), "src", url);
}
return next();
},
],
};