Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ describe("counterfact", () => {

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

const createSpy = jest.spyOn(ApiRunner, "create");
createSpy.mockImplementation(async (...args) => {
const runner = await realCreate.apply(ApiRunner, args);
capturedRunners.push(runner);
const group = args[1];
if (group) {
capturedRunnersByGroup.set(group, runner);
}
return runner;
});

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

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

expect(capturedRunners).toHaveLength(2);
expect(result.contextRegistry).toBe(capturedRunners[0]!.contextRegistry);
expect(result.registry).toBe(capturedRunners[0]!.registry);
expect(capturedRunnersByGroup.size).toBe(2);
expect(firstRunner).toBeDefined();
expect(result.contextRegistry).toBe(firstRunner!.contextRegistry);
expect(result.registry).toBe(firstRunner!.registry);

createSpy.mockRestore();
});
Expand Down
9 changes: 6 additions & 3 deletions test/repl/raw-http-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ describe("RawHttpClient", () => {

client.get("/pets");

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

client.get("/pets");

await capture;
const raw = await capture;
expect(raw).toMatch(/^GET \/pets HTTP\/1\.1/);
await new Promise((resolve) => setTimeout(resolve, 20));
});

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

client.get("/status");

await capture;
const raw = await capture;
expect(raw).toMatch(/^GET \/status HTTP\/1\.1/);
await new Promise((resolve) => setTimeout(resolve, 20));
});
});
Loading