Skip to content

Commit 510ed11

Browse files
committed
Avoid importing anything but types from @cucumber/messages
.. in the browser bundle, that is. Due to updated transitive dependencies and deduping, the build + browserify examples suddenly fail to due to error parsing nullish coalescing assignment operators [1]. [1] browserify/detective#88
1 parent c3f823a commit 510ed11

16 files changed

+82
-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+
- Import types-only from `@cucumber/messages`, fixes [#1273](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1273).
8+
59
## v22.0.0
610

711
Breaking changes:

lib/bin/cucumber-json-formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Writable } from "stream";
66

77
import { NdjsonToMessageStream } from "@cucumber/message-streams";
88

9-
import messages from "@cucumber/messages";
9+
import type * as messages from "@cucumber/messages";
1010

1111
import { createJsonFormatter } from "../helpers/formatters";
1212

lib/browser-runtime.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as messages from "@cucumber/messages";
1+
import type * as messages from "@cucumber/messages";
22

33
import parse from "@cucumber/tag-expressions";
44

@@ -72,6 +72,12 @@ import {
7272
} from "./helpers/options";
7373
import { Position } from "./helpers/source-map";
7474

75+
import {
76+
SourceMediaType,
77+
StepDefinitionPatternType,
78+
TestStepResultStatus,
79+
} from "./helpers/messages-enums";
80+
7581
type Node = ReturnType<typeof parse>;
7682

