Skip to content

Commit b732a8f

Browse files
authored
Merge pull request #1917 from counterfact/copilot/resolve-jest-expect-expect-warnings
Resolve `jest/expect-expect` warnings and stabilize flaky app runner test
2 parents c62f89e + 2e2b256 commit b732a8f

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

test/app.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,15 @@ describe("counterfact", () => {
8181

8282
it("uses the first spec's runner as primary (contextRegistry, registry) when specs are provided", async () => {
8383
const realCreate = ApiRunner.create;
84-
const capturedRunners: ApiRunner[] = [];
84+
const capturedRunnersByGroup = new Map<string, ApiRunner>();
8585

8686
const createSpy = jest.spyOn(ApiRunner, "create");
8787
createSpy.mockImplementation(async (...args) => {
8888
const runner = await realCreate.apply(ApiRunner, args);
89-
capturedRunners.push(runner);
89+
const group = args[1];
90+
if (group) {
91+
capturedRunnersByGroup.set(group, runner);
92+
}
9093
return runner;
9194
});
9295

@@ -96,10 +99,12 @@ describe("counterfact", () => {
9699
];
97100

98101
const result = await (app as any).counterfact(mockConfig, specs);
102+
const firstRunner = capturedRunnersByGroup.get("v1");
99103

100-
expect(capturedRunners).toHaveLength(2);
101-
expect(result.contextRegistry).toBe(capturedRunners[0]!.contextRegistry);
102-
expect(result.registry).toBe(capturedRunners[0]!.registry);
104+
expect(capturedRunnersByGroup.size).toBe(2);
105+
expect(firstRunner).toBeDefined();
106+
expect(result.contextRegistry).toBe(firstRunner!.contextRegistry);
107+
expect(result.registry).toBe(firstRunner!.registry);
103108

104109
createSpy.mockRestore();
105110
});

test/repl/raw-http-client.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ describe("RawHttpClient", () => {
212212

213213
client.get("/pets");
214214

215-
await capture;
215+
const raw = await capture;
216+
expect(raw).toMatch(/^GET \/pets HTTP\/1\.1/);
216217
// Allow the event loop to flush the client's "data"/"end" socket events so
217218
// that #printResponse (including highlightJson with boolean/null values) runs.
218219
await new Promise((resolve) => setTimeout(resolve, 20));
@@ -227,7 +228,8 @@ describe("RawHttpClient", () => {
227228

228229
client.get("/pets");
229230

230-
await capture;
231+
const raw = await capture;
232+
expect(raw).toMatch(/^GET \/pets HTTP\/1\.1/);
231233
await new Promise((resolve) => setTimeout(resolve, 20));
232234
});
233235

@@ -240,7 +242,8 @@ describe("RawHttpClient", () => {
240242

241243
client.get("/status");
242244

243-
await capture;
245+
const raw = await capture;
246+
expect(raw).toMatch(/^GET \/status HTTP\/1\.1/);
244247
await new Promise((resolve) => setTimeout(resolve, 20));
245248
});
246249
});

0 commit comments

Comments
 (0)