@qavajs/playwright-runner-adapter 1.10.0 → 2.0.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 +28 -0
- package/README.md +9 -9
- package/adapter/PlaywrightWorld.d.ts +1 -0
- package/adapter/PlaywrightWorld.js +1 -0
- package/adapter/PlaywrightWorld.js.map +1 -1
- package/adapter/cucumberAdapter.d.ts +4 -0
- package/adapter/cucumberAdapter.js +275 -0
- package/adapter/cucumberAdapter.js.map +1 -0
- package/adapter/index.d.ts +1 -1
- package/adapter/index.js +1 -1
- package/adapter/index.js.map +1 -1
- package/adapter/loader.d.ts +2 -1
- package/adapter/loader.js +6 -8
- package/adapter/loader.js.map +1 -1
- package/package.json +7 -7
- package/src/PlaywrightWorld.ts +1 -0
- package/src/cucumberAdapter.ts +380 -0
- package/src/index.ts +1 -1
- package/src/loader.ts +8 -10
- package/adapter/cucumber.spec.d.ts +0 -1
- package/adapter/cucumber.spec.js +0 -181
- package/adapter/cucumber.spec.js.map +0 -1
- package/adapter/defineCucumber.d.ts +0 -19
- package/adapter/defineCucumber.js +0 -22
- package/adapter/defineCucumber.js.map +0 -1
- package/src/cucumber.spec.ts +0 -219
- package/src/defineCucumber.ts +0 -25
package/src/cucumber.spec.ts
DELETED
|
@@ -1,219 +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
|
-
function stepName(pickleStep: any) {
|
|
41
|
-
let step = pickleStep.text;
|
|
42
|
-
if (pickleStep.argument) {
|
|
43
|
-
step += pickleStep.argument.docString ? ' [MultiLine]' : ' [DataTable]';
|
|
44
|
-
}
|
|
45
|
-
return step;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const fixture = new supportCodeLibrary.World({});
|
|
49
|
-
const test: TestType<any, any> = fixture.test;
|
|
50
|
-
|
|
51
|
-
test.beforeAll(async () => {
|
|
52
|
-
for (const beforeAllHook of supportCodeLibrary.beforeTestRunHookDefinitions) {
|
|
53
|
-
const location = getLine(beforeAllHook);
|
|
54
|
-
await test.step(
|
|
55
|
-
'Before All',
|
|
56
|
-
() => beforeAllHook.code.apply({}),
|
|
57
|
-
location
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const worlds = new Map();
|
|
63
|
-
|
|
64
|
-
for (const feature of features) {
|
|
65
|
-
const tests = feature.tests;
|
|
66
|
-
test.describe(feature.feature as string, async () => {
|
|
67
|
-
|
|
68
|
-
const worldFactory = (fixtures: any) => {
|
|
69
|
-
const world = new supportCodeLibrary.World({
|
|
70
|
-
log,
|
|
71
|
-
attach,
|
|
72
|
-
supportCodeLibrary
|
|
73
|
-
});
|
|
74
|
-
world.init(fixtures);
|
|
75
|
-
worlds.set(getTestId(test.info()), world);
|
|
76
|
-
};
|
|
77
|
-
worldFactory.toString = () => { return fixture.init.toString() }
|
|
78
|
-
|
|
79
|
-
test.beforeEach('World', worldFactory);
|
|
80
|
-
|
|
81
|
-
test.beforeEach('Before Hooks', async () => {
|
|
82
|
-
const testId = getTestId(test.info());
|
|
83
|
-
const world = worlds.get(testId);
|
|
84
|
-
const testCase = tests.find(test => test.id === testId)!;
|
|
85
|
-
for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
|
|
86
|
-
if (beforeHook.appliesToTestCase(testCase)) {
|
|
87
|
-
const hookName = beforeHook.name ?? 'Before';
|
|
88
|
-
const location = getLine(beforeHook);
|
|
89
|
-
await test.step(
|
|
90
|
-
hookName,
|
|
91
|
-
() => beforeHook.code.apply(world, [{
|
|
92
|
-
gherkinDocument: feature.gherkinDocument,
|
|
93
|
-
pickle: testCase
|
|
94
|
-
} as ITestCaseHookParameter]),
|
|
95
|
-
location
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
for (const testCase of tests) {
|
|
102
|
-
const tag = [...new Set(testCase.tags.map((tag: { name: string }) => tag.name))];
|
|
103
|
-
const annotation = [
|
|
104
|
-
{ type: 'name', description: testCase.name },
|
|
105
|
-
{ type: 'uri', description: testCase.uri },
|
|
106
|
-
{ type: 'testId', description: testCase.id },
|
|
107
|
-
{ type: 'tags', description: JSON.stringify(tag) }
|
|
108
|
-
];
|
|
109
|
-
test(testCase.name, { tag, annotation }, async () => {
|
|
110
|
-
const world = worlds.get(testCase.id);
|
|
111
|
-
const result: { status: string, error?: Error } = { status: 'passed' };
|
|
112
|
-
for (const pickleStep of testCase.steps) {
|
|
113
|
-
if (result.status !== 'passed') {
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
const steps = supportCodeLibrary.stepDefinitions
|
|
117
|
-
.filter(stepDefinition => stepDefinition.matchesStepName(pickleStep.text));
|
|
118
|
-
if (steps.length === 0) throw new Error(`Step '${pickleStep.text}' is not defined`);
|
|
119
|
-
if (steps.length > 1) throw new Error(`Step '${pickleStep.text}' matches multiple step definitions`);
|
|
120
|
-
const [ step ] = steps;
|
|
121
|
-
const location = getLine(step);
|
|
122
|
-
await test.step(stepName(pickleStep), async () => {
|
|
123
|
-
for (const beforeStep of supportCodeLibrary.beforeTestStepHookDefinitions) {
|
|
124
|
-
if (beforeStep.appliesToTestCase(testCase)) {
|
|
125
|
-
const location = getLine(beforeStep);
|
|
126
|
-
await test.step(
|
|
127
|
-
'Before Step',
|
|
128
|
-
() => beforeStep.code.apply(world, [{
|
|
129
|
-
gherkinDocument: feature.gherkinDocument,
|
|
130
|
-
pickle: testCase,
|
|
131
|
-
pickleStep
|
|
132
|
-
}]),
|
|
133
|
-
location
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
const { parameters } = await step.getInvocationParameters({
|
|
138
|
-
step: {
|
|
139
|
-
text: pickleStep.text,
|
|
140
|
-
argument: pickleStep.argument
|
|
141
|
-
},
|
|
142
|
-
world
|
|
143
|
-
} as any);
|
|
144
|
-
try {
|
|
145
|
-
await step.code.apply(world, parameters);
|
|
146
|
-
} catch (err: any) {
|
|
147
|
-
result.status = 'failed';
|
|
148
|
-
result.error = err;
|
|
149
|
-
throw err;
|
|
150
|
-
} finally {
|
|
151
|
-
for (const afterStep of supportCodeLibrary.afterTestStepHookDefinitions) {
|
|
152
|
-
if (afterStep.appliesToTestCase(testCase)) {
|
|
153
|
-
const location = getLine(afterStep);
|
|
154
|
-
await test.step(
|
|
155
|
-
'After Step',
|
|
156
|
-
() => afterStep.code.apply(world, [{
|
|
157
|
-
gherkinDocument: feature.gherkinDocument,
|
|
158
|
-
testCaseStartedId: '0',
|
|
159
|
-
testStepId: '0',
|
|
160
|
-
pickle: testCase,
|
|
161
|
-
pickleStep,
|
|
162
|
-
result: {
|
|
163
|
-
duration: 0 as any,
|
|
164
|
-
message: result.error?.message,
|
|
165
|
-
status: result.status.toUpperCase(),
|
|
166
|
-
exception: result.error
|
|
167
|
-
}
|
|
168
|
-
} as ITestStepHookParameter]),
|
|
169
|
-
location
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}, location);
|
|
175
|
-
}
|
|
176
|
-
})
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
test.afterEach('After Hooks', async () => {
|
|
180
|
-
const testInfo = test.info();
|
|
181
|
-
const testId = getTestId(testInfo);
|
|
182
|
-
const world = worlds.get(testId);
|
|
183
|
-
const testCase = tests.find(test => test.id === testId)!;
|
|
184
|
-
for (const afterHook of supportCodeLibrary.afterTestCaseHookDefinitions) {
|
|
185
|
-
if (afterHook.appliesToTestCase(testCase)) {
|
|
186
|
-
const hookName = afterHook.name ?? 'After';
|
|
187
|
-
const location = getLine(afterHook);
|
|
188
|
-
await test.step(
|
|
189
|
-
hookName,
|
|
190
|
-
() => afterHook.code.apply(world, [{
|
|
191
|
-
gherkinDocument: feature.gherkinDocument,
|
|
192
|
-
testCaseStartedId: '0',
|
|
193
|
-
pickle: testCase,
|
|
194
|
-
result: getResult(testInfo)
|
|
195
|
-
} as ITestCaseHookParameter]),
|
|
196
|
-
location
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test.afterEach('World', async () => {
|
|
203
|
-
const testId = getTestId(test.info());
|
|
204
|
-
worlds.delete(testId);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
test.afterAll(async () => {
|
|
211
|
-
for (const afterAllHook of supportCodeLibrary.afterTestRunHookDefinitions) {
|
|
212
|
-
const location = getLine(afterAllHook);
|
|
213
|
-
await test.step(
|
|
214
|
-
'After All',
|
|
215
|
-
() => afterAllHook.code.apply({}),
|
|
216
|
-
location
|
|
217
|
-
)
|
|
218
|
-
}
|
|
219
|
-
});
|
package/src/defineCucumber.ts
DELETED
|
@@ -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
|
-
}
|