Skip to content

Commit

Permalink
support WTR with import raw plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed May 6, 2024
1 parent 2f660fb commit 9f07baa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps=true
12 changes: 6 additions & 6 deletions web-test-runner.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defaultReporter } from '@web/test-runner';
import fs from 'fs/promises';
import { greenwoodPluginImportCss } from '@greenwood/plugin-import-css/src/index.js';
import { greenwoodPluginImportRaw } from '@greenwood/plugin-import-raw';
import { junitReporter } from '@web/test-runner-junit-reporter';

// create a direct instance of ImportCssResource
const importCssResource = greenwoodPluginImportCss()[0].provider({});
const importRawResource = greenwoodPluginImportRaw()[0].provider({});

export default {
files: './src/**/*.spec.js',
Expand All @@ -20,16 +20,16 @@ export default {
reportDir: './reports'
},
plugins: [{
name: 'import-css',
name: 'import-raw-css',
async transform(context) {
const url = new URL(`.${context.request.url}`, import.meta.url);
const request = new Request(url, { headers: new Headers(context.headers) });
const shouldIntercept = await importCssResource.shouldIntercept(url, request);
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 importCssResource.intercept(url, request, initResponse.clone());
const response = await importRawResource.intercept(url, request, initResponse.clone());

return {
body: await response.text(),
Expand Down

0 comments on commit 9f07baa

Please sign in to comment.