7783
type TestStepIds = Map<string, Map<string, string>>;
@@ -268,7 +274,7 @@ function emitSkippedPickle(
268274
testStepId,
269275
testCaseStartedId,
270276
testStepResult: {
271-
status: messages.TestStepResultStatus.SKIPPED,
277+
status: TestStepResultStatus.SKIPPED,
272278
duration: {
273279
seconds: 0,
274280
nanos: 0,
@@ -596,7 +602,7 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
596602
testStepId,
597603
testCaseStartedId,
598604
testStepResult: {
599-
status: messages.TestStepResultStatus.PENDING,
605+
status: TestStepResultStatus.PENDING,
600606
duration: duration(start, end),
601607
},
602608
timestamp: end,
@@ -606,7 +612,7 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
606612
testStepId,
607613
testCaseStartedId,
608614
testStepResult: {
609-
status: messages.TestStepResultStatus.SKIPPED,
615+
status: TestStepResultStatus.SKIPPED,
610616
duration: duration(start, end),
611617
},
612618
timestamp: end,
@@ -637,7 +643,7 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
637643
testStepId,
638644
testCaseStartedId,
639645
testStepResult: {
640-
status: messages.TestStepResultStatus.SKIPPED,
646+
status: TestStepResultStatus.SKIPPED,
641647
duration: {
642648
seconds: 0,
643649
nanos: 0,
@@ -657,7 +663,7 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
657663
testStepId,
658664
testCaseStartedId,
659665
testStepResult: {
660-
status: messages.TestStepResultStatus.PASSED,
666+
status: TestStepResultStatus.PASSED,
661667
duration: duration(start, end),
662668
},
663669
timestamp: end,
@@ -959,7 +965,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
959965
testStepId,
960966
testCaseStartedId,
961967
testStepResult: {
962-
status: messages.TestStepResultStatus.UNDEFINED,
968+
status: TestStepResultStatus.UNDEFINED,
963969
duration: {
964970
seconds: 0,
965971
nanos: 0,
@@ -972,8 +978,8 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
972978
testCaseStartedId,
973979
testStepResult: {
974980
status: error.includes("Multiple matching step definitions for")
975-
? messages.TestStepResultStatus.AMBIGUOUS
976-
: messages.TestStepResultStatus.FAILED,
981+
? TestStepResultStatus.AMBIGUOUS
982+
: TestStepResultStatus.FAILED,
977983
message: error,
978984
duration: duration(
979985
assertAndReturn(
@@ -1010,7 +1016,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
10101016
testStepId,
10111017
testCaseStartedId,
10121018
testStepResult: {
1013-
status: messages.TestStepResultStatus.SKIPPED,
1019+
status: TestStepResultStatus.SKIPPED,
10141020
duration: {
10151021
seconds: 0,
10161022
nanos: 0,
@@ -1041,7 +1047,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
10411047
testStepId,
10421048
testCaseStartedId,
10431049
testStepResult: {
1044-
status: messages.TestStepResultStatus.SKIPPED,
1050+
status: TestStepResultStatus.SKIPPED,
10451051
duration: duration(currentStepStartedAt, endTimestamp),
10461052
},
10471053
timestamp: endTimestamp,
@@ -1070,7 +1076,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
10701076
testStepId,
10711077
testCaseStartedId,
10721078
testStepResult: {
1073-
status: messages.TestStepResultStatus.SKIPPED,
1079+
status: TestStepResultStatus.SKIPPED,
10741080
duration: {
10751081
seconds: 0,
10761082
nanos: 0,
@@ -1102,7 +1108,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
11021108
testStepId,
11031109
testCaseStartedId,
11041110
testStepResult: {
1105-
status: messages.TestStepResultStatus.UNKNOWN,
1111+
status: TestStepResultStatus.UNKNOWN,
11061112
duration: {
11071113
seconds: 0,
11081114
nanos: 0,
@@ -1199,8 +1205,8 @@ export default function createTests(
11991205
registry.stepDefinitions.map((stepDefinition) => {
12001206
const type: messages.StepDefinitionPatternType =
12011207
stepDefinition.expression instanceof RegularExpression
1202-
? messages.StepDefinitionPatternType.REGULAR_EXPRESSION
1203-
: messages.StepDefinitionPatternType.CUCUMBER_EXPRESSION;
1208+
? StepDefinitionPatternType.REGULAR_EXPRESSION
1209+
: StepDefinitionPatternType.CUCUMBER_EXPRESSION;
12041210

12051211
return {
12061212
id: stepDefinition.id,
@@ -1276,7 +1282,7 @@ export default function createTests(
12761282
gherkinDocument.uri,
12771283
"Expected gherkin document to have URI",
12781284
),
1279-
mediaType: messages.SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN,
1285+
mediaType: SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN,
12801286
},
12811287
});
12821288

lib/cypress-task-definitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import messages from "@cucumber/messages";
1+
import type * as messages from "@cucumber/messages";
22

33
export const TASK_SPEC_ENVELOPES =
44
"cypress-cucumber-preprocessor:spec-envelopes";

lib/data_table.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "assert";
22

3-
import messages from "@cucumber/messages";
3+
import * as messages from "@cucumber/messages";
44

55
import DataTable from "./data_table";
66

lib/data_table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import messages from "@cucumber/messages";
1+
import type * as messages from "@cucumber/messages";
22

33
import { assert, assertAndReturn } from "./helpers/assertions";
44

lib/entrypoint-browser.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AttachmentContentEncoding, Pickle } from "@cucumber/messages";
1+
import type * as messages from "@cucumber/messages";
22

33
import parse from "@cucumber/tag-expressions";
44

@@ -42,6 +42,8 @@ import {
4242

4343
import { AddOptions } from "./add-cucumber-preprocessor-plugin";
4444

45+
import { AttachmentContentEncoding } from "./helpers/messages-enums";
46+
4547
function defineStep<T extends unknown[], C extends Mocha.Context>(
4648
description: string | RegExp,
4749
implementation: IStepDefinitionBody<T, C>,
@@ -162,7 +164,7 @@ function defineAfterAll(
162164
function createStringAttachment(
163165
data: string,
164166
mediaType: string,
165-
encoding: AttachmentContentEncoding,
167+
encoding: messages.AttachmentContentEncoding,
166168
) {
167169
const taskData: ITaskCreateStringAttachment = {
168170
data,
@@ -215,7 +217,7 @@ const NOT_FEATURE_ERROR =
215217
"Expected to find internal properties, but didn't. This is likely because you're calling doesFeatureMatch() in a non-feature spec. Use doesFeatureMatch() in combination with isFeature() if you have both feature and non-feature specs";
216218

217219
function doesFeatureMatch(expression: string) {
218-
let pickle: Pickle;
220+
let pickle: messages.Pickle;
219221

220222
try {
221223
pickle = retrieveInternalSpecProperties().pickle;

lib/helpers/ast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import messages from "@cucumber/messages";
1+
import type * as messages from "@cucumber/messages";
22

33
import { assertAndReturn } from "./assertions";
44

lib/helpers/formatters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
UsageFormatter,
1212
} from "@cucumber/cucumber";
1313

14-
import messages from "@cucumber/messages";
14+
import type * as messages from "@cucumber/messages";
1515

1616
import chalk from "chalk";
1717

lib/helpers/merge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from "fs/promises";
22

3-
import * as messages from "@cucumber/messages";
3+
import type * as messages from "@cucumber/messages";
44

55
import { notNull } from "./type-guards";
66

lib/helpers/messages-enums.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export enum PickleStepType {
2+
UNKNOWN = "Unknown",
3+
CONTEXT = "Context",
4+
ACTION = "Action",
5+
OUTCOME = "Outcome",
6+
}
7+
8+
export enum AttachmentContentEncoding {
9+
IDENTITY = "IDENTITY",
10+
BASE64 = "BASE64",
11+
}
12+
13+
export enum StepDefinitionPatternType {
14+
CUCUMBER_EXPRESSION = "CUCUMBER_EXPRESSION",
15+
REGULAR_EXPRESSION = "REGULAR_EXPRESSION",
16+
}
17+
18+
export enum TestStepResultStatus {
19+
UNKNOWN = "UNKNOWN",
20+
PASSED = "PASSED",
21+
SKIPPED = "SKIPPED",
22+
PENDING = "PENDING",
23+
UNDEFINED = "UNDEFINED",
24+
AMBIGUOUS = "AMBIGUOUS",
25+
FAILED = "FAILED",
26+
}
27+
28+
export enum SourceMediaType {
29+
TEXT_X_CUCUMBER_GHERKIN_PLAIN = "text/x.cucumber.gherkin+plain",
30+
TEXT_X_CUCUMBER_GHERKIN_MARKDOWN = "text/x.cucumber.gherkin+markdown",
31+
}

lib/helpers/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as messages from "@cucumber/messages";
1+
import type * as messages from "@cucumber/messages";
22

33
export type StrictTimestamp = {
44
seconds: number;

lib/helpers/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as messages from "@cucumber/messages";
1+
import type * as messages from "@cucumber/messages";
22

33
import { collectTagNames } from "./ast";
44

lib/helpers/snippets.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { GeneratedExpression } from "@cucumber/cucumber-expressions";
22

3-
import * as messages from "@cucumber/messages";
3+
import type * as messages from "@cucumber/messages";
4+
5+
import { PickleStepType } from "./messages-enums";
46

57
const TEMPLATE = `
68
[function]("[definition]", function ([arguments]) {
@@ -10,14 +12,16 @@ const TEMPLATE = `
1012

1113
export function getFunctionName(type: messages.PickleStepType) {
1214
switch (type) {
13-
case messages.PickleStepType.CONTEXT:
15+
case PickleStepType.CONTEXT:
1416
return "Given";
15-
case messages.PickleStepType.ACTION:
17+
case PickleStepType.ACTION:
1618
return "When";
17-
case messages.PickleStepType.OUTCOME:
19+
case PickleStepType.OUTCOME:
1820
return "Then";
19-
case messages.PickleStepType.UNKNOWN:
21+
case PickleStepType.UNKNOWN:
2022
return "Given";
23+
default:
24+
throw "Unknown PickleStepType: " + type;
2125
}
2226
}
2327

lib/public-member-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as messages from "@cucumber/messages";
1+
import type * as messages from "@cucumber/messages";
22

33
export interface IParameterTypeDefinition<T, C extends Mocha.Context> {
44
name: string;

lib/registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88

99
import parse from "@cucumber/tag-expressions";
1010

11-
import { IdGenerator } from "@cucumber/messages";
11+
import type { IdGenerator } from "@cucumber/messages";
1212

1313
import { assertAndReturn } from "./helpers/assertions";
1414

0 commit comments

Comments
 (0)