Skip to content

Commit

Permalink
build: fix test rerun on file change (#2965)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyubisation authored Jul 25, 2024
1 parent a880be6 commit 2f948a5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tools/web-test-runner/vite-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { existsSync } from 'node:fs';

import type { TestRunnerPlugin } from '@web/test-runner';
import { createServer, type ViteDevServer } from 'vite';

Expand All @@ -8,7 +10,7 @@ export function vitePlugin(): TestRunnerPlugin {
return {
name: 'vite-plugin',

async serverStart({ app }) {
async serverStart({ app, fileWatcher }) {
const externals = [
// @web/test-runner-commands needs to establish a web-socket
// connection. It expects a file to be served from the
Expand All @@ -22,6 +24,15 @@ export function vitePlugin(): TestRunnerPlugin {
server: { middlewareMode: true, hmr: false },
appType: 'custom',
plugins: [
{
name: 'file-name',
transform(_src, id) {
const file = id.split('?')[0];
if (!file.startsWith('\0') && existsSync(file)) {
fileWatcher.add(file);
}
},
},
{
name: 'mark-external',
resolveId: (id) => (externals.includes(id) ? { id, external: true } : undefined),
Expand Down

0 comments on commit 2f948a5

Please sign in to comment.