-
Notifications
You must be signed in to change notification settings - Fork 1.6k
test: add local docker compose coverage #1846
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { readFile } from "node:fs/promises"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { parse } from "yaml"; | ||
|
|
||
| type ComposeService = { | ||
| container_name?: string; | ||
| image?: string; | ||
| build?: { | ||
| context?: string; | ||
| dockerfile?: string; | ||
| }; | ||
| ports?: Array<number | string>; | ||
| volumes?: string[]; | ||
| depends_on?: string[]; | ||
| environment?: Record<string, string | number>; | ||
| }; | ||
|
|
||
| type ComposeFile = { | ||
| name?: string; | ||
| services?: Record<string, ComposeService>; | ||
| volumes?: Record<string, unknown>; | ||
| }; | ||
|
|
||
| const composePath = fileURLToPath( | ||
| new URL("./docker-compose.yml", import.meta.url), | ||
| ); | ||
|
|
||
| async function readCompose() { | ||
| const source = await readFile(composePath, "utf8"); | ||
| return parse(source) as ComposeFile; | ||
| } | ||
|
|
||
| describe("local Docker compose file", () => { | ||
| it("keeps the expected local development services wired", async () => { | ||
| const compose = await readCompose(); | ||
|
|
||
| expect(compose.name).toBe("cap-so-dev"); | ||
| expect(Object.keys(compose.services ?? {}).sort()).toEqual([ | ||
| "cap-media-server", | ||
| "createbuckets", | ||
| "minio", | ||
| "ps-mysql", | ||
| ]); | ||
|
|
||
| expect(compose.services?.["ps-mysql"]).toMatchObject({ | ||
| image: "mysql:8.0", | ||
| container_name: "mysql-primary-db", | ||
| }); | ||
| expect(compose.services?.["cap-media-server"]?.build).toEqual({ | ||
| context: "../..", | ||
| dockerfile: "apps/media-server/Dockerfile", | ||
| }); | ||
| expect(compose.services?.minio?.ports).toEqual(["9000:9000", "9001:9001"]); | ||
| expect(compose.services?.createbuckets?.depends_on).toEqual(["minio"]); | ||
| }); | ||
|
|
||
| it("does not declare stale named volumes", async () => { | ||
| const compose = await readCompose(); | ||
| const declaredVolumes = new Set(Object.keys(compose.volumes ?? {})); | ||
| const usedNamedVolumes = new Set( | ||
| Object.values(compose.services ?? {}) | ||
| .flatMap((service) => service.volumes ?? []) | ||
| .map((volume) => volume.split(":")[0]) | ||
| .filter( | ||
| (source) => | ||
| source && | ||
| !source.startsWith(".") && | ||
| !source.startsWith("/") && | ||
| !source.startsWith("~"), | ||
| ), | ||
| ); | ||
|
|
||
| expect([...declaredVolumes].sort()).toEqual([...usedNamedVolumes].sort()); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,8 @@ | ||||||
| import { defineConfig } from "vitest/config"; | ||||||
|
|
||||||
| export default defineConfig({ | ||||||
| test: { | ||||||
| environment: "node", | ||||||
| include: ["**/*.test.ts"], | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/local-docker/vitest.config.ts
Line: 6
Comment:
The `include` pattern `["**/*.test.ts"]` will recurse through all subdirectories. Since this package's tests live at the root level, scoping it to `["*.test.ts"]` is both cleaner and avoids any accidental discovery of test files that end up in sub-directories (e.g., a future `scripts/` folder).
```suggestion
include: ["*.test.ts"],
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
| }, | ||||||
| }); | ||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readCompose()is called independently inside eachitblock, which reads and parses the YAML file twice per test run. Hoisting the parse into abeforeAlland sharing the result removes the duplicate I/O and makes the shared setup intent explicit.Prompt To Fix With AI