racejar 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.3](https://github.com/portabletext/editor/compare/racejar-v1.0.2...racejar-v1.0.3) (2024-12-01)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * fix type error when defining inline steps without using generics ([d371044](https://github.com/portabletext/editor/commit/d371044dae46e87188bfc52cbadd8708748bb0ce))
9
+
10
+ ## [1.0.2](https://github.com/portabletext/editor/compare/racejar-v1.0.1...racejar-v1.0.2) (2024-11-29)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * allow synchronous step callbacks ([a8b1848](https://github.com/portabletext/editor/commit/a8b18489a5beaa1bd013d4753361357d53f44650))
16
+ * make parameter types optional ([3f35c97](https://github.com/portabletext/editor/commit/3f35c97cc2fcb7790f2edcd733132cefc35ae17d))
17
+
3
18
  ## [1.0.1](https://github.com/portabletext/editor/compare/racejar-v1.0.0...racejar-v1.0.1) (2024-11-26)
4
19
 
5
20
 
package/README.md CHANGED
@@ -106,7 +106,44 @@ import {createParameterType} from 'racejar'
106
106
  const parameterTypes = [createParameterType(/* ... */)]
107
107
  ```
108
108
 
109
- ## Example Usage
109
+ ## Basic Example
110
+
111
+ ```ts
112
+ import {Given, Then, When} from 'racejar'
113
+ import {Feature} from 'racejar/vitest'
114
+ import {expect} from 'vitest'
115
+
116
+ function greet(name: string) {
117
+ return `Hello, ${name}!`
118
+ }
119
+
120
+ type Context = {
121
+ person: string
122
+ greeting: string
123
+ }
124
+
125
+ Feature({
126
+ featureText: `
127
+ Feature: Greeting
128
+ Scenario: Greeting a person
129
+ Given the person "Herman"
130
+ When greeting the person
131
+ Then the greeting is "Hello, Herman!"`,
132
+ stepDefinitions: [
133
+ Given('the person {string}', (context: Context, person: string) => {
134
+ context.person = person
135
+ }),
136
+ When('greeting the person', (context: Context) => {
137
+ context.greeting = greet(context.person)
138
+ }),
139
+ Then('the greeting is {string}', (context: Context, greeting: string) => {
140
+ expect(context.greeting).toBe(greeting)
141
+ }),
142
+ ],
143
+ })
144
+ ```
145
+
146
+ ## Advanced Example
110
147
 
111
148
  The following example is taken from the [`editor`](/packages/editor/) package in this repository. For a full example of how to use `racejar`, head over to [/packages/editor/gherkin-tests/](/packages/editor/gherkin-tests/). The package uses `racejar` to run a [Playwright](https://playwright.dev/) E2E test suite powered by [Vitest Browser Mode](https://vitest.dev/guide/browser/).
112
149
 
@@ -0,0 +1,32 @@
1
+ import {expect} from 'vitest'
2
+ import {Given, Then, When} from '../src/step-definitions'
3
+ import {Feature} from '../src/vitest'
4
+
5
+ function greet(name: string) {
6
+ return `Hello, ${name}!`
7
+ }
8
+
9
+ type Context = {
10
+ person: string
11
+ greeting: string
12
+ }
13
+
14
+ Feature({
15
+ featureText: `
16
+ Feature: Greeting
17
+ Scenario: Greeting a person
18
+ Given the person "Herman"
19
+ When greeting the person
20
+ Then the greeting is "Hello, Herman!"`,
21
+ stepDefinitions: [
22
+ Given('the person {string}', (context: Context, person: string) => {
23
+ context.person = person
24
+ }),
25
+ When('greeting the person', (context: Context) => {
26
+ context.greeting = greet(context.person)
27
+ }),
28
+ Then('the greeting is {string}', (context: Context, greeting: string) => {
29
+ expect(context.greeting).toBe(greeting)
30
+ }),
31
+ ],
32
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "racejar",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A testing framework agnostic Gherkin driver",
5
5
  "keywords": [
6
6
  "cucumber",
@@ -40,8 +40,8 @@
40
40
  "@cucumber/gherkin": "^30.0.4",
41
41
  "@cucumber/messages": "^27.0.2",
42
42
  "@jest/globals": "^29.7.0",
43
- "@sanity/pkg-utils": "^6.11.12",
44
- "typescript": "5.6.3",
43
+ "@sanity/pkg-utils": "^6.11.13",
44
+ "typescript": "5.7.2",
45
45
  "vitest": "^2.1.5"
46
46
  },
47
47
  "peerDependencies": {
@@ -51,6 +51,8 @@
51
51
  "scripts": {
52
52
  "check:lint": "biome lint .",
53
53
  "check:types": "tsc",
54
- "lint:fix": "biome lint --write ."
54
+ "lint:fix": "biome lint --write .",
55
+ "test": "vitest --run",
56
+ "test:watch": "vitest"
55
57
  }
56
58
  }
@@ -5,10 +5,7 @@ import {
5
5
  } from '@cucumber/cucumber-expressions'
6
6
  import * as Gherkin from '@cucumber/gherkin'
7
7
  import * as Messages from '@cucumber/messages'
8
- import type {
9
- StepDefinition,
10
- StepDefinitionCallbackParameters,
11
- } from './step-definitions'
8
+ import type {StepDefinition} from './step-definitions'
12
9
 
13
10
  /**
14
11
  * @public
@@ -19,7 +16,7 @@ export type CompiledFeature = {
19
16
  scenarios: Array<{
20
17
  name: string
21
18
  tag?: 'only' | 'skip'
22
- steps: Array<() => Promise<void>>
19
+ steps: Array<() => Promise<void> | void>
23
20
  }>
24
21
  }
25
22
 
@@ -33,7 +30,7 @@ export function compileFeature<TContext extends Record<string, any> = object>({
33
30
  }: {
34
31
  featureText: string
35
32
  stepDefinitions: Array<StepDefinition<TContext, any, any, any>>
36
- parameterTypes: Array<ParameterType<unknown>>
33
+ parameterTypes?: Array<ParameterType<unknown>>
37
34
  }): CompiledFeature {
38
35
  const uuidFn = Messages.IdGenerator.uuid()
39
36
  const builder = new Gherkin.AstBuilder(uuidFn)
@@ -48,9 +45,11 @@ export function compileFeature<TContext extends Record<string, any> = object>({
48
45
  )
49
46
 
50
47
  const parameterTypeRegistry = new ParameterTypeRegistry()
51
- parameterTypes.forEach((parameterType) =>
52
- parameterTypeRegistry.defineParameterType(parameterType),
53
- )
48
+ if (parameterTypes) {
49
+ parameterTypes.forEach((parameterType) =>
50
+ parameterTypeRegistry.defineParameterType(parameterType),
51
+ )
52
+ }
54
53
 
55
54
  if (!gherkinDocument.feature) {
56
55
  throw new Error('No feature found')
@@ -114,11 +113,9 @@ export function compileFeature<TContext extends Record<string, any> = object>({
114
113
  throw new Error(`Multiple implementations found for step: ${step.text}`)
115
114
  }
116
115
 
117
- const args = matchingStep.args.map((arg) =>
118
- arg.getValue(matchingStep),
119
- ) as StepDefinitionCallbackParameters<any, any, any>
116
+ const args = matchingStep.args.map((arg) => arg.getValue(matchingStep))
120
117
 
121
- return () => matchingStep.callback(context, ...args)
118
+ return () => matchingStep.callback(context, args[0], args[1], args[2])
122
119
  })
123
120
 
124
121
  return {
@@ -13,7 +13,7 @@ export function Feature<TContext extends Record<string, any> = object>({
13
13
  }: {
14
14
  featureText: string
15
15
  stepDefinitions: Array<StepDefinition<TContext, any, any, any>>
16
- parameterTypes: Array<ParameterType<unknown>>
16
+ parameterTypes?: Array<ParameterType<unknown>>
17
17
  }) {
18
18
  const feature = compileFeature({
19
19
  featureText,
@@ -1,30 +1,27 @@
1
1
  /**
2
2
  * @public
3
3
  */
4
- export type StepDefinitionCallbackParameters<
4
+ export type StepDefinitionCallback<
5
+ TContext extends Record<string, any> = object,
5
6
  TParamA = undefined,
6
7
  TParamB = undefined,
7
8
  TParamC = undefined,
8
9
  > = TParamA extends undefined
9
- ? []
10
+ ? (context: TContext) => Promise<void> | void
10
11
  : TParamB extends undefined
11
- ? [TParamA]
12
+ ? (context: TContext, paramA: TParamA) => Promise<void> | void
12
13
  : TParamC extends undefined
13
- ? [TParamA, TParamB]
14
- : [TParamA, TParamB, TParamC]
15
-
16
- /**
17
- * @public
18
- */
19
- export type StepDefinitionCallback<
20
- TContext extends Record<string, any> = object,
21
- TParamA = undefined,
22
- TParamB = undefined,
23
- TParamC = undefined,
24
- > = (
25
- context: TContext,
26
- ...args: StepDefinitionCallbackParameters<TParamA, TParamB, TParamC>
27
- ) => Promise<void>
14
+ ? (
15
+ context: TContext,
16
+ paramA: TParamA,
17
+ paramB: TParamB,
18
+ ) => Promise<void> | void
19
+ : (
20
+ context: TContext,
21
+ paramA: TParamA,
22
+ paramB: TParamB,
23
+ paramC: TParamC,
24
+ ) => Promise<void> | void
28
25
 
29
26
  /**
30
27
  * @public
@@ -13,7 +13,7 @@ export function Feature<TContext extends Record<string, any> = object>({
13
13
  }: {
14
14
  featureText: string
15
15
  stepDefinitions: Array<StepDefinition<TContext, any, any, any>>
16
- parameterTypes: Array<ParameterType<unknown>>
16
+ parameterTypes?: Array<ParameterType<unknown>>
17
17
  }) {
18
18
  const feature = compileFeature({
19
19
  featureText,
@@ -0,0 +1,17 @@
1
+ /// <reference types="vitest" />
2
+ import {defineWorkspace} from 'vitest/config'
3
+
4
+ export default defineWorkspace([
5
+ {
6
+ plugins: [],
7
+ test: {
8
+ name: 'unit',
9
+ },
10
+ },
11
+ {
12
+ plugins: [],
13
+ test: {
14
+ name: 'chromium',
15
+ },
16
+ },
17
+ ])