Skip to content

Commit c2ad22c

Browse files
authored
test: switch to prool (latticexyz#3550)
1 parent 90aac1d commit c2ad22c

File tree

5 files changed

+128
-12
lines changed

5 files changed

+128
-12
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"@types/node": "^20",
4444
"@typescript-eslint/eslint-plugin": "7.1.1",
4545
"@typescript-eslint/parser": "7.1.1",
46-
"@viem/anvil": "^0.0.7",
4746
"chalk": "^5.2.0",
4847
"eslint": "8.57.0",
4948
"execa": "^9.5.2",
@@ -52,6 +51,7 @@
5251
"lint-staged": "^15.2.10",
5352
"prettier": "3.2.5",
5453
"prettier-plugin-solidity": "1.3.1",
54+
"prool": "^0.0.16",
5555
"shx": "^0.3.4",
5656
"sort-package-json": "^2.10.1",
5757
"tsup": "8.3.0",

pnpm-lock.yaml

+92-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-setup/global/anvil.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import { startProxy as startAnvilProxy } from "@viem/anvil";
1+
import { createServer } from "prool";
2+
import { anvil } from "prool/instances";
23
import { anvilHost, anvilPort } from "../common";
34
import { execa } from "execa";
45

5-
// ensure anvil dies
6-
// TODO: maybe don't need this once we move to prool
7-
process.on("SIGINT", () => process.exit());
8-
process.on("SIGTERM", () => process.exit());
9-
process.on("SIGQUIT", () => process.exit());
6+
// The nightly warning from Foundry causes anvil to not start up properly.
7+
// https://github.com/wevm/prool/issues/35
8+
process.env.FOUNDRY_DISABLE_NIGHTLY_WARNING ??= "1";
9+
10+
const server = createServer({
11+
instance: anvil(),
12+
host: anvilHost,
13+
port: anvilPort,
14+
});
1015

1116
export default async () => {
1217
console.log("building mock game contracts");
@@ -17,5 +22,9 @@ export default async () => {
1722
});
1823

1924
console.log("starting anvil proxy");
20-
return startAnvilProxy({ host: anvilHost, port: anvilPort });
25+
const stopServer = await server.start();
26+
27+
return async () => {
28+
await stopServer();
29+
};
2130
};

test-setup/global/polyfill.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// TODO: remove once we upgrade to
2+
if (typeof Promise.withResolvers === "undefined") {
3+
Promise.withResolvers = <T>() => {
4+
let resolve: (value: T | PromiseLike<T>) => void;
5+
let reject: (reason?: unknown) => void;
6+
const promise = new Promise<T>((res, rej) => {
7+
resolve = res;
8+
reject = rej;
9+
});
10+
return { promise, resolve: resolve!, reject: reject! };
11+
};
12+
}
13+
14+
export default () => {};

vitest.config.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { defineConfig } from "vitest/config";
22

33
export default defineConfig({
44
test: {
5-
globalSetup: [`${__dirname}/test-setup/global/arktype.ts`, `${__dirname}/test-setup/global/anvil.ts`],
5+
globalSetup: [
6+
`${__dirname}/test-setup/global/polyfill.ts`,
7+
`${__dirname}/test-setup/global/arktype.ts`,
8+
`${__dirname}/test-setup/global/anvil.ts`,
9+
],
610
setupFiles: [],
711
passWithNoTests: true,
812
// Temporarily set a low teardown timeout because anvil hangs otherwise

0 commit comments

Comments
 (0)