racejar 1.0.3 → 1.1.1

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.1.1](https://github.com/portabletext/editor/compare/racejar-v1.1.0...racejar-v1.1.1) (2024-12-13)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **deps:** update dependency @playwright/test to ^1.49.1 ([21e0e3e](https://github.com/portabletext/editor/commit/21e0e3efe4b9451956f9d4133d65dca5147b3c64))
9
+
10
+ ## [1.1.0](https://github.com/portabletext/editor/compare/racejar-v1.0.3...racejar-v1.1.0) (2024-12-02)
11
+
12
+
13
+ ### Features
14
+
15
+ * **`compileFeature`:** allow passing context to each `step` ([05d6a23](https://github.com/portabletext/editor/commit/05d6a233d18eada7a46ff52520155f22d58f6ae4))
16
+ * add initial version of `racejar/playwright` ([2cac384](https://github.com/portabletext/editor/commit/2cac3846db0f01a157c00d55b0b7ba802278fe0a))
17
+
3
18
  ## [1.0.3](https://github.com/portabletext/editor/compare/racejar-v1.0.2...racejar-v1.0.3) (2024-12-01)
4
19
 
5
20
 
@@ -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",
3
+ "version": "1.1.1",
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,13 +44,15 @@
40
44
  "@cucumber/gherkin": "^30.0.4",
41
45
  "@cucumber/messages": "^27.0.2",
42
46
  "@jest/globals": "^29.7.0",
43
- "@sanity/pkg-utils": "^6.11.13",
47
+ "@playwright/test": "^1.49.1",
48
+ "@sanity/pkg-utils": "^6.12.0",
44
49
  "typescript": "5.7.2",
45
- "vitest": "^2.1.5"
50
+ "vitest": "^2.1.8"
46
51
  },
47
52
  "peerDependencies": {
48
53
  "@jest/globals": "^29.7.0",
49
- "vitest": "^2.1.5"
54
+ "@playwright/test": "^1.49.1",
55
+ "vitest": "^2.1.8"
50
56
  },
51
57
  "scripts": {
52
58
  "check:lint": "biome lint .",
@@ -10,20 +10,24 @@ import type {StepDefinition} from './step-definitions'
10
10
  /**
11
11
  * @public
12
12
  */
13
- export type CompiledFeature = {
14
- name: string
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
- steps: Array<() => Promise<void> | void>
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<TContext extends Record<string, any> = object>({
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 () => matchingStep.callback(context, args[0], args[1], args[2])
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, () => {
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
+ }
@@ -6,12 +6,14 @@ export default defineWorkspace([
6
6
  plugins: [],
7
7
  test: {
8
8
  name: 'unit',
9
+ exclude: ['example-playwright'],
9
10
  },
10
11
  },
11
12
  {
12
13
  plugins: [],
13
14
  test: {
14
15
  name: 'chromium',
16
+ exclude: ['example-playwright'],
15
17
  },
16
18
  },
17
19
  ])