Skip to content
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
40 changes: 37 additions & 3 deletions compatibility/cck_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const CCK_FEATURES_PATH = 'node_modules/@cucumber/compatibility-kit/features'
const CCK_IMPLEMENTATIONS_PATH = 'compatibility/features'

const UNSUPPORTED = [
// we don't support global hooks messages yet
'global-hooks',
'global-hooks-attachments',
'global-hooks-beforeall-error',
'global-hooks-afterall-error',
Expand Down Expand Up @@ -102,9 +100,45 @@ describe('Cucumber Compatibility Kit', () => {
})
)

expect(actualMessages)
expect(reorderEnvelopes(actualMessages))
.excludingEvery(ignorableKeys)
.to.deep.eq(expectedMessages)
})
}
})

function reorderEnvelopes(
envelopes: ReadonlyArray<Envelope>
): ReadonlyArray<Envelope> {
let testRunStartedEnvelope: Envelope
let testCaseStartedEnvelope: Envelope

const result: Envelope[] = []
const moveAfterTestRunStarted: Envelope[] = []

for (const envelope of envelopes) {
if (envelope.testRunStarted) {
testRunStartedEnvelope = envelope
}
if (envelope.testCaseStarted) {
testCaseStartedEnvelope = envelope
}

if (
(envelope.testRunHookStarted || envelope.testRunHookFinished) &&
!testCaseStartedEnvelope
) {
moveAfterTestRunStarted.push(envelope)
} else {
result.push(envelope)
}
}

result.splice(
result.indexOf(testRunStartedEnvelope) + 1,
0,
...moveAfterTestRunStarted
)

return result
}
25 changes: 25 additions & 0 deletions compatibility/features/global-hooks/global-hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { When, BeforeAll, AfterAll } from '../../../src'

BeforeAll({}, function () {
// no-op
})

BeforeAll({}, function () {
// no-op
})

When('a step passes', function () {
// no-op
})

When('a step fails', function () {
throw new Error('Exception in step')
})

AfterAll({}, function () {
// no-op
})

AfterAll({}, function () {
// no-op
})
1 change: 1 addition & 0 deletions features/support/formatter_output_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const ignorableKeys = [
'pickleStepId',
'stepDefinitionIds',
'testRunStartedId',
'testRunHookStartedId',
'testCaseId',
'testCaseStartedId',
'testStepId',
Expand Down
9 changes: 4 additions & 5 deletions src/runtime/coordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Runtime } from './index'

export class Coordinator implements Runtime {
constructor(
private testRunStartedId: string,
private eventBroadcaster: EventEmitter,
private newId: IdGenerator.NewId,
private sourcedPickles: ReadonlyArray<SourcedPickle>,
Expand All @@ -16,17 +17,15 @@ export class Coordinator implements Runtime {
) {}

async run(): Promise<boolean> {
const testRunStartedId = this.newId()

this.eventBroadcaster.emit('envelope', {
testRunStarted: {
id: testRunStartedId,
id: this.testRunStartedId,
timestamp: timestamp(),
},
} satisfies Envelope)

const assembledTestCases = await assembleTestCases(
testRunStartedId,
this.testRunStartedId,
this.eventBroadcaster,
this.newId,
this.sourcedPickles,
Expand All @@ -37,7 +36,7 @@ export class Coordinator implements Runtime {

this.eventBroadcaster.emit('envelope', {
testRunFinished: {
testRunStartedId,
testRunStartedId: this.testRunStartedId,
timestamp: timestamp(),
success,
},
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/make_runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,26 @@ export async function makeRuntime({
supportCodeLibrary: SupportCodeLibrary
options: IRunOptionsRuntime
}): Promise<Runtime> {
const testRunStartedId = newId()
const adapter: RuntimeAdapter =
options.parallel > 0
? new ChildProcessAdapter(
testRunStartedId,
environment,
logger,
eventBroadcaster,
options,
supportCodeLibrary
)
: new InProcessAdapter(
testRunStartedId,
eventBroadcaster,
newId,
options,
supportCodeLibrary
)
return new Coordinator(
testRunStartedId,
eventBroadcaster,
newId,
sourcedPickles,
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/parallel/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class ChildProcessAdapter implements RuntimeAdapter {
private readonly workers: Record<string, ManagedWorker> = {}

constructor(
private readonly testRunStartedId: string,
private readonly environment: IRunEnvironment,
private readonly logger: ILogger,
private readonly eventBroadcaster: EventEmitter,
Expand Down Expand Up @@ -112,6 +113,7 @@ export class ChildProcessAdapter implements RuntimeAdapter {
})
worker.process.send({
type: 'INITIALIZE',
testRunStartedId: this.testRunStartedId,
supportCodeCoordinates: this.supportCodeLibrary.originalCoordinates,
supportCodeIds: {
stepDefinitionIds: this.supportCodeLibrary.stepDefinitions.map(
Expand All @@ -123,6 +125,10 @@ export class ChildProcessAdapter implements RuntimeAdapter {
),
afterTestCaseHookDefinitionIds:
this.supportCodeLibrary.afterTestCaseHookDefinitions.map((h) => h.id),
beforeTestRunHookDefinitionIds:
this.supportCodeLibrary.beforeTestRunHookDefinitions.map((h) => h.id),
afterTestRunHookDefinitionIds:
this.supportCodeLibrary.afterTestRunHookDefinitions.map((h) => h.id),
},
options: this.options,
} satisfies InitializeCommand)
Expand Down
1 change: 1 addition & 0 deletions src/runtime/parallel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type CoordinatorToWorkerCommand =

export interface InitializeCommand {
type: 'INITIALIZE'
testRunStartedId: string
supportCodeCoordinates: ISupportCodeCoordinates
supportCodeIds: CanonicalSupportCodeIds
options: RuntimeOptions
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/parallel/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class ChildProcessWorker {
}

async initialize({
testRunStartedId,
supportCodeCoordinates,
supportCodeIds,
options,
Expand All @@ -75,6 +76,7 @@ export class ChildProcessWorker {

this.options = options
this.worker = new Worker(
testRunStartedId,
this.id,
this.eventBroadcaster,
this.newId,
Expand Down
40 changes: 0 additions & 40 deletions src/runtime/run_test_run_hooks.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/runtime/serial/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export class InProcessAdapter implements RuntimeAdapter {
private failing: boolean = false

constructor(
testRunStartedId: string,
eventBroadcaster: EventEmitter,
newId: IdGenerator.NewId,
options: RuntimeOptions,
supportCodeLibrary: SupportCodeLibrary
) {
this.worker = new Worker(
testRunStartedId,
undefined,
eventBroadcaster,
newId,
Expand Down
Loading
Loading