-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathweb-test-runner.config.js
73 lines (66 loc) · 2.08 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
68
69
70
71
72
73
import { defaultReporter } from "@web/test-runner";
import fs from "fs/promises";
import { greenwoodPluginImportRaw } from "@greenwood/plugin-import-raw";
import { readAndMergeConfig } from "@greenwood/cli/src/lifecycles/config.js";
import { initContext } from "@greenwood/cli/src/lifecycles/context.js";
import { junitReporter } from "@web/test-runner-junit-reporter";
import path from "path";
// bootstrap custom plugin transforms from Greenwood
const config = await readAndMergeConfig();
const context = await initContext({ config });
const compilation = { context, config };
const rawResource = greenwoodPluginImportRaw()[0].provider(compilation);
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 = await fs.readFile(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 resolveAssets(context, next) {
const { url } = context.request;
if (url.startsWith("/assets")) {
context.request.url = path.join(process.cwd(), "src", url);
}
return next();
},
],
};