Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate integration tests to use history instead of timeline #413

Merged
merged 1 commit into from
Dec 4, 2023
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
16 changes: 9 additions & 7 deletions packages/inngest/src/test/functions/hello-world/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ describe("run", () => {
}, 60000);

test("returns 'Hello, Inngest!'", async () => {
await expect(
runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
output: JSON.stringify("Hello, Inngest!"),
})
).resolves.toBeDefined();
const item = await runHasTimeline(runId, {
type: "StepCompleted",
stepName: "step",
});

expect(item).toBeDefined();

const output = await item?.getOutput();
expect(output).toEqual("Hello, Inngest!");
}, 60000);
});
27 changes: 13 additions & 14 deletions packages/inngest/src/test/functions/parallel-reduce/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,24 @@ describe("run", () => {

["blue", "red", "green"].forEach((team) => {
test(`ran "Get ${team} team score" step`, async () => {
const step = await runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
name: `Get ${team} team score`,
const item = await runHasTimeline(runId, {
type: "StepCompleted",
stepName: `Get ${team} team score`,
});
expect(item).toBeDefined();

expect(step).toBeDefined();
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(step.output).toEqual(expect.any(String));
const output = await item?.getOutput();
expect(output).toEqual({ data: expect.any(Number) });
}, 60000);
});

test("Returned total score", async () => {
await expect(
runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
output: JSON.stringify("150"),
})
).resolves.toBeDefined();
const item = await runHasTimeline(runId, {
type: "FunctionCompleted",
});
expect(item).toBeDefined();

const output = await item?.getOutput();
expect(output).toEqual(150);
}, 60000);
});
51 changes: 25 additions & 26 deletions packages/inngest/src/test/functions/parallel-work/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,44 @@ describe("run", () => {
}, 60000);

["First", "Second", "Third"].forEach((scoreStep) => {
const name = `${scoreStep} score`;
const stepName = `${scoreStep} score`;

test(`ran "${name}" step`, async () => {
const step = await runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
name,
test(`ran "${stepName}" step`, async () => {
const item = await runHasTimeline(runId, {
type: "StepCompleted",
stepName,
});
expect(item).toBeDefined();

expect(step).toBeDefined();
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(step.output).toEqual(expect.any(String));
const output = await item?.getOutput();
expect(output).toEqual({ data: expect.any(Number) });
}, 60000);
});

const fruits = ["Apple", "Banana", "Orange"];

fruits.forEach((fruit) => {
const name = `Get ${fruit.toLowerCase()}`;
const stepName = `Get ${fruit.toLowerCase()}`;

test(`ran "${name}" step`, async () => {
await expect(
runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
name,
output: JSON.stringify({ data: fruit }),
})
).resolves.toBeDefined();
test(`ran "${stepName}" step`, async () => {
const item = await runHasTimeline(runId, {
type: "StepCompleted",
stepName,
});
expect(item).toBeDefined();

const output = await item?.getOutput();
expect(output).toEqual({ data: fruit });
}, 60000);
});

test("Returned correct data", async () => {
await expect(
runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
output: JSON.stringify([6, `${fruits.join(", ")}`]),
})
).resolves.toBeDefined();
const item = await runHasTimeline(runId, {
type: "FunctionCompleted",
});
expect(item).toBeDefined();

const output = await item?.getOutput();
expect(output).toEqual([6, `${fruits.join(", ")}`]);
}, 60000);
});
48 changes: 24 additions & 24 deletions packages/inngest/src/test/functions/promise-all/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,35 @@ describe("run", () => {
}, 60000);

test("ran Step 1", async () => {
await expect(
runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
name: "Step 1",
output: JSON.stringify({ data: 1 }),
})
).resolves.toBeDefined();
const item = await runHasTimeline(runId, {
type: "StepCompleted",
stepName: "Step 1",
});
expect(item).toBeDefined();

const output = await item?.getOutput();
expect(output).toEqual({ data: 1 });
}, 60000);

test("ran Step 2", async () => {
await expect(
runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
name: "Step 2",
output: JSON.stringify({ data: 2 }),
})
).resolves.toBeDefined();
const item = await runHasTimeline(runId, {
type: "StepCompleted",
stepName: "Step 2",
});
expect(item).toBeDefined();

const output = await item?.getOutput();
expect(output).toEqual({ data: 2 });
}, 60000);

test("ran Step 3", async () => {
await expect(
runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
name: "Step 3",
output: JSON.stringify({ data: 3 }),
})
).resolves.toBeDefined();
const item = await runHasTimeline(runId, {
type: "StepCompleted",
stepName: "Step 3",
});
expect(item).toBeDefined();

const output = await item?.getOutput();
expect(output).toEqual({ data: 3 });
}, 60000);
});
44 changes: 22 additions & 22 deletions packages/inngest/src/test/functions/promise-race/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,38 @@ describe("run", () => {
}, 60000);

test("ran Step A", async () => {
await expect(
runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
name: "Step A",
output: JSON.stringify({ data: "A" }),
})
).resolves.toBeDefined();
const item = await runHasTimeline(runId, {
type: "StepCompleted",
stepName: "Step A",
});
expect(item).toBeDefined();

const output = await item?.getOutput();
expect(output).toEqual({ data: "A" });
}, 60000);

test("ran Step B", async () => {
await expect(
runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
name: "Step B",
output: JSON.stringify({ data: "B" }),
})
).resolves.toBeDefined();
const item = await runHasTimeline(runId, {
type: "StepCompleted",
stepName: "Step B",
});
expect(item).toBeDefined();

const output = await item?.getOutput();
expect(output).toEqual({ data: "B" });
}, 60000);

let winner: "A" | "B" | undefined;

test("ran Step C", async () => {
const timelineItem = await runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
name: "Step C",
const item = await runHasTimeline(runId, {
type: "StepCompleted",
stepName: "Step C",
});

expect(timelineItem).toBeDefined();
const output = JSON.parse(timelineItem.output);
expect(item).toBeDefined();

const output = await item?.getOutput();
winner =
output.data === "A is the winner!"
? "A"
Expand Down
27 changes: 13 additions & 14 deletions packages/inngest/src/test/functions/sequential-reduce/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,24 @@ describe("run", () => {

["blue", "red", "green"].forEach((team) => {
test(`ran "Get ${team} team score" step`, async () => {
const step = await runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
name: `Get ${team} team score`,
const item = await runHasTimeline(runId, {
type: "StepCompleted",
stepName: `Get ${team} team score`,
});
expect(item).toBeDefined();

expect(step).toBeDefined();
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(step.output).toEqual(expect.any(String));
const output = await item?.getOutput();
expect(output).toEqual({ data: expect.any(Number) });
}, 60000);
});

test("Returned total score", async () => {
await expect(
runHasTimeline(runId, {
__typename: "StepEvent",
stepType: "COMPLETED",
output: JSON.stringify("150"),
})
).resolves.toBeDefined();
const item = await runHasTimeline(runId, {
type: "FunctionCompleted",
});
expect(item).toBeDefined();

const output = await item?.getOutput();
expect(output).toEqual(150);
}, 60000);
});
Loading
Loading