racejar 1.0.3 → 1.1.0
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,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.1.0](https://github.com/portabletext/editor/compare/racejar-v1.0.3...racejar-v1.1.0) (2024-12-02)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **`compileFeature`:** allow passing context to each `step` ([05d6a23](https://github.com/portabletext/editor/commit/05d6a233d18eada7a46ff52520155f22d58f6ae4))
|
|
9
|
+
* add initial version of `racejar/playwright` ([2cac384](https://github.com/portabletext/editor/commit/2cac3846db0f01a157c00d55b0b7ba802278fe0a))
|
|
10
|
+
|
|
3
11
|
## [1.0.3](https://github.com/portabletext/editor/compare/racejar-v1.0.2...racejar-v1.0.3) (2024-12-01)
|
|
4
12
|
|
|
5
13
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {expect} from '@playwright/test'
|
|
2
|
+
import {Feature, type PlaywrightContext} from '../src/playwright'
|
|
3
|
+
import {Given, Then, When} from '../src/step-definitions'
|
|
4
|
+
|
|
5
|
+
type Context = PlaywrightContext
|
|
6
|
+
|
|
7
|
+
Feature({
|
|
8
|
+
featureText: `
|
|
9
|
+
Feature: Playwright Homepage
|
|
10
|
+
Scenario: Navigating to Get Started
|
|
11
|
+
Given the homepage
|
|
12
|
+
When clicking the "Get started" link
|
|
13
|
+
Then the heading is "Installation"`,
|
|
14
|
+
stepDefinitions: [
|
|
15
|
+
Given('the homepage', async (context: Context) => {
|
|
16
|
+
await context.playwright.page.goto('https://playwright.dev/')
|
|
17
|
+
}),
|
|
18
|
+
When(
|
|
19
|
+
'clicking the {string} link',
|
|
20
|
+
async (context: Context, linkName: string) => {
|
|
21
|
+
await context.playwright.page
|
|
22
|
+
.getByRole('link', {name: linkName})
|
|
23
|
+
.click()
|
|
24
|
+
},
|
|
25
|
+
),
|
|
26
|
+
Then(
|
|
27
|
+
'the heading is {string}',
|
|
28
|
+
async (context: Context, heading: string) => {
|
|
29
|
+
await expect(
|
|
30
|
+
context.playwright.page.getByRole('heading', {name: heading}),
|
|
31
|
+
).toBeVisible()
|
|
32
|
+
},
|
|
33
|
+
),
|
|
34
|
+
],
|
|
35
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "racejar",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A testing framework agnostic Gherkin driver",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cucumber",
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"default": "./src/jest/index.ts",
|
|
31
31
|
"types": "./src/jest/index.ts"
|
|
32
32
|
},
|
|
33
|
+
"./playwright": {
|
|
34
|
+
"default": "./src/playwright/index.ts",
|
|
35
|
+
"types": "./src/playwright/index.ts"
|
|
36
|
+
},
|
|
33
37
|
"./vitest": {
|
|
34
38
|
"default": "./src/vitest/index.ts",
|
|
35
39
|
"types": "./src/vitest/index.ts"
|
|
@@ -40,12 +44,14 @@
|
|
|
40
44
|
"@cucumber/gherkin": "^30.0.4",
|
|
41
45
|
"@cucumber/messages": "^27.0.2",
|
|
42
46
|
"@jest/globals": "^29.7.0",
|
|
47
|
+
"@playwright/test": "^1.49.0",
|
|
43
48
|
"@sanity/pkg-utils": "^6.11.13",
|
|
44
49
|
"typescript": "5.7.2",
|
|
45
50
|
"vitest": "^2.1.5"
|
|
46
51
|
},
|
|
47
52
|
"peerDependencies": {
|
|
48
53
|
"@jest/globals": "^29.7.0",
|
|
54
|
+
"@playwright/test": "^1.49.0",
|
|
49
55
|
"vitest": "^2.1.5"
|
|
50
56
|
},
|
|
51
57
|
"scripts": {
|
package/src/compile-feature.ts
CHANGED
|
@@ -10,20 +10,24 @@ import type {StepDefinition} from './step-definitions'
|
|
|
10
10
|
/**
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
|
-
export type CompiledFeature =
|
|
14
|
-
|
|
15
|
-
tag?: 'only' | 'skip'
|
|
16
|
-
scenarios: Array<{
|
|
13
|
+
export type CompiledFeature<TStepContext extends Record<string, any> = object> =
|
|
14
|
+
{
|
|
17
15
|
name: string
|
|
18
16
|
tag?: 'only' | 'skip'
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
scenarios: Array<{
|
|
18
|
+
name: string
|
|
19
|
+
tag?: 'only' | 'skip'
|
|
20
|
+
steps: Array<(stepContext?: TStepContext) => Promise<void> | void>
|
|
21
|
+
}>
|
|
22
|
+
}
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* @public
|
|
25
26
|
*/
|
|
26
|
-
export function compileFeature<
|
|
27
|
+
export function compileFeature<
|
|
28
|
+
TContext extends Record<string, any> = object,
|
|
29
|
+
TStepContext extends Record<string, any> = object,
|
|
30
|
+
>({
|
|
27
31
|
featureText,
|
|
28
32
|
stepDefinitions,
|
|
29
33
|
parameterTypes,
|
|
@@ -31,7 +35,7 @@ export function compileFeature<TContext extends Record<string, any> = object>({
|
|
|
31
35
|
featureText: string
|
|
32
36
|
stepDefinitions: Array<StepDefinition<TContext, any, any, any>>
|
|
33
37
|
parameterTypes?: Array<ParameterType<unknown>>
|
|
34
|
-
}): CompiledFeature {
|
|
38
|
+
}): CompiledFeature<TStepContext> {
|
|
35
39
|
const uuidFn = Messages.IdGenerator.uuid()
|
|
36
40
|
const builder = new Gherkin.AstBuilder(uuidFn)
|
|
37
41
|
const matcher = new Gherkin.GherkinClassicTokenMatcher()
|
|
@@ -115,7 +119,13 @@ export function compileFeature<TContext extends Record<string, any> = object>({
|
|
|
115
119
|
|
|
116
120
|
const args = matchingStep.args.map((arg) => arg.getValue(matchingStep))
|
|
117
121
|
|
|
118
|
-
return (
|
|
122
|
+
return (stepContext: TStepContext | undefined) =>
|
|
123
|
+
matchingStep.callback(
|
|
124
|
+
Object.assign(context, stepContext),
|
|
125
|
+
args[0],
|
|
126
|
+
args[1],
|
|
127
|
+
args[2],
|
|
128
|
+
)
|
|
119
129
|
})
|
|
120
130
|
|
|
121
131
|
return {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './playwright-gherkin-driver'
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type {ParameterType} from '@cucumber/cucumber-expressions'
|
|
2
|
+
import {test, type BrowserContext, type Page} from '@playwright/test'
|
|
3
|
+
import {compileFeature} from '../compile-feature'
|
|
4
|
+
import type {StepDefinition} from '../step-definitions'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export type PlaywrightContext = {
|
|
10
|
+
playwright: {
|
|
11
|
+
page: Page
|
|
12
|
+
context: BrowserContext
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export function Feature<
|
|
20
|
+
TContext extends PlaywrightContext = PlaywrightContext,
|
|
21
|
+
>({
|
|
22
|
+
featureText,
|
|
23
|
+
stepDefinitions,
|
|
24
|
+
parameterTypes,
|
|
25
|
+
}: {
|
|
26
|
+
featureText: string
|
|
27
|
+
stepDefinitions: Array<StepDefinition<TContext, any, any, any>>
|
|
28
|
+
parameterTypes?: Array<ParameterType<unknown>>
|
|
29
|
+
}) {
|
|
30
|
+
const feature = compileFeature({
|
|
31
|
+
featureText,
|
|
32
|
+
stepDefinitions,
|
|
33
|
+
parameterTypes,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const describeFn =
|
|
37
|
+
feature.tag === 'only'
|
|
38
|
+
? test.describe.only
|
|
39
|
+
: feature.tag === 'skip'
|
|
40
|
+
? test.describe.skip
|
|
41
|
+
: test.describe
|
|
42
|
+
|
|
43
|
+
describeFn(feature.name, async () => {
|
|
44
|
+
for (const scenario of feature.scenarios) {
|
|
45
|
+
const testFn =
|
|
46
|
+
scenario.tag === 'only'
|
|
47
|
+
? test.only
|
|
48
|
+
: scenario.tag === 'skip'
|
|
49
|
+
? test.skip
|
|
50
|
+
: test
|
|
51
|
+
|
|
52
|
+
testFn(scenario.name, async ({page, context}) => {
|
|
53
|
+
for (const step of scenario.steps) {
|
|
54
|
+
await step({
|
|
55
|
+
playwright: {
|
|
56
|
+
page,
|
|
57
|
+
context,
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
}
|
package/vitest.workspace.ts
CHANGED