Hi! I was wondering if someone has created some tests using the Node SDK + Jest.
In Jenkins, where I have a Groovy library with utilities to install/use tools in a pipeline, I have tried many times to create a good solution to run integration tests over some of those functions. At the end, this is not possible/real/worth the effort as Jenkins does run Groovy in a serialized way + Jenkins plugins are not available locally.
One of the things that I was hopping to do with Dagger was to be able to finally create this integrations tests, but jest is not playing well with dagger. I am not very familiar with the node ecosystem, so this may be because I'm doing some weird stuff because of my lack of knowledge.
This is the test I have created:
import { describe, expect, test } from "@jest/globals"
import { connect, Client } from "@dagger.io/dagger"
import { withSdkman } from "./install.mjs"
describe("test sdk installation", () => {
test("sdk directory exists after installation", async () => {
connect(async (client: Client) => {
let container = client.container().from("ubuntu:20.04")
container = (await withSdkman(client, container)).withExec(
"ls /root/.sdkman/sdkman".split(" "),
)
await container.stdout()
expect(0).toBe(0)
})
})
})
this is the function I am trying to test:
export async function withSdkman(
client: Client,
container: Container,
with_cache: Boolean = false,
): Promise<Container> {
if (with_cache) {
const sdkman_cache = client.cacheVolume(SDKMAN_CACHE)
container.withMountedCache(SDKMAN_PATH, sdkman_cache)
}
container = container
.withExec("apt-get update".split(" "))
.withExec("apt-get install -y zip unzip wget curl".split(" "))
.withEnvVariable("SDKMAN_DIR", `${SDKMAN_PATH}/sdkman`)
.withExec(["bash", "-c", "curl -s https://get.sdkman.io | bash"])
return container
}