Skip to content

Commit 5d9109b

Browse files
sawasawasawalgandecki
authored andcommitted
chore: Move test to another file to ensure setting the TAGS env correctly (#181)
* Move test to another file to ensure setting the TAGS env correctly * Extract test setup
1 parent 015de0f commit 5d9109b

File tree

3 files changed

+73
-65
lines changed

3 files changed

+73
-65
lines changed

lib/resolveStepDefinition.test.js

Lines changed: 20 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,7 @@
11
/* eslint-disable global-require */
22
/* global jest */
3-
const fs = require("fs");
4-
const { Parser } = require("gherkin");
3+
const { readAndParseFeatureFile } = require("./setup");
54
const { createTestsFromFeature } = require("./createTestsFromFeature");
6-
const {
7-
defineParameterType,
8-
defineStep,
9-
when,
10-
then,
11-
given,
12-
and,
13-
but
14-
} = require("./resolveStepDefinition");
15-
16-
window.defineParameterType = defineParameterType;
17-
window.when = when;
18-
window.then = then;
19-
window.given = given;
20-
window.and = and;
21-
window.but = but;
22-
window.defineStep = defineStep;
23-
window.cy = {
24-
log: jest.fn()
25-
};
26-
27-
window.Cypress = {
28-
env: jest.fn()
29-
};
30-
31-
const readAndParseFeatureFile = featureFilePath => {
32-
const spec = fs.readFileSync(featureFilePath);
33-
return new Parser().parse(spec.toString());
34-
};
355

366
describe("Scenario Outline", () => {
377
require("../cypress/support/step_definitions/scenario_outline_integer");
@@ -99,41 +69,7 @@ describe("Tags implementation", () => {
9969
);
10070
});
10171

102-
describe("Tags inheritance", () => {
103-
window.Cypress = {
104-
env: () => "@inherited-tag and @own-tag"
105-
};
106-
require("../cypress/support/step_definitions/tags_implementation_with_env_set");
107-
108-
createTestsFromFeature(
109-
readAndParseFeatureFile("./cypress/integration/TagsInheritance.feature")
110-
);
111-
});
112-
113-
// TODO we need to take a look why these do not work properly, but as long as they run correctly with cypress run we can skip for now.
114-
describe.skip("Tags with env TAGS set", () => {
115-
window.Cypress = {
116-
env: () => "@test-tag and not @ignore-tag"
117-
};
118-
require("../cypress/support/step_definitions/tags_implementation_with_env_set");
119-
120-
createTestsFromFeature(
121-
readAndParseFeatureFile(
122-
"./cypress/integration/TagsImplementationWithEnvSet.feature"
123-
)
124-
);
125-
126-
createTestsFromFeature(
127-
readAndParseFeatureFile(
128-
"./cypress/integration/TagsImplementationWithEnvSetScenarioLevel.feature"
129-
)
130-
);
131-
});
132-
13372
describe("Smart tagging", () => {
134-
window.Cypress = {
135-
env: () => ""
136-
};
13773
require("../cypress/support/step_definitions/smart_tagging");
13874

13975
createTestsFromFeature(
@@ -156,3 +92,22 @@ describe("defineStep", () => {
15692
readAndParseFeatureFile("./cypress/integration/DefineStep.feature")
15793
);
15894
});
95+
96+
describe("Tags with env TAGS set", () => {
97+
window.Cypress = {
98+
env: () => "@test-tag and not @ignore-tag"
99+
};
100+
require("../cypress/support/step_definitions/tags_implementation_with_env_set");
101+
102+
createTestsFromFeature(
103+
readAndParseFeatureFile(
104+
"./cypress/integration/TagsImplementationWithEnvSet.feature"
105+
)
106+
);
107+
108+
createTestsFromFeature(
109+
readAndParseFeatureFile(
110+
"./cypress/integration/TagsImplementationWithEnvSetScenarioLevel.feature"
111+
)
112+
);
113+
});

lib/setup.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* eslint-disable global-require */
2+
/* global jest */
3+
const fs = require("fs");
4+
const { Parser } = require("gherkin");
5+
const {
6+
defineParameterType,
7+
defineStep,
8+
when,
9+
then,
10+
given,
11+
and,
12+
but
13+
} = require("./resolveStepDefinition");
14+
15+
window.defineParameterType = defineParameterType;
16+
window.when = when;
17+
window.then = then;
18+
window.given = given;
19+
window.and = and;
20+
window.but = but;
21+
window.defineStep = defineStep;
22+
window.cy = {
23+
log: jest.fn()
24+
};
25+
26+
window.Cypress = {
27+
env: jest.fn()
28+
};
29+
30+
const readAndParseFeatureFile = featureFilePath => {
31+
const spec = fs.readFileSync(featureFilePath);
32+
return new Parser().parse(spec.toString());
33+
};
34+
35+
module.exports = {
36+
readAndParseFeatureFile
37+
};

lib/tagsInheritance.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* eslint-disable global-require */
2+
/* global jest */
3+
const { readAndParseFeatureFile } = require("./setup");
4+
const { createTestsFromFeature } = require("./createTestsFromFeature");
5+
6+
describe("Tags inheritance", () => {
7+
window.Cypress = {
8+
env: () => "@inherited-tag and @own-tag"
9+
};
10+
11+
require("../cypress/support/step_definitions/tags_implementation_with_env_set");
12+
13+
createTestsFromFeature(
14+
readAndParseFeatureFile("./cypress/integration/TagsInheritance.feature")
15+
);
16+
});

0 commit comments

Comments
 (0)