racejar 1.0.1 → 1.0.2
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 +8 -0
- package/README.md +38 -1
- package/example/hello-herman.test.ts +32 -0
- package/package.json +6 -4
- package/src/compile-feature.ts +7 -5
- package/src/jest/jest-gherkin-driver.ts +1 -1
- package/src/step-definitions.ts +1 -1
- package/src/vitest/vitest-gherkin-driver.ts +1 -1
- package/vitest.workspace.ts +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.2](https://github.com/portabletext/editor/compare/racejar-v1.0.1...racejar-v1.0.2) (2024-11-29)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* allow synchronous step callbacks ([a8b1848](https://github.com/portabletext/editor/commit/a8b18489a5beaa1bd013d4753361357d53f44650))
|
|
9
|
+
* make parameter types optional ([3f35c97](https://github.com/portabletext/editor/commit/3f35c97cc2fcb7790f2edcd733132cefc35ae17d))
|
|
10
|
+
|
|
3
11
|
## [1.0.1](https://github.com/portabletext/editor/compare/racejar-v1.0.0...racejar-v1.0.1) (2024-11-26)
|
|
4
12
|
|
|
5
13
|
|
package/README.md
CHANGED
|
@@ -106,7 +106,44 @@ import {createParameterType} from 'racejar'
|
|
|
106
106
|
const parameterTypes = [createParameterType(/* ... */)]
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
## Example
|
|
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<Context, string>('the person {string}', (context, person) => {
|
|
134
|
+
context.person = person
|
|
135
|
+
}),
|
|
136
|
+
When<Context>('greeting the person', (context) => {
|
|
137
|
+
context.greeting = greet(context.person)
|
|
138
|
+
}),
|
|
139
|
+
Then<Context, string>('the greeting is {string}', (context, greeting) => {
|
|
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<Context, string>('the person {string}', (context, person) => {
|
|
23
|
+
context.person = person
|
|
24
|
+
}),
|
|
25
|
+
When<Context>('greeting the person', (context) => {
|
|
26
|
+
context.greeting = greet(context.person)
|
|
27
|
+
}),
|
|
28
|
+
Then<Context, string>('the greeting is {string}', (context, greeting) => {
|
|
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.
|
|
3
|
+
"version": "1.0.2",
|
|
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.
|
|
44
|
-
"typescript": "5.
|
|
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
|
}
|
package/src/compile-feature.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type CompiledFeature = {
|
|
|
19
19
|
scenarios: Array<{
|
|
20
20
|
name: string
|
|
21
21
|
tag?: 'only' | 'skip'
|
|
22
|
-
steps: Array<() => Promise<void
|
|
22
|
+
steps: Array<() => Promise<void> | void>
|
|
23
23
|
}>
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -33,7 +33,7 @@ export function compileFeature<TContext extends Record<string, any> = object>({
|
|
|
33
33
|
}: {
|
|
34
34
|
featureText: string
|
|
35
35
|
stepDefinitions: Array<StepDefinition<TContext, any, any, any>>
|
|
36
|
-
parameterTypes
|
|
36
|
+
parameterTypes?: Array<ParameterType<unknown>>
|
|
37
37
|
}): CompiledFeature {
|
|
38
38
|
const uuidFn = Messages.IdGenerator.uuid()
|
|
39
39
|
const builder = new Gherkin.AstBuilder(uuidFn)
|
|
@@ -48,9 +48,11 @@ export function compileFeature<TContext extends Record<string, any> = object>({
|
|
|
48
48
|
)
|
|
49
49
|
|
|
50
50
|
const parameterTypeRegistry = new ParameterTypeRegistry()
|
|
51
|
-
parameterTypes
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
if (parameterTypes) {
|
|
52
|
+
parameterTypes.forEach((parameterType) =>
|
|
53
|
+
parameterTypeRegistry.defineParameterType(parameterType),
|
|
54
|
+
)
|
|
55
|
+
}
|
|
54
56
|
|
|
55
57
|
if (!gherkinDocument.feature) {
|
|
56
58
|
throw new Error('No feature found')
|
|
@@ -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
|
|
16
|
+
parameterTypes?: Array<ParameterType<unknown>>
|
|
17
17
|
}) {
|
|
18
18
|
const feature = compileFeature({
|
|
19
19
|
featureText,
|
package/src/step-definitions.ts
CHANGED
|
@@ -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
|
|
16
|
+
parameterTypes?: Array<ParameterType<unknown>>
|
|
17
17
|
}) {
|
|
18
18
|
const feature = compileFeature({
|
|
19
19
|
featureText,
|