Skip to content

Commit

Permalink
debug a flaky test on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed Sep 11, 2023
1 parent 6564031 commit ceb42ad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
key: ${{ runner.os }}-${{ steps.node-version.outputs.version }}-${{ hashFiles('**/yarn.lock') }}
- name: Install Packages
run: yarn install --frozen-lockfile --network-timeout 100000
- name: flaky test on Windows
env:
DEGUG: "counterfact:*"
run: yarn test transpiler
- name: ESlint
run: yarn eslint -f github-annotations .
- name: TypeScript
Expand Down
10 changes: 9 additions & 1 deletion src/server/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import fs from "node:fs/promises";
import nodePath from "node:path";

import { type FSWatcher, watch as chokidarWatch } from "chokidar";
import createDebug from "debug";
import ts from "typescript";

import { ensureDirectoryExists } from "../util/ensure-directory-exists.js";
import { CHOKIDAR_OPTIONS } from "./constants.js";

const debug = createDebug("counterfact:server:transpiler");
export class Transpiler extends EventTarget {
private readonly sourcePath: string;

Expand All @@ -24,6 +26,7 @@ export class Transpiler extends EventTarget {
}

public async watch(): Promise<void> {
debug("transpiler: watch");
this.watcher = chokidarWatch(`${this.sourcePath}/**/*.{ts,mts,js,mjs}`, {
...CHOKIDAR_OPTIONS,
ignored: `${this.sourcePath}/js`,
Expand All @@ -34,8 +37,9 @@ export class Transpiler extends EventTarget {
this.watcher.on(
"all",

// eslint-disable-next-line @typescript-eslint/no-misused-promises
// eslint-disable-next-line @typescript-eslint/no-misused-promises, max-statements
async (eventName: string, sourcePathOriginal: string) => {
debug("transpiler event: %s <%s>", eventName, sourcePathOriginal);
const sourcePath = sourcePathOriginal.replaceAll("\\", "/");

const destinationPath = sourcePath
Expand All @@ -55,6 +59,8 @@ export class Transpiler extends EventTarget {
} catch (error) {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
if ((error as { code: string }).code !== "ENOENT") {
debug("error removing %s: %o", destinationPath, error);
this.dispatchEvent(new Event("error"));
throw error;
}
}
Expand Down Expand Up @@ -100,6 +106,8 @@ export class Transpiler extends EventTarget {
// eslint-disable-next-line total-functions/no-unsafe-readonly-mutable-assignment
await fs.writeFile(fullDestination, result);
} catch {
debug("error transpiling %s", fullDestination);
this.dispatchEvent(new Event("error"));
throw new Error("could not transpile");
}

Expand Down
3 changes: 2 additions & 1 deletion test/server/transpiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ describe("a Transpiler", () => {
await transpiler.watch();

const write = once(transpiler, "write");
const error = once(transpiler, "error");

await add("src/added.ts", TYPESCRIPT_SOURCE);
await write;
await Promise.race([write, error]);

// eslint-disable-next-line promise/avoid-new
await new Promise((resolve) => {
Expand Down

0 comments on commit ceb42ad

Please sign in to comment.