Skip to content
Open
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
10 changes: 7 additions & 3 deletions apps/service/src/__tests__/workflow.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
import { describe, it, expect, beforeAll, afterAll, inject } from 'vitest'
import { TestWorkflowEnvironment } from '@temporalio/testing'
import { Worker } from '@temporalio/worker'
import path from 'node:path'
Expand Down Expand Up @@ -31,10 +31,14 @@ function stubActivities(overrides: Partial<SyncActivities> = {}): SyncActivities
let testEnv: TestWorkflowEnvironment

beforeAll(async () => {
testEnv = await TestWorkflowEnvironment.createLocal()
}, 120_000)
// Connect to the shared dev server started in vitest.global-setup.ts instead of
// spawning a new one per file — avoids concurrent startup races under file parallelism.
const address = inject('temporalTestServerAddress')
testEnv = await TestWorkflowEnvironment.createFromExistingServer({ address })
}, 30_000)

afterAll(async () => {
// teardown() on an existing-server env only closes connections, not the server itself.
await testEnv?.teardown()
})

Expand Down
8 changes: 6 additions & 2 deletions apps/service/src/api/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it, beforeAll, afterAll } from 'vitest'
import { describe, expect, it, beforeAll, afterAll, inject } from 'vitest'
import type { WorkflowClient } from '@temporalio/client'
import { TestWorkflowEnvironment } from '@temporalio/testing'
import { Worker } from '@temporalio/worker'
Expand Down Expand Up @@ -90,7 +90,10 @@ let worker: Worker
let workerRunning: Promise<void>

beforeAll(async () => {
testEnv = await TestWorkflowEnvironment.createLocal()
// Connect to the shared dev server started in vitest.global-setup.ts instead of
// spawning a new one per file — avoids concurrent startup races under file parallelism.
const address = inject('temporalTestServerAddress')
testEnv = await TestWorkflowEnvironment.createFromExistingServer({ address })
worker = await Worker.create({
connection: testEnv.nativeConnection,
taskQueue: 'test-api',
Expand All @@ -103,6 +106,7 @@ beforeAll(async () => {
afterAll(async () => {
worker?.shutdown()
await workerRunning
// teardown() on an existing-server env only closes connections, not the server itself.
await testEnv?.teardown()
})

Expand Down
1 change: 1 addition & 0 deletions apps/service/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
globalSetup: ['./vitest.global-setup.ts'],
exclude: ['**/node_modules/**', '**/dist/**', '**/*.integration.test.ts'],
testTimeout: 60_000,
hookTimeout: 60_000,
Expand Down
7 changes: 7 additions & 0 deletions apps/service/vitest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'vitest'

declare module 'vitest' {
export interface ProvidedContext {
temporalTestServerAddress: string
}
}
20 changes: 20 additions & 0 deletions apps/service/vitest.global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Vitest global setup: starts ONE Temporal dev server for the entire test run.
*
* Each test file connects to this shared server via TestWorkflowEnvironment.createFromExistingServer()
* rather than calling createLocal() per-file, which avoids concurrent startup races under
* Vitest's default file parallelism.
*/
import { TestWorkflowEnvironment } from '@temporalio/testing'
import type { GlobalSetupContext } from 'vitest/node'

let env: TestWorkflowEnvironment | undefined

export async function setup({ provide }: GlobalSetupContext) {
env = await TestWorkflowEnvironment.createLocal()
provide('temporalTestServerAddress', env.address)
}

export async function teardown() {
await env?.teardown()
}
6 changes: 1 addition & 5 deletions e2e/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ const ROOT = join(import.meta.dirname, '..')
// All plan and design files must start with YYYY-MM-DD-
const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}-[\w-]+\.md$/

const CHECKED_DIRS = [
'docs/plans/active',
'docs/plans/completed',
'docs/design',
]
const CHECKED_DIRS = ['docs/plans/active', 'docs/plans/completed', 'docs/design']

for (const dir of CHECKED_DIRS) {
describe(`${dir} naming convention`, () => {
Expand Down
Loading