Skip to content

Fix tests #533

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

Merged
merged 8 commits into from
May 5, 2025
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
181 changes: 21 additions & 160 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/restate-sdk-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
},
"devDependencies": {
"tsx": "^4.15.7",
"@restatedev/restate-sdk-testcontainers": "^1.5.4",
"testcontainers": "^10.24.1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When ⁠GenericContainer was imported from two separate modules (⁠restate-sdk-examples and ⁠restate-sdk-testcontainers), it created two distinct versions of the class—causing issues with testcontainers. To resolve this, I introduced ⁠RestateGenericContainer as a single, unified reference.

"@restatedev/restate-sdk-testcontainers": "^1.5.4"
},
"engines": {
"node": ">= 18.13"
Expand Down
8 changes: 5 additions & 3 deletions packages/restate-sdk-examples/test/testcontainers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
*/

import { RestateTestEnvironment } from "@restatedev/restate-sdk-testcontainers";
import {
RestateContainer,
RestateTestEnvironment,
} from "@restatedev/restate-sdk-testcontainers";
import { counter } from "../src/object.js";
import * as clients from "@restatedev/restate-sdk-clients";
import * as core from "@restatedev/restate-sdk-core";
import { describe, it, beforeAll, afterAll, expect } from "vitest";
import { GenericContainer } from "testcontainers";

describe("ExampleObject", () => {
let restateTestEnvironment: RestateTestEnvironment;
Expand Down Expand Up @@ -127,7 +129,7 @@ describe("Custom testcontainer config", () => {
restateTestEnvironment = await RestateTestEnvironment.start(
(restateServer) => restateServer.bind(counter),
() =>
new GenericContainer("restatedev/restate:1.1")
new RestateContainer()
.withEnvironment({ RESTATE_LOG_FORMAT: "json" })
.withLogConsumer((stream) => {
// eslint-disable-next-line no-console
Expand Down
5 changes: 4 additions & 1 deletion packages/restate-sdk-testcontainers/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
*/

export { RestateTestEnvironment } from "./restate_test_environment.js";
export {
RestateTestEnvironment,
RestateContainer,
} from "./restate_test_environment.js";
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class RestateTestEnvironment {
public static async start(
mountServicesFn: (server: restate.RestateEndpoint) => void,
restateContainerFactory: () => GenericContainer = () =>
new GenericContainer("docker.io/restatedev/restate:latest")
new RestateContainer()
): Promise<RestateTestEnvironment> {
const startedRestateHttpServer = await prepareRestateEndpoint(
mountServicesFn
Expand All @@ -167,6 +167,11 @@ export class RestateTestEnvironment {
export type TypedState = Record<string, any>;
export type UntypedState = { _: never };

export class RestateContainer extends GenericContainer {
constructor(version = "latest") {
super(`docker.io/restatedev/restate:${version}`);
}
}
export class StateProxy<TState extends TypedState> {
constructor(
private adminAPIBaseUrl: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ const greeterFoo = restate.service({

describe("BindService", () => {
it("should preserve `this`", async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-assignment
const handler = greeterFoo["service"]["greet"];
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
expect(await handler({}, "abc")).toEqual("abc");
// @ts-expect-error service does not exist in the returned type
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
expect(await greeterFoo.service?.greet({}, "abc")).toEqual("abc");
});
});

Expand Down