@qavajs/cypress-runner-adapter 1.4.1 → 1.5.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,14 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
14
14
 
15
15
  :microscope: - experimental
16
16
 
17
+ ## [1.5.0]
18
+ - :rocket: added `world.log` method
19
+ - :rocket: updated test.body to render corresponding step code
20
+
21
+ ## [1.4.2]
22
+ - :pencil: updated to cypress 15.7.0
23
+ - :pencil: updated to gherkin to 37.0.0
24
+
17
25
  ## [1.4.1]
18
26
  - :beetle: fixed `result` property in `After` and `AfterStep` hooks
19
27
  - :rocket: added workaround to complete `AfterStep` hook in case of step fail
@@ -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,17 @@ module.exports = function makeMochaTest(tests) {
8
12
  }
9
13
  }
10
14
 
11
- function executeStepByText(text, argument) {
15
+ function findStepDefinition(text) {
12
16
  const steps = supportCodeLibrary.stepDefinitions
13
17
  .filter(stepDefinition => stepDefinition.matchesStepName(text));
14
18
  if (steps.length === 0) throw new Error(`Step '${text}' is not defined`);
15
19
  if (steps.length > 1) throw new Error(`Step '${text}' matches multiple step definitions`);
16
20
  const [step] = steps;
21
+ return step;
22
+ }
23
+
24
+ function executeStepByText(text, argument) {
25
+ const step = findStepDefinition(text);
17
26
  const { parameters } = step.getInvocationParameters({
18
27
  step: { text, argument },
19
28
  world: this
@@ -35,6 +44,7 @@ module.exports = function makeMochaTest(tests) {
35
44
  describe('Before All', function () {
36
45
  for (const beforeRun of supportCodeLibrary.beforeTestRunHookDefinitions) {
37
46
  it('Before All', function () {
47
+ this.test.body = beforeRun.code.toString();
38
48
  beforeRun.code.apply();
39
49
  });
40
50
  }
@@ -43,7 +53,11 @@ module.exports = function makeMochaTest(tests) {
43
53
 
44
54
  for (const test of tests) {
45
55
  describe('Scenario: ' + test.name, { testIsolation: false }, function () {
46
- const world = new supportCodeLibrary.World();
56
+ const world = new supportCodeLibrary.World({
57
+ log,
58
+ attach: log,
59
+ link: log
60
+ });
47
61
  world.executeStep = executeStepByText;
48
62
  let skip = false;
49
63
  let status = 'passed';
@@ -81,6 +95,8 @@ module.exports = function makeMochaTest(tests) {
81
95
  for (const beforeTest of supportCodeLibrary.beforeTestCaseHookDefinitions) {
82
96
  if (beforeTest.appliesToTestCase(test)) {
83
97
  it(beforeTest.name, function () {
98
+ this.test.body = beforeTest.code.toString();
99
+ world.test = this;
84
100
  if (skip) return this.skip();
85
101
  beforeTest.code.apply(world, [{
86
102
  pickle: test,
@@ -92,6 +108,7 @@ module.exports = function makeMochaTest(tests) {
92
108
  }
93
109
  for (const step of test.steps) {
94
110
  it(keyword(step) + ': ' + step.text, function () {
111
+ this.test.body = findStepDefinition(step.text).code.toString();
95
112
  this.step = step;
96
113
  if (skip) return this.skip();
97
114
  for (const beforeStep of supportCodeLibrary.beforeTestStepHookDefinitions) {
@@ -109,6 +126,7 @@ module.exports = function makeMochaTest(tests) {
109
126
  for (const afterTest of supportCodeLibrary.afterTestCaseHookDefinitions) {
110
127
  if (afterTest.appliesToTestCase(test)) {
111
128
  it(afterTest.name, function () {
129
+ this.test.body = afterTest.code.toString();
112
130
  this.step = null;
113
131
  afterTest.code.apply(world, [{
114
132
  pickle: test,
@@ -130,6 +148,7 @@ module.exports = function makeMochaTest(tests) {
130
148
  describe('After All', function () {
131
149
  for (const afterRun of supportCodeLibrary.afterTestRunHookDefinitions) {
132
150
  it('After All', function () {
151
+ this.test.body = afterRun.code.toString();
133
152
  afterRun.code.apply();
134
153
  });
135
154
  }
@@ -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':
@@ -60,6 +64,10 @@ module.exports = function makeMochaTest(tests) {
60
64
  return tests.find(test => test.name === testName);
61
65
  }
62
66
 
67
+ function renderGherkinTest(steps) {
68
+ return steps.map(step => `${keyword(step)} ${step.text}`).join('\n');
69
+ }
70
+
63
71
  if (supportCodeLibrary.beforeTestRunHookDefinitions.length > 0) {
64
72
  before(function () {
65
73
  for (const beforeRun of supportCodeLibrary.beforeTestRunHookDefinitions) {
@@ -70,7 +78,12 @@ module.exports = function makeMochaTest(tests) {
70
78
 
71
79
  beforeEach(function () {
72
80
  const test = findTest(tests, this.currentTest.title);
73
- const world = this.world = new supportCodeLibrary.World();
81
+ this.currentTest.body = renderGherkinTest(test.steps);
82
+ const world = this.world = new supportCodeLibrary.World({
83
+ log,
84
+ attach: log,
85
+ link: log
86
+ });
74
87
  for (const beforeTest of supportCodeLibrary.beforeTestCaseHookDefinitions) {
75
88
  if (beforeTest.appliesToTestCase(test)) {
76
89
  runStep(beforeTest.name, function () {
@@ -122,7 +135,7 @@ module.exports = function makeMochaTest(tests) {
122
135
  const stepName = keyword(step) + ': ' + step.text;
123
136
  runStep(stepName, function () {
124
137
  this.step = step;
125
- const result = { status: 'passed', duration: 0 };
138
+ const result = {status: 'passed', duration: 0};
126
139
  for (const beforeStep of supportCodeLibrary.beforeTestStepHookDefinitions) {
127
140
  if (beforeStep.appliesToTestCase(step)) {
128
141
  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.1",
3
+ "version": "1.5.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": "^36.0.0",
27
- "@cucumber/tag-expressions": "^8.0.0",
28
- "@cypress/webpack-preprocessor": "^7.0.1",
26
+ "@cucumber/gherkin": "^37.0.0",
27
+ "@cucumber/tag-expressions": "^8.1.0",
28
+ "@cypress/webpack-preprocessor": "^7.0.2",
29
29
  "fs-extra": "^11.3.2"
30
30
  },
31
31
  "devDependencies": {
32
- "cypress": "^15.5.0"
32
+ "cypress": "^15.7.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: [],