@samitouri / QOS-React-1 / commits / 43e3cd61f8

[snap] Use sync fs apis to stop crashes

--- Not sure why, but snap kept silently crashing when I used fs/promises to write to many file handles. I tried a `.catch(...)`, but couldn't figure it out. This diff changes snap to use sync fs apis to avoid crashes, but I'd love to get feedback if someone knows how to debug this.

Mofei Zhang committed Aug 16, 2023 at 15:32 UTC 43e3cd61f844b32804c3e2822a1645450baaa02a
1 file changed +13 -5
compiler/forget/packages/snap/src/runner.ts
+13 -5
@@ -7,8 +7,16 @@
7
8 import watcher from "@parcel/watcher";
9 import chalk from "chalk";
10 -import { COMPILER_PATH, LOGGER_PATH, FIXTURES_PATH, FILTER_FILENAME, FILTER_PATH, readTestFilter, TestFilter } from 'fixture-test-utils';
11 -import fs from "fs/promises";
10 +import {
11 + COMPILER_PATH,
12 + LOGGER_PATH,
13 + FIXTURES_PATH,
14 + FILTER_FILENAME,
15 + FILTER_PATH,
16 + readTestFilter,
17 + TestFilter,
18 +} from "fixture-test-utils";
19 +import fs from "fs";
20 import invariant from "invariant";
21 import { diff } from "jest-diff";
22 import { Worker } from "jest-worker";
@@ -20,7 +28,7 @@ import yargs from "yargs";
28 import { hideBin } from "yargs/helpers";
29 import { TestResult } from "./compiler-worker";
30 import * as compiler from "./compiler-worker";
23 -import {getFixtures} from 'fixture-test-utils';
31 +import { getFixtures } from "fixture-test-utils";
32
33 const WORKER_PATH = require.resolve("./compiler-worker.js");
34
@@ -216,7 +224,7 @@ async function update(results: Results): Promise<void> {
224 chalk.red.inverse.bold(" REMOVE ") + " " + chalk.dim(basename)
225 );
226 try {
219 - await fs.unlink(result.outputPath);
227 + fs.unlinkSync(result.outputPath);
228 console.log(" remove " + result.outputPath);
229 deleted++;
230 } catch (e) {
@@ -230,7 +238,7 @@ async function update(results: Results): Promise<void> {
238 console.log(
239 chalk.blue.inverse.bold(" UPDATE ") + " " + chalk.dim(basename)
240 );
233 - await fs.writeFile(result.outputPath, result.actual, "utf8");
241 + fs.writeFileSync(result.outputPath, result.actual, "utf8");
242 if (result.expected == null) {
243 created++;
244 } else {