From f5e4ebf5b9fb61a05fa510a6d7168cb20789a413 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Tue, 23 Apr 2024 15:04:17 +0200 Subject: [PATCH] chore: keep code --- packages/vitest/src/node/pools/rpc.ts | 7 +++---- packages/web-worker/src/utils.ts | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/vitest/src/node/pools/rpc.ts b/packages/vitest/src/node/pools/rpc.ts index aa8535d1abad..538ab2b5a94b 100644 --- a/packages/vitest/src/node/pools/rpc.ts +++ b/packages/vitest/src/node/pools/rpc.ts @@ -27,12 +27,13 @@ export function createMethodsRPC(project: WorkspaceProject): RuntimeRPC { }, async fetch(id, transformMode) { const result = await project.vitenode.fetchResult(id, transformMode) + const code = result.code if (result.externalize) return result - if (!result.code && 'id' in result) + if ('id' in result) return { id: result.id as string } - if (!result.code) + if (!code) throw new Error(`Failed to fetch module ${id}`) const dir = join(project.tmpDir, transformMode) @@ -45,10 +46,8 @@ export function createMethodsRPC(project: WorkspaceProject): RuntimeRPC { await mkdir(dir, { recursive: true }) created.add(dir) } - const code = result.code promises.set(tmp, writeFile(tmp, code, 'utf-8').finally(() => promises.delete(tmp))) await promises.get(tmp) - result.code = undefined Object.assign(result, { id: tmp }) return { id: tmp } }, diff --git a/packages/web-worker/src/utils.ts b/packages/web-worker/src/utils.ts index 6cd01139f56b..a19f4b8c4069 100644 --- a/packages/web-worker/src/utils.ts +++ b/packages/web-worker/src/utils.ts @@ -1,4 +1,4 @@ -import { readFile } from 'node:fs/promises' +import { readFileSync } from 'node:fs' import type { WorkerGlobalState } from 'vitest' import ponyfillStructuredClone from '@ungap/structured-clone' import createDebug from 'debug' @@ -69,7 +69,7 @@ export function getRunnerOptions(): any { async fetchModule(id: string) { const result = await rpc.fetch(id, 'web') if (result.id && !result.externalize) { - const code = await readFile(result.id, 'utf-8') + const code = readFileSync(result.id, 'utf-8') return { code } } return result