@qavajs/playwright-runner-adapter 1.9.1 → 2.0.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.
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineCucumber = defineCucumber;
4
- const node_path_1 = require("node:path");
5
- /**
6
- * Define cucumber config in playwright config
7
- * @param {CucumberConfig} config
8
- * @example
9
- * export default defineConfig({
10
- * testDir: defineCucumber({
11
- * config: 'cucumber.ts',
12
- * profile: 'chrome', // optional
13
- * adapter: 'path/to/adapter' // optional
14
- * }),
15
- * })
16
- */
17
- function defineCucumber(config) {
18
- process.env.CONFIG = config.config;
19
- process.env.PROFILE = config.profile ?? 'default';
20
- return config.adapter ?? (0, node_path_1.resolve)('./node_modules/@qavajs/playwright-runner-adapter/adapter');
21
- }
22
- //# sourceMappingURL=defineCucumber.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defineCucumber.js","sourceRoot":"","sources":["../src/defineCucumber.ts"],"names":[],"mappings":";;AAoBA,wCAIC;AAxBD,yCAAoC;AAQpC;;;;;;;;;;;GAWG;AACH,SAAgB,cAAc,CAAC,MAAsB;IACjD,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,SAAS,CAAC;IAClD,OAAO,MAAM,CAAC,OAAO,IAAI,IAAA,mBAAO,EAAC,0DAA0D,CAAC,CAAC;AACjG,CAAC"}
@@ -1,211 +0,0 @@
1
- import { load } from './loader';
2
- import type { TestInfo, TestType } from '@playwright/test';
3
- import type { ITestCaseHookParameter, ITestStepHookParameter } from '@cucumber/cucumber';
4
-
5
- const { features, supportCodeLibrary } = load();
6
-
7
- function getTestId(testInfo: TestInfo) {
8
- return testInfo
9
- .annotations
10
- .find((annotation: { type: string }) => annotation.type === 'testId')!
11
- .description;
12
- }
13
-
14
- function getResult(testInfo: TestInfo) {
15
- const message = testInfo.errors.length > 0
16
- ? testInfo.errors.map((err: any) => err.message).join('\n')
17
- : undefined;
18
- return {
19
- duration: testInfo.duration as any,
20
- message,
21
- status: testInfo.status?.toUpperCase(),
22
- exception: testInfo.error
23
- };
24
- }
25
-
26
- function getLine(step: { uri: string, line: number }) {
27
- return { location: { column: 1, file: step.uri, line: step.line }}
28
- }
29
-
30
- function log(data: any) {
31
- console.log(data);
32
- }
33
-
34
- function attach(this: { test: any }, body: any, details: any) {
35
- const fileName = details?.fileName ?? 'attachment';
36
- const contentType = details?.mediaType ?? 'text/plain';
37
- this.test.info().attach(fileName, { body, contentType });
38
- }
39
-
40
- const fixture = new supportCodeLibrary.World({});
41
- const test: TestType<any, any> = fixture.test;
42
-
43
- test.beforeAll(async () => {
44
- for (const beforeAllHook of supportCodeLibrary.beforeTestRunHookDefinitions) {
45
- const location = getLine(beforeAllHook);
46
- await test.step(
47
- 'Before All',
48
- () => beforeAllHook.code.apply({}),
49
- location
50
- )
51
- }
52
- });
53
-
54
- const worlds = new Map();
55
-
56
- for (const feature of features) {
57
- const tests = feature.tests;
58
- test.describe(feature.feature as string, async () => {
59
-
60
- const worldFactory = (fixtures: any) => {
61
- const world = new supportCodeLibrary.World({
62
- log,
63
- attach,
64
- supportCodeLibrary
65
- });
66
- world.init(fixtures);
67
- worlds.set(getTestId(test.info()), world);
68
- };
69
- worldFactory.toString = () => { return fixture.init.toString() }
70
-
71
- test.beforeEach('World', worldFactory);
72
-
73
- test.beforeEach('Before Hooks', async () => {
74
- const testId = getTestId(test.info());
75
- const world = worlds.get(testId);
76
- const testCase = tests.find(test => test.id === testId)!;
77
- for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
78
- if (beforeHook.appliesToTestCase(testCase)) {
79
- const hookName = beforeHook.name ?? 'Before';
80
- const location = getLine(beforeHook);
81
- await test.step(
82
- hookName,
83
- () => beforeHook.code.apply(world, [{
84
- gherkinDocument: feature.gherkinDocument,
85
- pickle: testCase
86
- } as ITestCaseHookParameter]),
87
- location
88
- );
89
- }
90
- }
91
- });
92
-
93
- for (const testCase of tests) {
94
- const tag = [...new Set(testCase.tags.map((tag: { name: string }) => tag.name))];
95
- const annotation = [
96
- { type: 'name', description: testCase.name },
97
- { type: 'uri', description: testCase.uri },
98
- { type: 'testId', description: testCase.id },
99
- { type: 'tags', description: JSON.stringify(tag) }
100
- ];
101
- test(testCase.name, { tag, annotation }, async () => {
102
- const world = worlds.get(testCase.id);
103
- const result: { status: string, error?: Error } = { status: 'passed' };
104
- for (const pickleStep of testCase.steps) {
105
- if (result.status !== 'passed') {
106
- break;
107
- }
108
- const steps = supportCodeLibrary.stepDefinitions
109
- .filter(stepDefinition => stepDefinition.matchesStepName(pickleStep.text));
110
- if (steps.length === 0) throw new Error(`Step '${pickleStep.text}' is not defined`);
111
- if (steps.length > 1) throw new Error(`Step '${pickleStep.text}' matches multiple step definitions`);
112
- const [ step ] = steps;
113
- const location = getLine(step);
114
- await test.step(pickleStep.text, async () => {
115
- for (const beforeStep of supportCodeLibrary.beforeTestStepHookDefinitions) {
116
- if (beforeStep.appliesToTestCase(testCase)) {
117
- const location = getLine(beforeStep);
118
- await test.step(
119
- 'Before Step',
120
- () => beforeStep.code.apply(world, [{
121
- gherkinDocument: feature.gherkinDocument,
122
- pickle: testCase,
123
- pickleStep
124
- }]),
125
- location
126
- );
127
- }
128
- }
129
- const { parameters } = await step.getInvocationParameters({
130
- step: {
131
- text: pickleStep.text,
132
- argument: pickleStep.argument
133
- },
134
- world
135
- } as any);
136
- try {
137
- await step.code.apply(world, parameters);
138
- } catch (err: any) {
139
- result.status = 'failed';
140
- result.error = err;
141
- throw err;
142
- } finally {
143
- for (const afterStep of supportCodeLibrary.afterTestStepHookDefinitions) {
144
- if (afterStep.appliesToTestCase(testCase)) {
145
- const location = getLine(afterStep);
146
- await test.step(
147
- 'After Step',
148
- () => afterStep.code.apply(world, [{
149
- gherkinDocument: feature.gherkinDocument,
150
- testCaseStartedId: '0',
151
- testStepId: '0',
152
- pickle: testCase,
153
- pickleStep,
154
- result: {
155
- duration: 0 as any,
156
- message: result.error?.message,
157
- status: result.status.toUpperCase(),
158
- exception: result.error
159
- }
160
- } as ITestStepHookParameter]),
161
- location
162
- );
163
- }
164
- }
165
- }
166
- }, location);
167
- }
168
- })
169
- }
170
-
171
- test.afterEach('After Hooks', async () => {
172
- const testInfo = test.info();
173
- const testId = getTestId(testInfo);
174
- const world = worlds.get(testId);
175
- const testCase = tests.find(test => test.id === testId)!;
176
- for (const afterHook of supportCodeLibrary.afterTestCaseHookDefinitions) {
177
- if (afterHook.appliesToTestCase(testCase)) {
178
- const hookName = afterHook.name ?? 'After';
179
- const location = getLine(afterHook);
180
- await test.step(
181
- hookName,
182
- () => afterHook.code.apply(world, [{
183
- gherkinDocument: feature.gherkinDocument,
184
- testCaseStartedId: '0',
185
- pickle: testCase,
186
- result: getResult(testInfo)
187
- } as ITestCaseHookParameter]),
188
- location
189
- );
190
- }
191
- }
192
- });
193
-
194
- test.afterEach('World', async () => {
195
- const testId = getTestId(test.info());
196
- worlds.delete(testId);
197
- });
198
-
199
- });
200
- }
201
-
202
- test.afterAll(async () => {
203
- for (const afterAllHook of supportCodeLibrary.afterTestRunHookDefinitions) {
204
- const location = getLine(afterAllHook);
205
- await test.step(
206
- 'After All',
207
- () => afterAllHook.code.apply({}),
208
- location
209
- )
210
- }
211
- });
@@ -1,25 +0,0 @@
1
- import { resolve } from 'node:path';
2
-
3
- type CucumberConfig = {
4
- config: string,
5
- profile?: string,
6
- adapter?: string
7
- }
8
-
9
- /**
10
- * Define cucumber config in playwright config
11
- * @param {CucumberConfig} config
12
- * @example
13
- * export default defineConfig({
14
- * testDir: defineCucumber({
15
- * config: 'cucumber.ts',
16
- * profile: 'chrome', // optional
17
- * adapter: 'path/to/adapter' // optional
18
- * }),
19
- * })
20
- */
21
- export function defineCucumber(config: CucumberConfig): string {
22
- process.env.CONFIG = config.config;
23
- process.env.PROFILE = config.profile ?? 'default';
24
- return config.adapter ?? resolve('./node_modules/@qavajs/playwright-runner-adapter/adapter');
25
- }