@qavajs/cypress-runner-adapter 1.4.2 → 1.6.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
@@ -14,6 +14,15 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
14
14
 
15
15
  :microscope: - experimental
16
16
 
17
+
18
+ ## [1.6.0]
19
+ - :rocket: updated logs for Gherkin steps
20
+ - :rocket: improved multi line and data table step logging
21
+
22
+ ## [1.5.0]
23
+ - :rocket: added `world.log` method
24
+ - :rocket: updated test.body to render corresponding step code
25
+
17
26
  ## [1.4.2]
18
27
  - :pencil: updated to cypress 15.7.0
19
28
  - :pencil: updated to gherkin to 37.0.0
@@ -1,4 +1,8 @@
1
1
  module.exports = function makeMochaTest(tests) {
2
+ function log(data) {
3
+ cy.log(data);
4
+ }
5
+
2
6
  function keyword(step) {
3
7
  switch (step.type) {
4
8
  case 'Context': return 'Given';
@@ -8,12 +12,25 @@ module.exports = function makeMochaTest(tests) {
8
12
  }
9
13
  }
10
14
 
11
- function executeStepByText(text, argument) {
15
+ function stepName(pickleStep) {
16
+ let step = pickleStep.text;
17
+ if (pickleStep.argument) {
18
+ step += pickleStep.argument.docString ? ' [MultiLine]' : ' [DataTable]';
19
+ }
20
+ return step;
21
+ }
22
+
23
+ function findStepDefinition(text) {
12
24
  const steps = supportCodeLibrary.stepDefinitions
13
25
  .filter(stepDefinition => stepDefinition.matchesStepName(text));
14
26
  if (steps.length === 0) throw new Error(`Step '${text}' is not defined`);
15
27
  if (steps.length > 1) throw new Error(`Step '${text}' matches multiple step definitions`);
16
28
  const [step] = steps;
29
+ return step;
30
+ }
31
+
32
+ function executeStepByText(text, argument) {
33
+ const step = findStepDefinition(text);
17
34
  const { parameters } = step.getInvocationParameters({
18
35
  step: { text, argument },
19
36
  world: this
@@ -35,6 +52,7 @@ module.exports = function makeMochaTest(tests) {
35
52
  describe('Before All', function () {
36
53
  for (const beforeRun of supportCodeLibrary.beforeTestRunHookDefinitions) {
37
54
  it('Before All', function () {
55
+ this.test.body = beforeRun.code.toString();
38
56
  beforeRun.code.apply();
39
57
  });
40
58
  }
@@ -43,7 +61,11 @@ module.exports = function makeMochaTest(tests) {
43
61
 
44
62
  for (const test of tests) {
45
63
  describe('Scenario: ' + test.name, { testIsolation: false }, function () {
46
- const world = new supportCodeLibrary.World();
64
+ const world = new supportCodeLibrary.World({
65
+ log,
66
+ attach: log,
67
+ link: log
68
+ });
47
69
  world.executeStep = executeStepByText;
48
70
  let skip = false;
49
71
  let status = 'passed';
@@ -81,6 +103,8 @@ module.exports = function makeMochaTest(tests) {
81
103
  for (const beforeTest of supportCodeLibrary.beforeTestCaseHookDefinitions) {
82
104
  if (beforeTest.appliesToTestCase(test)) {
83
105
  it(beforeTest.name, function () {
106
+ this.test.body = beforeTest.code.toString();
107
+ world.test = this;
84
108
  if (skip) return this.skip();
85
109
  beforeTest.code.apply(world, [{
86
110
  pickle: test,
@@ -91,7 +115,8 @@ module.exports = function makeMochaTest(tests) {
91
115
  }
92
116
  }
93
117
  for (const step of test.steps) {
94
- it(keyword(step) + ': ' + step.text, function () {
118
+ it(`${keyword(step)} ${stepName(step)}`, function () {
119
+ this.test.body = findStepDefinition(step.text).code.toString();
95
120
  this.step = step;
96
121
  if (skip) return this.skip();
97
122
  for (const beforeStep of supportCodeLibrary.beforeTestStepHookDefinitions) {
@@ -109,6 +134,7 @@ module.exports = function makeMochaTest(tests) {
109
134
  for (const afterTest of supportCodeLibrary.afterTestCaseHookDefinitions) {
110
135
  if (afterTest.appliesToTestCase(test)) {
111
136
  it(afterTest.name, function () {
137
+ this.test.body = afterTest.code.toString();
112
138
  this.step = null;
113
139
  afterTest.code.apply(world, [{
114
140
  pickle: test,
@@ -130,6 +156,7 @@ module.exports = function makeMochaTest(tests) {
130
156
  describe('After All', function () {
131
157
  for (const afterRun of supportCodeLibrary.afterTestRunHookDefinitions) {
132
158
  it('After All', function () {
159
+ this.test.body = afterRun.code.toString();
133
160
  afterRun.code.apply();
134
161
  });
135
162
  }
@@ -1,4 +1,8 @@
1
1
  module.exports = function makeMochaTest(tests) {
2
+ function log(data) {
3
+ cy.log(data);
4
+ }
5
+
2
6
  function keyword(step) {
3
7
  switch (step.type) {
4
8
  case 'Context':
@@ -12,6 +16,14 @@ module.exports = function makeMochaTest(tests) {
12
16
  }
13
17
  }
14
18
 
19
+ function stepNameText(pickleStep) {
20
+ let step = pickleStep.text;
21
+ if (pickleStep.argument) {
22
+ step += pickleStep.argument.docString ? ' [MultiLine]' : ' [DataTable]';
23
+ }
24
+ return step;
25
+ }
26
+
15
27
  function getResult(currentTest) {
16
28
  return {
17
29
  duration: currentTest.duration,
@@ -60,6 +72,10 @@ module.exports = function makeMochaTest(tests) {
60
72
  return tests.find(test => test.name === testName);
61
73
  }
62
74
 
75
+ function renderGherkinTest(steps) {
76
+ return steps.map(step => `${keyword(step)} ${step.text}`).join('\n');
77
+ }
78
+
63
79
  if (supportCodeLibrary.beforeTestRunHookDefinitions.length > 0) {
64
80
  before(function () {
65
81
  for (const beforeRun of supportCodeLibrary.beforeTestRunHookDefinitions) {
@@ -70,7 +86,12 @@ module.exports = function makeMochaTest(tests) {
70
86
 
71
87
  beforeEach(function () {
72
88
  const test = findTest(tests, this.currentTest.title);
73
- const world = this.world = new supportCodeLibrary.World();
89
+ this.currentTest.body = renderGherkinTest(test.steps);
90
+ const world = this.world = new supportCodeLibrary.World({
91
+ log,
92
+ attach: log,
93
+ link: log
94
+ });
74
95
  for (const beforeTest of supportCodeLibrary.beforeTestCaseHookDefinitions) {
75
96
  if (beforeTest.appliesToTestCase(test)) {
76
97
  runStep(beforeTest.name, function () {
@@ -119,10 +140,10 @@ module.exports = function makeMochaTest(tests) {
119
140
  it('Scenario: ' + test.name, function () {
120
141
  const world = this.world;
121
142
  for (const step of test.steps) {
122
- const stepName = keyword(step) + ': ' + step.text;
143
+ const stepName = `${keyword(step)} ${stepNameText(step)}`;
123
144
  runStep(stepName, function () {
124
145
  this.step = step;
125
- const result = { status: 'passed', duration: 0 };
146
+ const result = {status: 'passed', duration: 0};
126
147
  for (const beforeStep of supportCodeLibrary.beforeTestStepHookDefinitions) {
127
148
  if (beforeStep.appliesToTestCase(step)) {
128
149
  beforeStep.code.apply(world, [{
package/index.d.ts CHANGED
@@ -29,4 +29,11 @@ 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;
32
+ export function Template(template: (...args: any[]) => string): () => void;
33
+ export class World {
34
+ constructor(options: {
35
+ log: (...args: any) => void;
36
+ attach: (...args: any) => void;
37
+ link: (...args: any) => void;
38
+ });
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qavajs/cypress-runner-adapter",
3
- "version": "1.4.2",
3
+ "version": "1.6.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "debug": "cypress open --config-file test/cypress.config.js",
@@ -23,13 +23,14 @@
23
23
  "homepage": "https://qavajs.github.io/docs/intro",
24
24
  "dependencies": {
25
25
  "@cucumber/cucumber-expressions": "^18.0.1",
26
- "@cucumber/gherkin": "^37.0.0",
27
- "@cucumber/tag-expressions": "^8.0.0",
26
+ "@cucumber/gherkin": "^37.0.1",
27
+ "@cucumber/tag-expressions": "^8.1.0",
28
28
  "@cypress/webpack-preprocessor": "^7.0.2",
29
- "fs-extra": "^11.3.2"
29
+ "fs-extra": "^11.3.3"
30
30
  },
31
31
  "devDependencies": {
32
- "cypress": "^15.7.0"
32
+ "cypress": "^15.9.0",
33
+ "mochawesome": "^7.1.4"
33
34
  },
34
35
  "keywords": [
35
36
  "cypress",
@@ -5,7 +5,14 @@ import TestCaseHookDefinition from './test_case_hook_definition';
5
5
  import TestStepHookDefinition from './test_step_hook_definition';
6
6
  import { buildParameterType } from './build_parameter_type';
7
7
  import TestRunHookDefinition from './test_run_hook_definition';
8
- class World {}
8
+
9
+ export class World {
10
+ constructor(options) {
11
+ this.log = options.log;
12
+ this.attach = options.attach;
13
+ this.link = options.link;
14
+ }
15
+ }
9
16
 
10
17
  const supportCodeLibrary = {
11
18
  stepDefinitions: [],