Skip to content

Commit 672af4e

Browse files
committed
Fix type members to account for scenario hook names
This fixes #1113 [1]. [1] #1113
1 parent cf6f647 commit 672af4e

File tree

8 files changed

+48
-35
lines changed

8 files changed

+48
-35
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## Unreleased
6+
7+
- Fix type members to account for scenario hook names, fixes [#1113](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1113).
8+
59
## v19.0.0
610

711
Breaking changes:

lib/browser-runtime.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ import { runStepWithLogGroup } from "./helpers/cypress";
6363

6464
import { getTags } from "./helpers/environment";
6565

66-
import { IHookParameter, IStepHookParameter } from "./public-member-types";
66+
import {
67+
IHookOptions,
68+
IHookParameter,
69+
IStepHookParameter,
70+
} from "./public-member-types";
6771

6872
type Node = ReturnType<typeof parse>;
6973

@@ -279,10 +283,7 @@ function getTestStepId(options: {
279283
function createStepDescription({
280284
name,
281285
tags,
282-
}: {
283-
name?: string;
284-
tags?: string;
285-
}): string | undefined {
286+
}: IHookOptions): string | undefined {
286287
if (name == null && tags == null) {
287288
return;
288289
} else if (name == null) {

lib/entrypoint-browser.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
IStepHookBody,
3131
IParameterTypeDefinition,
3232
IStepDefinitionBody,
33+
IHookOptions,
3334
} from "./public-member-types";
3435

3536
import {
@@ -66,10 +67,10 @@ function defineParameterType<T, C extends Mocha.Context>(
6667
getRegistry().defineParameterType(options);
6768
}
6869

69-
function defineBefore(options: { tags?: string }, fn: IHookBody): void;
70+
function defineBefore(options: IHookOptions, fn: IHookBody): void;
7071
function defineBefore(fn: IHookBody): void;
7172
function defineBefore(
72-
optionsOrFn: IHookBody | { tags?: string },
73+
optionsOrFn: IHookBody | IHookOptions,
7374
maybeFn?: IHookBody
7475
) {
7576
if (typeof optionsOrFn === "function") {
@@ -81,10 +82,10 @@ function defineBefore(
8182
}
8283
}
8384

84-
function defineAfter(options: { tags?: string }, fn: IHookBody): void;
85+
function defineAfter(options: IHookOptions, fn: IHookBody): void;
8586
function defineAfter(fn: IHookBody): void;
8687
function defineAfter(
87-
optionsOrFn: IHookBody | { tags?: string },
88+
optionsOrFn: IHookBody | IHookOptions,
8889
maybeFn?: IHookBody
8990
) {
9091
if (typeof optionsOrFn === "function") {
@@ -96,10 +97,10 @@ function defineAfter(
9697
}
9798
}
9899

99-
function defineBeforeStep(options: { tags?: string }, fn: IStepHookBody): void;
100+
function defineBeforeStep(options: IHookOptions, fn: IStepHookBody): void;
100101
function defineBeforeStep(fn: IStepHookBody): void;
101102
function defineBeforeStep(
102-
optionsOrFn: IStepHookBody | { tags?: string },
103+
optionsOrFn: IStepHookBody | IHookOptions,
103104
maybeFn?: IStepHookBody
104105
) {
105106
if (typeof optionsOrFn === "function") {
@@ -111,10 +112,10 @@ function defineBeforeStep(
111112
}
112113
}
113114

114-
function defineAfterStep(options: { tags?: string }, fn: IStepHookBody): void;
115+
function defineAfterStep(options: IHookOptions, fn: IStepHookBody): void;
115116
function defineAfterStep(fn: IStepHookBody): void;
116117
function defineAfterStep(
117-
optionsOrFn: IStepHookBody | { tags?: string },
118+
optionsOrFn: IStepHookBody | IHookOptions,
118119
maybeFn?: IStepHookBody
119120
) {
120121
if (typeof optionsOrFn === "function") {

lib/entrypoint-node.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
IStepHookBody,
66
IParameterTypeDefinition,
77
IStepDefinitionBody,
8+
IHookOptions,
89
} from "./public-member-types";
910

1011
export {
@@ -74,44 +75,44 @@ export function attach(data: string | ArrayBuffer, mediaType?: string) {
7475
throw createUnimplemented();
7576
}
7677

77-
export function Before(options: { tags?: string }, fn: IHookBody): void;
78+
export function Before(options: IHookOptions, fn: IHookBody): void;
7879
export function Before(fn: IHookBody): void;
7980
export function Before(
8081
// eslint-disable-next-line @typescript-eslint/no-unused-vars
81-
optionsOrFn: IHookBody | { tags?: string },
82+
optionsOrFn: IHookBody | IHookOptions,
8283
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8384
maybeFn?: IHookBody
8485
) {
8586
throw createUnimplemented();
8687
}
8788

88-
export function After(options: { tags?: string }, fn: IHookBody): void;
89+
export function After(options: IHookOptions, fn: IHookBody): void;
8990
export function After(fn: IHookBody): void;
9091
export function After(
9192
// eslint-disable-next-line @typescript-eslint/no-unused-vars
92-
optionsOrFn: IHookBody | { tags?: string },
93+
optionsOrFn: IHookBody | IHookOptions,
9394
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9495
maybeFn?: IHookBody
9596
) {
9697
throw createUnimplemented();
9798
}
9899

99-
export function BeforeStep(options: { tags?: string }, fn: IStepHookBody): void;
100+
export function BeforeStep(options: IHookOptions, fn: IStepHookBody): void;
100101
export function BeforeStep(fn: IStepHookBody): void;
101102
export function BeforeStep(
102103
// eslint-disable-next-line @typescript-eslint/no-unused-vars
103-
optionsOrFn: IStepHookBody | { tags?: string },
104+
optionsOrFn: IStepHookBody | IHookOptions,
104105
// eslint-disable-next-line @typescript-eslint/no-unused-vars
105106
maybeFn?: IStepHookBody
106107
) {
107108
throw createUnimplemented();
108109
}
109110

110-
export function AfterStep(options: { tags?: string }, fn: IStepHookBody): void;
111+
export function AfterStep(options: IHookOptions, fn: IStepHookBody): void;
111112
export function AfterStep(fn: IStepHookBody): void;
112113
export function AfterStep(
113114
// eslint-disable-next-line @typescript-eslint/no-unused-vars
114-
optionsOrFn: IStepHookBody | { tags?: string },
115+
optionsOrFn: IStepHookBody | IHookOptions,
115116
// eslint-disable-next-line @typescript-eslint/no-unused-vars
116117
maybeFn?: IStepHookBody
117118
) {

lib/public-member-types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export interface IParameterTypeDefinition<T, C extends Mocha.Context> {
66
transformer: (this: C, ...match: string[]) => T;
77
}
88

9+
export interface IHookOptions {
10+
name?: string;
11+
tags?: string;
12+
}
13+
914
export interface IHookBody {
1015
(this: Mocha.Context, options: IHookParameter): void;
1116
}

lib/registry.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
IParameterTypeDefinition,
2424
IStepDefinitionBody,
2525
IHookParameter,
26+
IHookOptions,
2627
} from "./public-member-types";
2728

2829
import {
@@ -163,7 +164,7 @@ export class Registry {
163164

164165
public defineHook(
165166
keyword: ScenarioHookKeyword,
166-
options: { tags?: string },
167+
options: IHookOptions,
167168
fn: IHookBody
168169
) {
169170
this.preliminaryHooks.push(
@@ -176,17 +177,17 @@ export class Registry {
176177
);
177178
}
178179

179-
public defineBefore(options: { tags?: string }, fn: IHookBody) {
180+
public defineBefore(options: IHookOptions, fn: IHookBody) {
180181
this.defineHook("Before", options, fn);
181182
}
182183

183-
public defineAfter(options: { tags?: string }, fn: IHookBody) {
184+
public defineAfter(options: IHookOptions, fn: IHookBody) {
184185
this.defineHook("After", options, fn);
185186
}
186187

187188
public defineStepHook(
188189
keyword: StepHookKeyword,
189-
options: { tags?: string },
190+
options: IHookOptions,
190191
fn: IStepHookBody
191192
) {
192193
this.stepHooks.push(
@@ -199,11 +200,11 @@ export class Registry {
199200
);
200201
}
201202

202-
public defineBeforeStep(options: { tags?: string }, fn: IStepHookBody) {
203+
public defineBeforeStep(options: IHookOptions, fn: IStepHookBody) {
203204
this.defineStepHook("BeforeStep", options, fn);
204205
}
205206

206-
public defineAfterStep(options: { tags?: string }, fn: IStepHookBody) {
207+
public defineAfterStep(options: IHookOptions, fn: IStepHookBody) {
207208
this.defineStepHook("AfterStep", options, fn);
208209
}
209210

test-d/entrypoint-browser.test-d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Before({}, function () {
146146
expectType<Mocha.Context>(this);
147147
});
148148

149-
Before({ tags: "foo" }, function () {
149+
Before({ tags: "foo", name: "bar" }, function () {
150150
expectType<Mocha.Context>(this);
151151
});
152152

@@ -158,7 +158,7 @@ After({}, function () {
158158
expectType<Mocha.Context>(this);
159159
});
160160

161-
After({ tags: "foo" }, function () {
161+
After({ tags: "foo", name: "bar" }, function () {
162162
expectType<Mocha.Context>(this);
163163
});
164164

@@ -196,7 +196,7 @@ BeforeStep(
196196
);
197197

198198
BeforeStep(
199-
{ tags: "foo" },
199+
{ tags: "foo", name: "bar" },
200200
function ({
201201
pickle,
202202
pickleStep,
@@ -247,7 +247,7 @@ AfterStep(
247247
);
248248

249249
AfterStep(
250-
{ tags: "foo" },
250+
{ tags: "foo", name: "bar" },
251251
function ({
252252
pickle,
253253
pickleStep,

test-d/entrypoint-node.test-d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Before({}, function () {
146146
expectType<Mocha.Context>(this);
147147
});
148148

149-
Before({ tags: "foo" }, function () {
149+
Before({ tags: "foo", name: "bar" }, function () {
150150
expectType<Mocha.Context>(this);
151151
});
152152

@@ -158,7 +158,7 @@ After({}, function () {
158158
expectType<Mocha.Context>(this);
159159
});
160160

161-
After({ tags: "foo" }, function () {
161+
After({ tags: "foo", name: "bar" }, function () {
162162
expectType<Mocha.Context>(this);
163163
});
164164

@@ -196,7 +196,7 @@ BeforeStep(
196196
);
197197

198198
BeforeStep(
199-
{ tags: "foo" },
199+
{ tags: "foo", name: "bar" },
200200
function ({
201201
pickle,
202202
pickleStep,
@@ -247,7 +247,7 @@ AfterStep(
247247
);
248248

249249
AfterStep(
250-
{ tags: "foo" },
250+
{ tags: "foo", name: "bar" },
251251
function ({
252252
pickle,
253253
pickleStep,

0 commit comments

Comments
 (0)