From 5d34ed24654246f3973c84d515c718fa2de0f20c Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 1 Sep 2023 11:57:55 +0200 Subject: [PATCH] fix: webFS#fileExists needs to await file check --- packages/build-info/src/browser/file-system.ts | 4 ++-- packages/build-info/tests/helpers.ts | 17 ++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/packages/build-info/src/browser/file-system.ts b/packages/build-info/src/browser/file-system.ts index dbb45e693c..7fc854fdbe 100644 --- a/packages/build-info/src/browser/file-system.ts +++ b/packages/build-info/src/browser/file-system.ts @@ -26,7 +26,7 @@ export class GithubProvider { if (response.headers?.get('Content-Type')?.match(/json/)) { const json = await response.json() if (!response.ok) { - Promise.reject(json) + throw new Error(JSON.stringify(json)) } return json } @@ -55,7 +55,7 @@ export class WebFS extends FileSystem { async fileExists(path: string): Promise { try { - this.readFile(path) + await this.readFile(path) return true } catch { return false diff --git a/packages/build-info/tests/helpers.ts b/packages/build-info/tests/helpers.ts index 737c3a3e78..fe903b73eb 100644 --- a/packages/build-info/tests/helpers.ts +++ b/packages/build-info/tests/helpers.ts @@ -68,16 +68,11 @@ export const createWebFixture = async (fixture: string) => { const info = await stat(src) if (info.isDirectory()) { const entries = await readdir(src, { withFileTypes: true }) - return new Response( - JSON.stringify( - entries.map((entry) => ({ - path: entry.name, - type: entry.isDirectory() ? 'dir' : 'file', - })), - ), - { - headers: { 'Content-Type': 'application/json' }, - }, + return Response.json( + entries.map((entry) => ({ + path: entry.name, + type: entry.isDirectory() ? 'dir' : 'file', + })), ) } else { const file = await readFile(src, 'utf-8') @@ -87,7 +82,7 @@ export const createWebFixture = async (fixture: string) => { // noop } - throw new Error(`404 ${url} not found!`) + return Response.json({ error: 'not found' }, { status: 404 }) }) return { cwd: '/' }