Skip to content

Commit 8b48ab0

Browse files
Fix for running under deno (#4385)
1 parent e5e17d8 commit 8b48ab0

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/common/runtime/cmdline.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* eslint-disable no-console, n/no-restricted-import */
22

3-
import * as fs from 'fs';
4-
53
import { dataCache } from '../framework/data_cache.js';
64
import { getResourcePath, setBaseResourcePath } from '../framework/resources.js';
75
import { globalTestConfig } from '../framework/test_config.js';
@@ -152,13 +150,16 @@ Did you remember to build with code coverage instrumentation enabled?`
152150
dataCache.setStore({
153151
load: (path: string) => {
154152
return new Promise<Uint8Array>((resolve, reject) => {
155-
fs.readFile(getResourcePath(`cache/${path}`), (err, data) => {
156-
if (err !== null) {
157-
reject(err.message);
158-
} else {
159-
resolve(data);
153+
sys.readFile(
154+
getResourcePath(`cache/${path}`),
155+
(err: { message: string }, data: Uint8Array) => {
156+
if (err !== null) {
157+
reject(err.message);
158+
} else {
159+
resolve(data);
160+
}
160161
}
161-
});
162+
);
162163
});
163164
},
164165
});

src/common/runtime/helper/sys.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
function node() {
55
/* eslint-disable-next-line n/no-restricted-require */
6-
const { existsSync } = require('fs');
6+
const { readFile, existsSync } = require('fs');
77

88
return {
99
type: 'node',
10+
readFile,
1011
existsSync,
1112
args: process.argv.slice(2),
1213
cwd: () => process.cwd(),
@@ -16,6 +17,10 @@ function node() {
1617

1718
declare global {
1819
namespace Deno {
20+
function readFile(
21+
path: string,
22+
callback?: (error: unknown, data: string) => void
23+
): Promise<Uint8Array>;
1924
function readFileSync(path: string): Uint8Array;
2025
const args: string[];
2126
const cwd: () => string;
@@ -36,6 +41,7 @@ function deno() {
3641
return {
3742
type: 'deno',
3843
existsSync,
44+
readFile: Deno.readFile,
3945
args: Deno.args,
4046
cwd: Deno.cwd,
4147
exit: Deno.exit,

0 commit comments

Comments
 (0)