-
Notifications
You must be signed in to change notification settings - Fork 0
/
web-test-runner.config.js
54 lines (48 loc) · 1.64 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
import { defaultReporter } from '@web/test-runner';
import fs from 'fs/promises';
import { greenwoodPluginImportRaw } from '@greenwood/plugin-import-raw';
import { junitReporter } from '@web/test-runner-junit-reporter';
// create a direct instance of ImportCssResource
const importRawResource = 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-css',
async transform(context) {
const url = new URL(`.${context.request.url}`, import.meta.url);
const request = new Request(url, { headers: { 'Sec-Fetch-Dest': 'empty' } });
const shouldIntercept = await importRawResource.shouldIntercept(url, request);
if (shouldIntercept) {
const contents = await fs.readFile(url);
const initResponse = new Response(contents, { headers: new Headers(context.headers) });
const response = await importRawResource.intercept(url, request, initResponse.clone());
return {
body: await response.text(),
headers: {
'Content-Type': response.headers.get('Content-Type')
}
};
}
}
}],
middleware: [
function rewriteIndex(context, next) {
const { url } = context.request;
if (url.indexOf('/assets') === 0) {
context.request.url = new URL(`./src/${url}`, import.meta.url).pathname;
}
return next();
}
]
};