Skip to content

Commit

Permalink
Avoid importing anything but types from @cucumber/messages
Browse files Browse the repository at this point in the history
.. 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
  • Loading branch information
badeball committed Feb 9, 2025
1 parent c3f823a commit 510ed11
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 35 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

## Unreleased

- Import types-only from `@cucumber/messages`, fixes [#1273](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1273).

## v22.0.0

Breaking changes:
Expand Down
2 changes: 1 addition & 1 deletion lib/bin/cucumber-json-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Writable } from "stream";

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

import messages from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

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

Expand Down
38 changes: 22 additions & 16 deletions lib/browser-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as messages from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

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

Expand Down Expand Up @@ -72,6 +72,12 @@ import {
} from "./helpers/options";
import { Position } from "./helpers/source-map";

import {
SourceMediaType,
StepDefinitionPatternType,
TestStepResultStatus,
} from "./helpers/messages-enums";

type Node = ReturnType<typeof parse>;

type TestStepIds = Map<string, Map<string, string>>;
Expand Down Expand Up @@ -268,7 +274,7 @@ function emitSkippedPickle(
testStepId,
testCaseStartedId,
testStepResult: {
status: messages.TestStepResultStatus.SKIPPED,
status: TestStepResultStatus.SKIPPED,
duration: {
seconds: 0,
nanos: 0,
Expand Down Expand Up @@ -596,7 +602,7 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
testStepId,
testCaseStartedId,
testStepResult: {
status: messages.TestStepResultStatus.PENDING,
status: TestStepResultStatus.PENDING,
duration: duration(start, end),
},
timestamp: end,
Expand All @@ -606,7 +612,7 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
testStepId,
testCaseStartedId,
testStepResult: {
status: messages.TestStepResultStatus.SKIPPED,
status: TestStepResultStatus.SKIPPED,
duration: duration(start, end),
},
timestamp: end,
Expand Down Expand Up @@ -637,7 +643,7 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
testStepId,
testCaseStartedId,
testStepResult: {
status: messages.TestStepResultStatus.SKIPPED,
status: TestStepResultStatus.SKIPPED,
duration: {
seconds: 0,
nanos: 0,
Expand All @@ -657,7 +663,7 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
testStepId,
testCaseStartedId,
testStepResult: {
status: messages.TestStepResultStatus.PASSED,
status: TestStepResultStatus.PASSED,
duration: duration(start, end),
},
timestamp: end,
Expand Down Expand Up @@ -959,7 +965,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
testStepId,
testCaseStartedId,
testStepResult: {
status: messages.TestStepResultStatus.UNDEFINED,
status: TestStepResultStatus.UNDEFINED,
duration: {
seconds: 0,
nanos: 0,
Expand All @@ -972,8 +978,8 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
testCaseStartedId,
testStepResult: {
status: error.includes("Multiple matching step definitions for")
? messages.TestStepResultStatus.AMBIGUOUS
: messages.TestStepResultStatus.FAILED,
? TestStepResultStatus.AMBIGUOUS
: TestStepResultStatus.FAILED,
message: error,
duration: duration(
assertAndReturn(
Expand Down Expand Up @@ -1010,7 +1016,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
testStepId,
testCaseStartedId,
testStepResult: {
status: messages.TestStepResultStatus.SKIPPED,
status: TestStepResultStatus.SKIPPED,
duration: {
seconds: 0,
nanos: 0,
Expand Down Expand Up @@ -1041,7 +1047,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
testStepId,
testCaseStartedId,
testStepResult: {
status: messages.TestStepResultStatus.SKIPPED,
status: TestStepResultStatus.SKIPPED,
duration: duration(currentStepStartedAt, endTimestamp),
},
timestamp: endTimestamp,
Expand Down Expand Up @@ -1070,7 +1076,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
testStepId,
testCaseStartedId,
testStepResult: {
status: messages.TestStepResultStatus.SKIPPED,
status: TestStepResultStatus.SKIPPED,
duration: {
seconds: 0,
nanos: 0,
Expand Down Expand Up @@ -1102,7 +1108,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
testStepId,
testCaseStartedId,
testStepResult: {
status: messages.TestStepResultStatus.UNKNOWN,
status: TestStepResultStatus.UNKNOWN,
duration: {
seconds: 0,
nanos: 0,
Expand Down Expand Up @@ -1199,8 +1205,8 @@ export default function createTests(
registry.stepDefinitions.map((stepDefinition) => {
const type: messages.StepDefinitionPatternType =
stepDefinition.expression instanceof RegularExpression
? messages.StepDefinitionPatternType.REGULAR_EXPRESSION
: messages.StepDefinitionPatternType.CUCUMBER_EXPRESSION;
? StepDefinitionPatternType.REGULAR_EXPRESSION
: StepDefinitionPatternType.CUCUMBER_EXPRESSION;

return {
id: stepDefinition.id,
Expand Down Expand Up @@ -1276,7 +1282,7 @@ export default function createTests(
gherkinDocument.uri,
"Expected gherkin document to have URI",
),
mediaType: messages.SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN,
mediaType: SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN,
},
});

Expand Down
2 changes: 1 addition & 1 deletion lib/cypress-task-definitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import messages from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

export const TASK_SPEC_ENVELOPES =
"cypress-cucumber-preprocessor:spec-envelopes";
Expand Down
2 changes: 1 addition & 1 deletion lib/data_table.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert";

import messages from "@cucumber/messages";
import * as messages from "@cucumber/messages";

import DataTable from "./data_table";

Expand Down
2 changes: 1 addition & 1 deletion lib/data_table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import messages from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

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

Expand Down
8 changes: 5 additions & 3 deletions lib/entrypoint-browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AttachmentContentEncoding, Pickle } from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

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

Expand Down Expand Up @@ -42,6 +42,8 @@ import {

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

import { AttachmentContentEncoding } from "./helpers/messages-enums";

function defineStep<T extends unknown[], C extends Mocha.Context>(
description: string | RegExp,
implementation: IStepDefinitionBody<T, C>,
Expand Down Expand Up @@ -162,7 +164,7 @@ function defineAfterAll(
function createStringAttachment(
data: string,
mediaType: string,
encoding: AttachmentContentEncoding,
encoding: messages.AttachmentContentEncoding,
) {
const taskData: ITaskCreateStringAttachment = {
data,
Expand Down Expand Up @@ -215,7 +217,7 @@ const NOT_FEATURE_ERROR =
"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";

function doesFeatureMatch(expression: string) {
let pickle: Pickle;
let pickle: messages.Pickle;

try {
pickle = retrieveInternalSpecProperties().pickle;
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/ast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import messages from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

import { assertAndReturn } from "./assertions";

Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
UsageFormatter,
} from "@cucumber/cucumber";

import messages from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

import chalk from "chalk";

Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/merge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "fs/promises";

import * as messages from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

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

Expand Down
31 changes: 31 additions & 0 deletions lib/helpers/messages-enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export enum PickleStepType {
UNKNOWN = "Unknown",
CONTEXT = "Context",
ACTION = "Action",
OUTCOME = "Outcome",
}

export enum AttachmentContentEncoding {
IDENTITY = "IDENTITY",
BASE64 = "BASE64",
}

export enum StepDefinitionPatternType {
CUCUMBER_EXPRESSION = "CUCUMBER_EXPRESSION",
REGULAR_EXPRESSION = "REGULAR_EXPRESSION",
}

export enum TestStepResultStatus {
UNKNOWN = "UNKNOWN",
PASSED = "PASSED",
SKIPPED = "SKIPPED",
PENDING = "PENDING",
UNDEFINED = "UNDEFINED",
AMBIGUOUS = "AMBIGUOUS",
FAILED = "FAILED",
}

export enum SourceMediaType {
TEXT_X_CUCUMBER_GHERKIN_PLAIN = "text/x.cucumber.gherkin+plain",
TEXT_X_CUCUMBER_GHERKIN_MARKDOWN = "text/x.cucumber.gherkin+markdown",
}
2 changes: 1 addition & 1 deletion lib/helpers/messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as messages from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

export type StrictTimestamp = {
seconds: number;
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as messages from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

import { collectTagNames } from "./ast";

Expand Down
14 changes: 9 additions & 5 deletions lib/helpers/snippets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { GeneratedExpression } from "@cucumber/cucumber-expressions";

import * as messages from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

import { PickleStepType } from "./messages-enums";

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

export function getFunctionName(type: messages.PickleStepType) {
switch (type) {
case messages.PickleStepType.CONTEXT:
case PickleStepType.CONTEXT:
return "Given";
case messages.PickleStepType.ACTION:
case PickleStepType.ACTION:
return "When";
case messages.PickleStepType.OUTCOME:
case PickleStepType.OUTCOME:
return "Then";
case messages.PickleStepType.UNKNOWN:
case PickleStepType.UNKNOWN:
return "Given";
default:
throw "Unknown PickleStepType: " + type;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/public-member-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as messages from "@cucumber/messages";
import type * as messages from "@cucumber/messages";

export interface IParameterTypeDefinition<T, C extends Mocha.Context> {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

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

import { IdGenerator } from "@cucumber/messages";
import type { IdGenerator } from "@cucumber/messages";

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

Expand Down

0 comments on commit 510ed11

Please sign in to comment.