@qavajs/cypress-runner-adapter 1.3.0 → 1.4.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 +15 -0
- package/adapter/make_mocha_tests_describe.js +26 -7
- package/adapter/make_mocha_tests_it.js +29 -6
- package/index.d.ts +1 -0
- package/package.json +5 -5
- package/supportCodeLibrary/index.js +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,21 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
|
|
|
14
14
|
|
|
15
15
|
:microscope: - experimental
|
|
16
16
|
|
|
17
|
+
## [1.4.1]
|
|
18
|
+
- :beetle: fixed `result` property in `After` and `AfterStep` hooks
|
|
19
|
+
- :rocket: added workaround to complete `AfterStep` hook in case of step fail
|
|
20
|
+
|
|
21
|
+
## [1.4.0]
|
|
22
|
+
- :rocket: added `Template` utility function
|
|
23
|
+
```typescript
|
|
24
|
+
import { When, Template } from '@qavajs/playwright-runner-adapter';
|
|
25
|
+
|
|
26
|
+
When('I click {string} and verify {string}', Template((locator, expected) => `
|
|
27
|
+
I click '${locator}'
|
|
28
|
+
I expect '${locator} > Value' to equal '${expected}'
|
|
29
|
+
`));
|
|
30
|
+
```
|
|
31
|
+
|
|
17
32
|
## [1.3.0]
|
|
18
33
|
- :rocket: added tags support
|
|
19
34
|
- :rocket: added alternative 'it mode' to translate gherkin tests to mocha `it` instead of `describe`
|
|
@@ -46,8 +46,20 @@ module.exports = function makeMochaTest(tests) {
|
|
|
46
46
|
const world = new supportCodeLibrary.World();
|
|
47
47
|
world.executeStep = executeStepByText;
|
|
48
48
|
let skip = false;
|
|
49
|
-
let
|
|
49
|
+
let status = 'passed';
|
|
50
|
+
let duration = 0;
|
|
51
|
+
let exception;
|
|
52
|
+
let message;
|
|
50
53
|
afterEach(function () {
|
|
54
|
+
if (this.currentTest.state !== 'passed') {
|
|
55
|
+
skip = true;
|
|
56
|
+
}
|
|
57
|
+
duration += this.currentTest.duration;
|
|
58
|
+
if (this.currentTest.state === 'failed') {
|
|
59
|
+
status = this.currentTest.state;
|
|
60
|
+
exception = this.currentTest.err;
|
|
61
|
+
message = this.currentTest.err?.message;
|
|
62
|
+
}
|
|
51
63
|
if (this.step) {
|
|
52
64
|
for (const afterStep of supportCodeLibrary.afterTestStepHookDefinitions) {
|
|
53
65
|
if (afterStep.appliesToTestCase(this.step)) {
|
|
@@ -55,15 +67,16 @@ module.exports = function makeMochaTest(tests) {
|
|
|
55
67
|
pickle: test,
|
|
56
68
|
pickleStep: this.step,
|
|
57
69
|
gherkinDocument: tests,
|
|
58
|
-
result:
|
|
70
|
+
result: {
|
|
71
|
+
duration,
|
|
72
|
+
status,
|
|
73
|
+
exception,
|
|
74
|
+
message
|
|
75
|
+
}
|
|
59
76
|
}]);
|
|
60
77
|
}
|
|
61
78
|
}
|
|
62
79
|
}
|
|
63
|
-
if (this.currentTest.state !== 'passed') {
|
|
64
|
-
skip = true;
|
|
65
|
-
}
|
|
66
|
-
result = this.currentTest.state;
|
|
67
80
|
});
|
|
68
81
|
for (const beforeTest of supportCodeLibrary.beforeTestCaseHookDefinitions) {
|
|
69
82
|
if (beforeTest.appliesToTestCase(test)) {
|
|
@@ -96,9 +109,15 @@ module.exports = function makeMochaTest(tests) {
|
|
|
96
109
|
for (const afterTest of supportCodeLibrary.afterTestCaseHookDefinitions) {
|
|
97
110
|
if (afterTest.appliesToTestCase(test)) {
|
|
98
111
|
it(afterTest.name, function () {
|
|
112
|
+
this.step = null;
|
|
99
113
|
afterTest.code.apply(world, [{
|
|
100
114
|
pickle: test,
|
|
101
|
-
result
|
|
115
|
+
result: {
|
|
116
|
+
duration,
|
|
117
|
+
status,
|
|
118
|
+
exception,
|
|
119
|
+
message
|
|
120
|
+
},
|
|
102
121
|
gherkinDocument: tests,
|
|
103
122
|
willBeRetried: false
|
|
104
123
|
}]);
|
|
@@ -12,13 +12,22 @@ module.exports = function makeMochaTest(tests) {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
function getResult(currentTest) {
|
|
16
|
+
return {
|
|
17
|
+
duration: currentTest.duration,
|
|
18
|
+
message: currentTest.err?.message,
|
|
19
|
+
status: currentTest.state,
|
|
20
|
+
exception: currentTest.err
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
15
24
|
function executeStepByText(text, argument) {
|
|
16
25
|
const steps = supportCodeLibrary.stepDefinitions
|
|
17
26
|
.filter(stepDefinition => stepDefinition.matchesStepName(text));
|
|
18
27
|
if (steps.length === 0) throw new Error(`Step '${text}' is not defined`);
|
|
19
28
|
if (steps.length > 1) throw new Error(`Step '${text}' matches multiple step definitions`);
|
|
20
|
-
const [
|
|
21
|
-
const {
|
|
29
|
+
const [step] = steps;
|
|
30
|
+
const {parameters} = step.getInvocationParameters({
|
|
22
31
|
step: {text, argument},
|
|
23
32
|
world: this
|
|
24
33
|
});
|
|
@@ -75,15 +84,29 @@ module.exports = function makeMochaTest(tests) {
|
|
|
75
84
|
}
|
|
76
85
|
});
|
|
77
86
|
|
|
78
|
-
afterEach(
|
|
87
|
+
afterEach(function () {
|
|
79
88
|
const test = findTest(tests, this.currentTest.title);
|
|
80
89
|
const world = this.world;
|
|
90
|
+
const result = getResult(this.currentTest);
|
|
91
|
+
// corner case to complete AfterStep if test is failed
|
|
92
|
+
if (result.status === 'failed' && this.step) {
|
|
93
|
+
for (const afterStep of supportCodeLibrary.afterTestStepHookDefinitions) {
|
|
94
|
+
if (afterStep.appliesToTestCase(this.step)) {
|
|
95
|
+
afterStep.code.apply(world, [{
|
|
96
|
+
pickle: test,
|
|
97
|
+
pickleStep: this.step,
|
|
98
|
+
gherkinDocument: tests,
|
|
99
|
+
result
|
|
100
|
+
}]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
81
104
|
for (const afterTest of supportCodeLibrary.afterTestCaseHookDefinitions) {
|
|
82
105
|
if (afterTest.appliesToTestCase(test)) {
|
|
83
106
|
runStep(afterTest.name, function () {
|
|
84
107
|
afterTest.code.apply(world, [{
|
|
85
108
|
pickle: test,
|
|
86
|
-
result
|
|
109
|
+
result,
|
|
87
110
|
gherkinDocument: tests,
|
|
88
111
|
willBeRetried: false
|
|
89
112
|
}]);
|
|
@@ -99,7 +122,7 @@ module.exports = function makeMochaTest(tests) {
|
|
|
99
122
|
const stepName = keyword(step) + ': ' + step.text;
|
|
100
123
|
runStep(stepName, function () {
|
|
101
124
|
this.step = step;
|
|
102
|
-
|
|
125
|
+
const result = { status: 'passed', duration: 0 };
|
|
103
126
|
for (const beforeStep of supportCodeLibrary.beforeTestStepHookDefinitions) {
|
|
104
127
|
if (beforeStep.appliesToTestCase(step)) {
|
|
105
128
|
beforeStep.code.apply(world, [{
|
|
@@ -116,7 +139,7 @@ module.exports = function makeMochaTest(tests) {
|
|
|
116
139
|
pickle: test,
|
|
117
140
|
pickleStep: this.step,
|
|
118
141
|
gherkinDocument: tests,
|
|
119
|
-
result
|
|
142
|
+
result
|
|
120
143
|
}]);
|
|
121
144
|
}
|
|
122
145
|
}
|
package/index.d.ts
CHANGED
|
@@ -29,3 +29,4 @@ export function BeforeAll(fn: Function): void;
|
|
|
29
29
|
export function AfterAll(fn: Function): void;
|
|
30
30
|
export function setWorldConstructor(world: IWorld): void;
|
|
31
31
|
export function defineParameterType(option: ParameterTypeOption): void;
|
|
32
|
+
export function Template(template: (...args: any[]) => string): () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qavajs/cypress-runner-adapter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"debug": "cypress open --config-file test/cypress.config.js",
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"bugs": {
|
|
21
21
|
"url": "https://github.com/qavajs/cypress-runner-adapter/issues"
|
|
22
22
|
},
|
|
23
|
-
"homepage": "https://github.
|
|
23
|
+
"homepage": "https://qavajs.github.io/docs/intro",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@cucumber/cucumber-expressions": "^18.0.1",
|
|
26
|
-
"@cucumber/gherkin": "^
|
|
27
|
-
"@cucumber/tag-expressions": "^
|
|
26
|
+
"@cucumber/gherkin": "^36.0.0",
|
|
27
|
+
"@cucumber/tag-expressions": "^8.0.0",
|
|
28
28
|
"@cypress/webpack-preprocessor": "^7.0.1",
|
|
29
29
|
"fs-extra": "^11.3.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"cypress": "^15.
|
|
32
|
+
"cypress": "^15.5.0"
|
|
33
33
|
},
|
|
34
34
|
"keywords": [
|
|
35
35
|
"cypress",
|
|
@@ -103,4 +103,28 @@ export function defineParameterType(options) {
|
|
|
103
103
|
supportCodeLibrary.parameterTypeRegistry.defineSourcedParameterType(parameterType, {})
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Define template step
|
|
108
|
+
* @param {() => string} scenario - multiline string with steps
|
|
109
|
+
* @example
|
|
110
|
+
* When('I click {string} and verify {string}', Template((locator, expected) => `
|
|
111
|
+
* I click '${locator}'
|
|
112
|
+
* I expect '${locator} > Value' to equal '${expected}'
|
|
113
|
+
* `));
|
|
114
|
+
*/
|
|
115
|
+
export function Template(scenario) {
|
|
116
|
+
return new Proxy(scenario, {
|
|
117
|
+
apply: function (template, world, args) {
|
|
118
|
+
const scenario = template(...args) ;
|
|
119
|
+
const steps = scenario
|
|
120
|
+
.split('\n')
|
|
121
|
+
.map(step => step.trim())
|
|
122
|
+
.filter(Boolean);
|
|
123
|
+
for (const step of steps) {
|
|
124
|
+
world.executeStep(step);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
106
130
|
|