Skip to content

Commit 21cd117

Browse files
authored
Add assert and mock to context (#20)
1 parent 291b03e commit 21cd117

File tree

3 files changed

+99
-82
lines changed

3 files changed

+99
-82
lines changed

api-report.md

Lines changed: 85 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,85 @@
1-
## API Report File for "@cucumber/node"
2-
3-
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4-
5-
```ts
6-
7-
import { Promisable } from 'type-fest';
8-
import { Readable } from 'node:stream';
9-
10-
// @public
11-
export function After(fn: HookFunction): void;
12-
13-
// @public
14-
export function After(options: HookOptions, fn: HookFunction): void;
15-
16-
// @public
17-
export type AttachmentOptions = {
18-
mediaType: string;
19-
fileName?: string;
20-
};
21-
22-
// @public
23-
export function Before(fn: HookFunction): void;
24-
25-
// @public
26-
export function Before(options: HookOptions, fn: HookFunction): void;
27-
28-
// @public
29-
export class DataTable {
30-
constructor(cells: ReadonlyArray<ReadonlyArray<string>>);
31-
hashes(): ReadonlyArray<Record<string, string>>;
32-
list(): ReadonlyArray<string>;
33-
raw(): ReadonlyArray<ReadonlyArray<string>>;
34-
transpose(): DataTable;
35-
}
36-
37-
// @public
38-
export function Given(text: string, fn: StepFunction): void;
39-
40-
// @public
41-
export type HookFunction = (context: TestCaseContext) => Promisable<void>;
42-
43-
// @public
44-
export type HookOptions = {
45-
name?: string;
46-
tagFilter?: string;
47-
};
48-
49-
// @public
50-
export function ParameterType(options: ParameterTypeOptions): void;
51-
52-
// @public
53-
export type ParameterTypeOptions = {
54-
name: string;
55-
regexp: RegExp | string | readonly RegExp[] | readonly string[];
56-
transformer?: (...match: string[]) => unknown;
57-
useForSnippets?: boolean;
58-
preferForRegexpMatch?: boolean;
59-
};
60-
61-
// @public
62-
export type StepFunction = (context: TestCaseContext, ...args: any) => Promisable<void>;
63-
64-
// @public
65-
export type TestCaseContext = {
66-
skip(): void;
67-
todo(): void;
68-
attach(data: Readable | Buffer | string, options: AttachmentOptions): Promise<void>;
69-
log(text: string): Promise<void>;
70-
link(url: string, title?: string): Promise<void>;
71-
world: any;
72-
};
73-
74-
// @public
75-
export function Then(text: string, fn: StepFunction): void;
76-
77-
// @public
78-
export function When(text: string, fn: StepFunction): void;
79-
80-
// (No @packageDocumentation comment for this package)
81-
82-
```
1+
## API Report File for "@cucumber/node"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
import { Promisable } from 'type-fest';
8+
import { Readable } from 'node:stream';
9+
import { TestContext } from 'node:test';
10+
11+
// @public
12+
export function After(fn: HookFunction): void;
13+
14+
// @public
15+
export function After(options: HookOptions, fn: HookFunction): void;
16+
17+
// @public
18+
export type AttachmentOptions = {
19+
mediaType: string;
20+
fileName?: string;
21+
};
22+
23+
// @public
24+
export function Before(fn: HookFunction): void;
25+
26+
// @public
27+
export function Before(options: HookOptions, fn: HookFunction): void;
28+
29+
// @public
30+
export class DataTable {
31+
constructor(cells: ReadonlyArray<ReadonlyArray<string>>);
32+
hashes(): ReadonlyArray<Record<string, string>>;
33+
list(): ReadonlyArray<string>;
34+
raw(): ReadonlyArray<ReadonlyArray<string>>;
35+
transpose(): DataTable;
36+
}
37+
38+
// @public
39+
export function Given(text: string, fn: StepFunction): void;
40+
41+
// @public
42+
export type HookFunction = (context: TestCaseContext) => Promisable<void>;
43+
44+
// @public
45+
export type HookOptions = {
46+
name?: string;
47+
tagFilter?: string;
48+
};
49+
50+
// @public
51+
export function ParameterType(options: ParameterTypeOptions): void;
52+
53+
// @public
54+
export type ParameterTypeOptions = {
55+
name: string;
56+
regexp: RegExp | string | readonly RegExp[] | readonly string[];
57+
transformer?: (...match: string[]) => unknown;
58+
useForSnippets?: boolean;
59+
preferForRegexpMatch?: boolean;
60+
};
61+
62+
// @public
63+
export type StepFunction = (context: TestCaseContext, ...args: any) => Promisable<void>;
64+
65+
// @public
66+
export type TestCaseContext = {
67+
assert: TestContext['assert'];
68+
mock: TestContext['mock'];
69+
skip(): void;
70+
todo(): void;
71+
attach(data: Readable | Buffer | string, options: AttachmentOptions): Promise<void>;
72+
log(text: string): Promise<void>;
73+
link(url: string, title?: string): Promise<void>;
74+
world: any;
75+
};
76+
77+
// @public
78+
export function Then(text: string, fn: StepFunction): void;
79+
80+
// @public
81+
export function When(text: string, fn: StepFunction): void;
82+
83+
// (No @packageDocumentation comment for this package)
84+
85+
```

src/runner/ContextTracker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export class ContextTracker {
1616

1717
makeContext(nodeTestContext: TestContext, testStepId: string): TestCaseContext {
1818
return {
19+
assert: nodeTestContext.assert,
20+
mock: nodeTestContext.mock,
1921
skip: () => {
2022
nodeTestContext.skip()
2123
this.outcomeKnown = true

src/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Readable } from 'node:stream'
2+
import { TestContext } from 'node:test'
23

34
import { Promisable } from 'type-fest'
45

@@ -26,6 +27,17 @@ export type AttachmentOptions = {
2627
* @public
2728
*/
2829
export type TestCaseContext = {
30+
/**
31+
* The `assert` object as provided by the test runner, including the normal methods from
32+
* `node:assert` plus extras for dealing with snapshots.
33+
* @see https://nodejs.org/api/test.html#contextassert
34+
*/
35+
assert: TestContext['assert']
36+
/**
37+
* The `mock` object as provided by the test runner.
38+
* @see https://nodejs.org/api/test.html#class-mocktracker
39+
*/
40+
mock: TestContext['mock']
2941
/**
3042
* Mark this test step as skipped. This will cause all subsequent steps to be skipped,
3143
* except `After` hooks.

0 commit comments

Comments
 (0)