@cucumber/query 7.0.1 → 9.0.2

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.
@@ -8,60 +8,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
13
  };
41
14
  Object.defineProperty(exports, "__esModule", { value: true });
42
- require("source-map-support/register");
43
- var gherkin_1 = require("@cucumber/gherkin");
44
- var gherkin_utils_1 = require("@cucumber/gherkin-utils");
45
- var messages_1 = require("@cucumber/messages");
46
- var stream_1 = require("stream");
47
- var assert_1 = __importDefault(require("assert"));
48
- var fake_cucumber_1 = require("@cucumber/fake-cucumber");
49
- var util_1 = require("util");
50
- var IncrementClock_1 = __importDefault(require("@cucumber/fake-cucumber/dist/src/IncrementClock"));
51
- var Query_1 = __importDefault(require("../src/Query"));
52
- var fake_cucumber_2 = require("@cucumber/fake-cucumber");
53
- var IncrementStopwatch_1 = __importDefault(require("@cucumber/fake-cucumber/dist/src/IncrementStopwatch"));
54
- var pipelinePromise = util_1.promisify(stream_1.pipeline);
55
- describe('Query', function () {
56
- var gherkinQuery;
57
- var cucumberQuery;
58
- beforeEach(function () {
15
+ const gherkin_streams_1 = require("@cucumber/gherkin-streams");
16
+ const gherkin_utils_1 = require("@cucumber/gherkin-utils");
17
+ const messages_1 = require("@cucumber/messages");
18
+ const stream_1 = require("stream");
19
+ const assert_1 = __importDefault(require("assert"));
20
+ const fake_cucumber_1 = require("@cucumber/fake-cucumber");
21
+ const util_1 = require("util");
22
+ const Query_1 = __importDefault(require("../src/Query"));
23
+ const pipelinePromise = util_1.promisify(stream_1.pipeline);
24
+ describe('Query', () => {
25
+ let gherkinQuery;
26
+ let cucumberQuery;
27
+ beforeEach(() => {
59
28
  gherkinQuery = new gherkin_utils_1.Query();
60
29
  cucumberQuery = new Query_1.default();
61
30
  });
62
- describe('#getWorstTestStepResult(testStepResults)', function () {
63
- it('returns a FAILED result for PASSED,FAILED,PASSED', function () {
64
- var result = cucumberQuery.getWorstTestStepResult([
31
+ describe('#getWorstTestStepResult(testStepResults)', () => {
32
+ it('returns a FAILED result for PASSED,FAILED,PASSED', () => {
33
+ const result = cucumberQuery.getWorstTestStepResult([
65
34
  new messages_1.messages.TestStepFinished.TestStepResult({
66
35
  status: messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
67
36
  }),
@@ -75,447 +44,352 @@ describe('Query', function () {
75
44
  assert_1.default.strictEqual(result.status, messages_1.messages.TestStepFinished.TestStepResult.Status.FAILED);
76
45
  });
77
46
  });
78
- describe('#getPickleStepTestStepResults(pickleStepIds)', function () {
79
- it('returns a single UNKNOWN when the list is empty', function () {
80
- var results = cucumberQuery.getPickleTestStepResults([]);
81
- assert_1.default.deepStrictEqual(results.map(function (r) { return r.status; }), [messages_1.messages.TestStepFinished.TestStepResult.Status.UNKNOWN]);
47
+ describe('#getPickleStepTestStepResults(pickleStepIds)', () => {
48
+ it('returns a single UNKNOWN when the list is empty', () => {
49
+ const results = cucumberQuery.getPickleTestStepResults([]);
50
+ assert_1.default.deepStrictEqual(results.map((r) => r.status), [messages_1.messages.TestStepFinished.TestStepResult.Status.UNKNOWN]);
82
51
  });
83
- it('looks up results for scenario steps', function () { return __awaiter(void 0, void 0, void 0, function () {
84
- var envelopes, scenario, pickleStepIds, testStepResults;
85
- return __generator(this, function (_a) {
86
- switch (_a.label) {
87
- case 0:
88
- envelopes = [];
89
- return [4 /*yield*/, execute("Feature: hello\n Scenario: ok\n Given a passed step\n", function (envelope) { return envelopes.push(envelope); })];
90
- case 1:
91
- _a.sent();
92
- scenario = findScenario(envelopes);
93
- pickleStepIds = gherkinQuery.getPickleStepIds(scenario.steps[0].id);
94
- assert_1.default.strictEqual(pickleStepIds.length, 1);
95
- testStepResults = cucumberQuery.getPickleStepTestStepResults(pickleStepIds);
96
- assert_1.default.strictEqual(testStepResults.length, 1);
97
- assert_1.default.strictEqual(testStepResults[0].status, messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED);
98
- return [2 /*return*/];
99
- }
100
- });
101
- }); });
102
- it('looks up results for background steps', function () { return __awaiter(void 0, void 0, void 0, function () {
103
- var envelopes, background, pickleStepIds, testStepResults;
104
- return __generator(this, function (_a) {
105
- switch (_a.label) {
106
- case 0:
107
- envelopes = [];
108
- return [4 /*yield*/, execute("Feature: hello\n Background:\n Given a passed step\n\n Scenario: ok\n Given a passed step\n\n Scenario: ko\n Given a failed step\n", function (envelope) { return envelopes.push(envelope); })];
109
- case 1:
110
- _a.sent();
111
- background = findBackground(envelopes);
112
- pickleStepIds = gherkinQuery.getPickleStepIds(background.steps[0].id);
113
- assert_1.default.strictEqual(pickleStepIds.length, 2);
114
- testStepResults = cucumberQuery.getPickleStepTestStepResults(pickleStepIds);
115
- assert_1.default.deepStrictEqual(testStepResults.map(function (r) { return r.status; }), [
116
- messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
117
- messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
118
- ]);
119
- return [2 /*return*/];
120
- }
121
- });
122
- }); });
123
- it('looks up results for background steps when scenarios are empty', function () { return __awaiter(void 0, void 0, void 0, function () {
124
- var envelopes, background, pickleStepIds, testStepResults;
125
- return __generator(this, function (_a) {
126
- switch (_a.label) {
127
- case 0:
128
- envelopes = [];
129
- return [4 /*yield*/, execute("Feature: hello\n Background:\n Given a passed step\n\n Scenario: ok\n\n Scenario: ok too\n", function (envelope) { return envelopes.push(envelope); })];
130
- case 1:
131
- _a.sent();
132
- background = findBackground(envelopes);
133
- pickleStepIds = gherkinQuery.getPickleStepIds(background.steps[0].id);
134
- assert_1.default.strictEqual(pickleStepIds.length, 0);
135
- testStepResults = cucumberQuery.getPickleStepTestStepResults(pickleStepIds);
136
- assert_1.default.strictEqual(testStepResults.length, 1);
137
- assert_1.default.strictEqual(testStepResults[0].status, messages_1.messages.TestStepFinished.TestStepResult.Status.UNKNOWN);
138
- return [2 /*return*/];
139
- }
140
- });
141
- }); });
52
+ it('looks up results for scenario steps', () => __awaiter(void 0, void 0, void 0, function* () {
53
+ const envelopes = [];
54
+ yield execute(`Feature: hello
55
+ Scenario: ok
56
+ Given a passed step
57
+ `, (envelope) => envelopes.push(envelope));
58
+ const scenario = findScenario(envelopes);
59
+ const pickleStepIds = gherkinQuery.getPickleStepIds(scenario.steps[0].id);
60
+ assert_1.default.strictEqual(pickleStepIds.length, 1);
61
+ const testStepResults = cucumberQuery.getPickleStepTestStepResults(pickleStepIds);
62
+ assert_1.default.strictEqual(testStepResults.length, 1);
63
+ assert_1.default.strictEqual(testStepResults[0].status, messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED);
64
+ }));
65
+ it('looks up results for background steps', () => __awaiter(void 0, void 0, void 0, function* () {
66
+ const envelopes = [];
67
+ yield execute(`Feature: hello
68
+ Background:
69
+ Given a passed step
70
+
71
+ Scenario: ok
72
+ Given a passed step
73
+
74
+ Scenario: ko
75
+ Given a failed step
76
+ `, (envelope) => envelopes.push(envelope));
77
+ const background = findBackground(envelopes);
78
+ const pickleStepIds = gherkinQuery.getPickleStepIds(background.steps[0].id);
79
+ assert_1.default.strictEqual(pickleStepIds.length, 2);
80
+ const testStepResults = cucumberQuery.getPickleStepTestStepResults(pickleStepIds);
81
+ assert_1.default.deepStrictEqual(testStepResults.map((r) => r.status), [
82
+ messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
83
+ messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
84
+ ]);
85
+ }));
86
+ it('looks up results for background steps when scenarios are empty', () => __awaiter(void 0, void 0, void 0, function* () {
87
+ const envelopes = [];
88
+ yield execute(`Feature: hello
89
+ Background:
90
+ Given a passed step
91
+
92
+ Scenario: ok
93
+
94
+ Scenario: ok too
95
+ `, (envelope) => envelopes.push(envelope));
96
+ const background = findBackground(envelopes);
97
+ const pickleStepIds = gherkinQuery.getPickleStepIds(background.steps[0].id);
98
+ assert_1.default.strictEqual(pickleStepIds.length, 0);
99
+ const testStepResults = cucumberQuery.getPickleStepTestStepResults(pickleStepIds);
100
+ assert_1.default.strictEqual(testStepResults.length, 1);
101
+ assert_1.default.strictEqual(testStepResults[0].status, messages_1.messages.TestStepFinished.TestStepResult.Status.UNKNOWN);
102
+ }));
142
103
  });
143
- describe('#getPickleTestStepResults(pickleIds)', function () {
144
- it('looks up results for scenarios', function () { return __awaiter(void 0, void 0, void 0, function () {
145
- var envelopes, scenario, pickleIds, testStepResults;
146
- return __generator(this, function (_a) {
147
- switch (_a.label) {
148
- case 0:
149
- envelopes = [];
150
- return [4 /*yield*/, execute("Feature: hello\n Scenario: ko\n Given a passed step\n Given a failed step\n", function (envelope) { return envelopes.push(envelope); })];
151
- case 1:
152
- _a.sent();
153
- scenario = findScenario(envelopes);
154
- pickleIds = gherkinQuery.getPickleIds('test.feature', scenario.id);
155
- assert_1.default.strictEqual(pickleIds.length, 1);
156
- testStepResults = cucumberQuery.getPickleTestStepResults(pickleIds);
157
- assert_1.default.deepStrictEqual(testStepResults.map(function (r) { return r.status; }), [
158
- messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
159
- messages_1.messages.TestStepFinished.TestStepResult.Status.FAILED,
160
- ]);
161
- return [2 /*return*/];
162
- }
163
- });
164
- }); });
165
- it('looks up results for scenario outlines', function () { return __awaiter(void 0, void 0, void 0, function () {
166
- var envelopes, scenario, pickleIds;
167
- return __generator(this, function (_a) {
168
- switch (_a.label) {
169
- case 0:
170
- envelopes = [];
171
- return [4 /*yield*/, execute("Feature: hello\n Scenario: hi <status1> and <status2>\n Given a <status1> step\n And a <status2> step\n\n Examples:\n | status1 | status2 |\n | passed | passed |\n | passed | failed |\n", function (envelope) { return envelopes.push(envelope); })];
172
- case 1:
173
- _a.sent();
174
- scenario = findScenario(envelopes);
175
- pickleIds = gherkinQuery.getPickleIds('test.feature', scenario.id);
176
- assert_1.default.strictEqual(pickleIds.length, 2);
177
- assert_1.default.deepStrictEqual(cucumberQuery.getPickleTestStepResults(pickleIds).map(function (r) { return r.status; }), [
178
- messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
179
- messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
180
- messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
181
- messages_1.messages.TestStepFinished.TestStepResult.Status.FAILED,
182
- ]);
183
- return [2 /*return*/];
184
- }
185
- });
186
- }); });
187
- it('looks up results for examples rows outlines', function () { return __awaiter(void 0, void 0, void 0, function () {
188
- var envelopes, scenario, exampleIds;
189
- return __generator(this, function (_a) {
190
- switch (_a.label) {
191
- case 0:
192
- envelopes = [];
193
- return [4 /*yield*/, execute("Feature: hello\n Scenario: hi <status1> and <status2>\n Given a <status1> step\n And a <status2> step\n\n Examples:\n | status1 | status2 |\n | passed | passed |\n | passed | failed |\n", function (envelope) { return envelopes.push(envelope); })];
194
- case 1:
195
- _a.sent();
196
- scenario = findScenario(envelopes);
197
- exampleIds = scenario.examples[0].tableBody.map(function (row) { return row.id; });
198
- assert_1.default.deepStrictEqual(cucumberQuery
199
- .getPickleTestStepResults(gherkinQuery.getPickleIds('test.feature', exampleIds[0]))
200
- .map(function (r) { return r.status; }), [
201
- messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
202
- messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
203
- ]);
204
- assert_1.default.deepStrictEqual(cucumberQuery
205
- .getPickleTestStepResults(gherkinQuery.getPickleIds('test.feature', exampleIds[1]))
206
- .map(function (r) { return r.status; }), [
207
- messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
208
- messages_1.messages.TestStepFinished.TestStepResult.Status.FAILED,
209
- ]);
210
- return [2 /*return*/];
211
- }
212
- });
213
- }); });
104
+ describe('#getPickleTestStepResults(pickleIds)', () => {
105
+ it('looks up results for scenarios', () => __awaiter(void 0, void 0, void 0, function* () {
106
+ const envelopes = [];
107
+ yield execute(`Feature: hello
108
+ Scenario: ko
109
+ Given a passed step
110
+ Given a failed step
111
+ `, (envelope) => envelopes.push(envelope));
112
+ const scenario = findScenario(envelopes);
113
+ const pickleIds = gherkinQuery.getPickleIds('test.feature', scenario.id);
114
+ assert_1.default.strictEqual(pickleIds.length, 1);
115
+ const testStepResults = cucumberQuery.getPickleTestStepResults(pickleIds);
116
+ assert_1.default.deepStrictEqual(testStepResults.map((r) => r.status), [
117
+ messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
118
+ messages_1.messages.TestStepFinished.TestStepResult.Status.FAILED,
119
+ ]);
120
+ }));
121
+ it('looks up results for scenario outlines', () => __awaiter(void 0, void 0, void 0, function* () {
122
+ const envelopes = [];
123
+ yield execute(`Feature: hello
124
+ Scenario: hi <status1> and <status2>
125
+ Given a <status1> step
126
+ And a <status2> step
127
+
128
+ Examples:
129
+ | status1 | status2 |
130
+ | passed | passed |
131
+ | passed | failed |
132
+ `, (envelope) => envelopes.push(envelope));
133
+ const scenario = findScenario(envelopes);
134
+ const pickleIds = gherkinQuery.getPickleIds('test.feature', scenario.id);
135
+ assert_1.default.strictEqual(pickleIds.length, 2);
136
+ assert_1.default.deepStrictEqual(cucumberQuery.getPickleTestStepResults(pickleIds).map((r) => r.status), [
137
+ messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
138
+ messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
139
+ messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
140
+ messages_1.messages.TestStepFinished.TestStepResult.Status.FAILED,
141
+ ]);
142
+ }));
143
+ it('looks up results for examples rows outlines', () => __awaiter(void 0, void 0, void 0, function* () {
144
+ const envelopes = [];
145
+ yield execute(`Feature: hello
146
+ Scenario: hi <status1> and <status2>
147
+ Given a <status1> step
148
+ And a <status2> step
149
+
150
+ Examples:
151
+ | status1 | status2 |
152
+ | passed | passed |
153
+ | passed | failed |
154
+ `, (envelope) => envelopes.push(envelope));
155
+ const scenario = findScenario(envelopes);
156
+ const exampleIds = scenario.examples[0].tableBody.map((row) => row.id);
157
+ assert_1.default.deepStrictEqual(cucumberQuery
158
+ .getPickleTestStepResults(gherkinQuery.getPickleIds('test.feature', exampleIds[0]))
159
+ .map((r) => r.status), [
160
+ messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
161
+ messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
162
+ ]);
163
+ assert_1.default.deepStrictEqual(cucumberQuery
164
+ .getPickleTestStepResults(gherkinQuery.getPickleIds('test.feature', exampleIds[1]))
165
+ .map((r) => r.status), [
166
+ messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED,
167
+ messages_1.messages.TestStepFinished.TestStepResult.Status.FAILED,
168
+ ]);
169
+ }));
214
170
  });
215
- describe('#getPickleStepAttachments(pickleIds)', function () {
216
- it('looks up attachments', function () { return __awaiter(void 0, void 0, void 0, function () {
217
- var envelopes, scenario, pickleStepIds, attachments;
218
- return __generator(this, function (_a) {
219
- switch (_a.label) {
220
- case 0:
221
- envelopes = [];
222
- return [4 /*yield*/, execute("Feature: hello\n Scenario: ok\n Given a passed step with attachment\n ", function (envelope) { return envelopes.push(envelope); })];
223
- case 1:
224
- _a.sent();
225
- scenario = findScenario(envelopes);
226
- pickleStepIds = gherkinQuery.getPickleStepIds(scenario.steps[0].id);
227
- assert_1.default.strictEqual(pickleStepIds.length, 1);
228
- attachments = cucumberQuery.getPickleStepAttachments(pickleStepIds);
229
- assert_1.default.strictEqual(attachments.length, 1);
230
- assert_1.default.strictEqual(attachments[0].body, 'Hello');
231
- return [2 /*return*/];
232
- }
233
- });
234
- }); });
171
+ describe('#getPickleStepAttachments(pickleIds)', () => {
172
+ it('looks up attachments', () => __awaiter(void 0, void 0, void 0, function* () {
173
+ const envelopes = [];
174
+ yield execute(`Feature: hello
175
+ Scenario: ok
176
+ Given a passed step with attachment
177
+ `, (envelope) => envelopes.push(envelope));
178
+ const scenario = findScenario(envelopes);
179
+ const pickleStepIds = gherkinQuery.getPickleStepIds(scenario.steps[0].id);
180
+ assert_1.default.strictEqual(pickleStepIds.length, 1);
181
+ const attachments = cucumberQuery.getPickleStepAttachments(pickleStepIds);
182
+ assert_1.default.strictEqual(attachments.length, 1);
183
+ assert_1.default.strictEqual(attachments[0].body, 'Hello');
184
+ }));
235
185
  });
236
- describe('#getStepMatchArguments(uri, lineNumber)', function () {
237
- it("looks up result for step's uri and line", function () { return __awaiter(void 0, void 0, void 0, function () {
238
- var envelopes, scenario;
239
- return __generator(this, function (_a) {
240
- switch (_a.label) {
241
- case 0:
242
- envelopes = [];
243
- return [4 /*yield*/, execute("Feature: hello\n Scenario: ok\n Given a passed step\n And I have 567 cukes in my belly\n ", function (envelope) { return envelopes.push(envelope); })];
244
- case 1:
245
- _a.sent();
246
- scenario = findScenario(envelopes);
247
- assert_1.default.deepStrictEqual(cucumberQuery
248
- .getStepMatchArgumentsLists(gherkinQuery.getPickleStepIds(scenario.steps[0].id)[0])
249
- .map(function (sal) {
250
- return sal.stepMatchArguments.map(function (arg) { return arg.parameterTypeName; });
251
- }), [[]]);
252
- assert_1.default.deepStrictEqual(cucumberQuery
253
- .getStepMatchArgumentsLists(gherkinQuery.getPickleStepIds(scenario.steps[1].id)[0])
254
- .map(function (sal) {
255
- return sal.stepMatchArguments.map(function (arg) { return arg.parameterTypeName; });
256
- }), [['int', 'word']]);
257
- return [2 /*return*/];
258
- }
259
- });
260
- }); });
261
- describe('#getBeforeHookSteps(pickleId: string)', function () {
262
- it('returns an empty list when there is no hooks', function () { return __awaiter(void 0, void 0, void 0, function () {
263
- var envelopes, scenarioId, pickleId;
264
- return __generator(this, function (_a) {
265
- switch (_a.label) {
266
- case 0:
267
- envelopes = [];
268
- return [4 /*yield*/, execute("Feature: hello\n Scenario: hi\n Given a passed step\n ", function (envelope) { return envelopes.push(envelope); })];
269
- case 1:
270
- _a.sent();
271
- scenarioId = findScenario(envelopes).id;
272
- pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
273
- assert_1.default.deepStrictEqual(cucumberQuery.getBeforeHookSteps(pickleId), []);
274
- return [2 /*return*/];
275
- }
276
- });
277
- }); });
278
- it('returns one before hook step', function () { return __awaiter(void 0, void 0, void 0, function () {
279
- var envelopes, scenarioId, pickleId;
280
- return __generator(this, function (_a) {
281
- switch (_a.label) {
282
- case 0:
283
- envelopes = [];
284
- return [4 /*yield*/, execute("Feature: hello\n @beforeHook\n Scenario: hi\n Given a passed step\n ", function (envelope) { return envelopes.push(envelope); })];
285
- case 1:
286
- _a.sent();
287
- scenarioId = findScenario(envelopes).id;
288
- pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
289
- assert_1.default.strictEqual(cucumberQuery.getBeforeHookSteps(pickleId).length, 1);
290
- return [2 /*return*/];
291
- }
292
- });
293
- }); });
294
- it('does not return after hook steps', function () { return __awaiter(void 0, void 0, void 0, function () {
295
- var envelopes, scenarioId, pickleId;
296
- return __generator(this, function (_a) {
297
- switch (_a.label) {
298
- case 0:
299
- envelopes = [];
300
- return [4 /*yield*/, execute("Feature: hello\n @afterHook\n Scenario: hi\n Given a passed step\n ", function (envelope) { return envelopes.push(envelope); })];
301
- case 1:
302
- _a.sent();
303
- scenarioId = findScenario(envelopes).id;
304
- pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
305
- assert_1.default.deepStrictEqual(cucumberQuery.getBeforeHookSteps(pickleId), []);
306
- return [2 /*return*/];
307
- }
308
- });
309
- }); });
186
+ describe('#getStepMatchArguments(uri, lineNumber)', () => {
187
+ it("looks up result for step's uri and line", () => __awaiter(void 0, void 0, void 0, function* () {
188
+ const envelopes = [];
189
+ yield execute(`Feature: hello
190
+ Scenario: ok
191
+ Given a passed step
192
+ And I have 567 cukes in my belly
193
+ `, (envelope) => envelopes.push(envelope));
194
+ const scenario = findScenario(envelopes);
195
+ assert_1.default.deepStrictEqual(cucumberQuery
196
+ .getStepMatchArgumentsLists(gherkinQuery.getPickleStepIds(scenario.steps[0].id)[0])
197
+ .map((sal) => sal.stepMatchArguments.map((arg) => arg.parameterTypeName)), [[]]);
198
+ assert_1.default.deepStrictEqual(cucumberQuery
199
+ .getStepMatchArgumentsLists(gherkinQuery.getPickleStepIds(scenario.steps[1].id)[0])
200
+ .map((sal) => sal.stepMatchArguments.map((arg) => arg.parameterTypeName)), [['int', 'word']]);
201
+ }));
202
+ describe('#getBeforeHookSteps(pickleId: string)', () => {
203
+ it('returns an empty list when there is no hooks', () => __awaiter(void 0, void 0, void 0, function* () {
204
+ const envelopes = [];
205
+ yield execute(`Feature: hello
206
+ Scenario: hi
207
+ Given a passed step
208
+ `, (envelope) => envelopes.push(envelope));
209
+ const scenarioId = findScenario(envelopes).id;
210
+ const pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
211
+ assert_1.default.deepStrictEqual(cucumberQuery.getBeforeHookSteps(pickleId), []);
212
+ }));
213
+ it('returns one before hook step', () => __awaiter(void 0, void 0, void 0, function* () {
214
+ const envelopes = [];
215
+ yield execute(`Feature: hello
216
+ @beforeHook
217
+ Scenario: hi
218
+ Given a passed step
219
+ `, (envelope) => envelopes.push(envelope));
220
+ const scenarioId = findScenario(envelopes).id;
221
+ const pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
222
+ assert_1.default.strictEqual(cucumberQuery.getBeforeHookSteps(pickleId).length, 1);
223
+ }));
224
+ it('does not return after hook steps', () => __awaiter(void 0, void 0, void 0, function* () {
225
+ const envelopes = [];
226
+ yield execute(`Feature: hello
227
+ @afterHook
228
+ Scenario: hi
229
+ Given a passed step
230
+ `, (envelope) => envelopes.push(envelope));
231
+ const scenarioId = findScenario(envelopes).id;
232
+ const pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
233
+ assert_1.default.deepStrictEqual(cucumberQuery.getBeforeHookSteps(pickleId), []);
234
+ }));
310
235
  });
311
- describe('#getAfterHookSteps(pickleId: string)', function () {
312
- it('returns an empty list when there is no hooks', function () { return __awaiter(void 0, void 0, void 0, function () {
313
- var envelopes, scenarioId, pickleId;
314
- return __generator(this, function (_a) {
315
- switch (_a.label) {
316
- case 0:
317
- envelopes = [];
318
- return [4 /*yield*/, execute("Feature: hello\n Scenario: hi\n Given a passed step\n ", function (envelope) { return envelopes.push(envelope); })];
319
- case 1:
320
- _a.sent();
321
- scenarioId = findScenario(envelopes).id;
322
- pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
323
- assert_1.default.deepStrictEqual(cucumberQuery.getAfterHookSteps(pickleId), []);
324
- return [2 /*return*/];
325
- }
326
- });
327
- }); });
328
- it('returns one after hook step', function () { return __awaiter(void 0, void 0, void 0, function () {
329
- var envelopes, scenarioId, pickleId;
330
- return __generator(this, function (_a) {
331
- switch (_a.label) {
332
- case 0:
333
- envelopes = [];
334
- return [4 /*yield*/, execute("Feature: hello\n @afterHook\n Scenario: hi\n Given a passed step\n ", function (envelope) { return envelopes.push(envelope); })];
335
- case 1:
336
- _a.sent();
337
- scenarioId = findScenario(envelopes).id;
338
- pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
339
- assert_1.default.strictEqual(cucumberQuery.getAfterHookSteps(pickleId).length, 1);
340
- return [2 /*return*/];
341
- }
342
- });
343
- }); });
344
- it('does not return before hook steps', function () { return __awaiter(void 0, void 0, void 0, function () {
345
- var envelopes, scenarioId, pickleId;
346
- return __generator(this, function (_a) {
347
- switch (_a.label) {
348
- case 0:
349
- envelopes = [];
350
- return [4 /*yield*/, execute("Feature: hello\n @beforeHook\n Scenario: hi\n Given a passed step\n ", function (envelope) { return envelopes.push(envelope); })];
351
- case 1:
352
- _a.sent();
353
- scenarioId = findScenario(envelopes).id;
354
- pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
355
- assert_1.default.deepStrictEqual(cucumberQuery.getAfterHookSteps(pickleId), []);
356
- return [2 /*return*/];
357
- }
358
- });
359
- }); });
236
+ describe('#getAfterHookSteps(pickleId: string)', () => {
237
+ it('returns an empty list when there is no hooks', () => __awaiter(void 0, void 0, void 0, function* () {
238
+ const envelopes = [];
239
+ yield execute(`Feature: hello
240
+ Scenario: hi
241
+ Given a passed step
242
+ `, (envelope) => envelopes.push(envelope));
243
+ const scenarioId = findScenario(envelopes).id;
244
+ const pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
245
+ assert_1.default.deepStrictEqual(cucumberQuery.getAfterHookSteps(pickleId), []);
246
+ }));
247
+ it('returns one after hook step', () => __awaiter(void 0, void 0, void 0, function* () {
248
+ const envelopes = [];
249
+ yield execute(`Feature: hello
250
+ @afterHook
251
+ Scenario: hi
252
+ Given a passed step
253
+ `, (envelope) => envelopes.push(envelope));
254
+ const scenarioId = findScenario(envelopes).id;
255
+ const pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
256
+ assert_1.default.strictEqual(cucumberQuery.getAfterHookSteps(pickleId).length, 1);
257
+ }));
258
+ it('does not return before hook steps', () => __awaiter(void 0, void 0, void 0, function* () {
259
+ const envelopes = [];
260
+ yield execute(`Feature: hello
261
+ @beforeHook
262
+ Scenario: hi
263
+ Given a passed step
264
+ `, (envelope) => envelopes.push(envelope));
265
+ const scenarioId = findScenario(envelopes).id;
266
+ const pickleId = gherkinQuery.getPickleIds('test.feature', scenarioId)[0];
267
+ assert_1.default.deepStrictEqual(cucumberQuery.getAfterHookSteps(pickleId), []);
268
+ }));
360
269
  });
361
- describe('#getTestStepResult', function () {
362
- it('returns one test step result', function () { return __awaiter(void 0, void 0, void 0, function () {
363
- var emittedMessages, testCase, testStep, results;
364
- return __generator(this, function (_a) {
365
- switch (_a.label) {
366
- case 0:
367
- emittedMessages = [];
368
- return [4 /*yield*/, execute("Feature: hello\n Scenario: hi\n Given a passed step\n ", function (message) { return emittedMessages.push(message); })];
369
- case 1:
370
- _a.sent();
371
- testCase = emittedMessages.find(function (child) { return child.testCase; })
372
- .testCase;
373
- testStep = testCase.testSteps[0];
374
- results = cucumberQuery.getTestStepResults(testStep.id);
375
- assert_1.default.deepStrictEqual(results.length, 1);
376
- assert_1.default.deepStrictEqual(results[0].status, messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED);
377
- return [2 /*return*/];
378
- }
379
- });
380
- }); });
381
- it('returns a result for hook step', function () { return __awaiter(void 0, void 0, void 0, function () {
382
- var emittedMessages, testCase, testStep, results;
383
- return __generator(this, function (_a) {
384
- switch (_a.label) {
385
- case 0:
386
- emittedMessages = [];
387
- return [4 /*yield*/, execute("Feature: hello\n @beforeHook\n Scenario: hi\n Given a passed step\n ", function (message) { return emittedMessages.push(message); })];
388
- case 1:
389
- _a.sent();
390
- testCase = emittedMessages.find(function (child) { return child.testCase; })
391
- .testCase;
392
- testStep = testCase.testSteps[0];
393
- results = cucumberQuery.getTestStepResults(testStep.id);
394
- assert_1.default.deepStrictEqual(results.length, 1);
395
- assert_1.default.deepStrictEqual(results[0].status, messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED);
396
- return [2 /*return*/];
397
- }
398
- });
399
- }); });
270
+ describe('#getTestStepResult', () => {
271
+ it('returns one test step result', () => __awaiter(void 0, void 0, void 0, function* () {
272
+ const emittedMessages = [];
273
+ yield execute(`Feature: hello
274
+ Scenario: hi
275
+ Given a passed step
276
+ `, (message) => emittedMessages.push(message));
277
+ const testCase = emittedMessages.find((child) => child.testCase).testCase;
278
+ const testStep = testCase.testSteps[0];
279
+ const results = cucumberQuery.getTestStepResults(testStep.id);
280
+ assert_1.default.deepStrictEqual(results.length, 1);
281
+ assert_1.default.deepStrictEqual(results[0].status, messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED);
282
+ }));
283
+ it('returns a result for hook step', () => __awaiter(void 0, void 0, void 0, function* () {
284
+ const emittedMessages = [];
285
+ yield execute(`Feature: hello
286
+ @beforeHook
287
+ Scenario: hi
288
+ Given a passed step
289
+ `, (message) => emittedMessages.push(message));
290
+ const testCase = emittedMessages.find((child) => child.testCase).testCase;
291
+ const testStep = testCase.testSteps[0];
292
+ const results = cucumberQuery.getTestStepResults(testStep.id);
293
+ assert_1.default.deepStrictEqual(results.length, 1);
294
+ assert_1.default.deepStrictEqual(results[0].status, messages_1.messages.TestStepFinished.TestStepResult.Status.PASSED);
295
+ }));
400
296
  });
401
- describe('#getHook(HookId)', function () {
402
- it('returns undefined if the id does not match any hook', function () {
297
+ describe('#getHook(HookId)', () => {
298
+ it('returns undefined if the id does not match any hook', () => {
403
299
  assert_1.default.strictEqual(cucumberQuery.getHook('tralala'), undefined);
404
300
  });
405
- it('returns the matching hook', function () {
406
- var hook = messages_1.messages.Hook.create({
301
+ it('returns the matching hook', () => {
302
+ const hook = messages_1.messages.Hook.create({
407
303
  id: 'tralala',
408
304
  });
409
- var envelope = messages_1.messages.Envelope.create({
410
- hook: hook,
305
+ const envelope = messages_1.messages.Envelope.create({
306
+ hook,
411
307
  });
412
308
  cucumberQuery.update(envelope);
413
309
  assert_1.default.deepStrictEqual(cucumberQuery.getHook('tralala'), hook);
414
310
  });
415
311
  });
416
- describe('#getAttachmentByTestStepId', function () {
417
- it('looks up attachments', function () { return __awaiter(void 0, void 0, void 0, function () {
418
- var testCases, attachments;
419
- return __generator(this, function (_a) {
420
- switch (_a.label) {
421
- case 0:
422
- testCases = [];
423
- return [4 /*yield*/, execute("Feature: hello\n Scenario: ok\n Given a passed step with attachment\n ", function (envelope) {
424
- if (envelope.testCase) {
425
- testCases.push(envelope.testCase);
426
- }
427
- })];
428
- case 1:
429
- _a.sent();
430
- attachments = cucumberQuery.getTestStepsAttachments([
431
- testCases[0].testSteps[0].id,
432
- ]);
433
- assert_1.default.strictEqual(attachments.length, 1);
434
- assert_1.default.strictEqual(attachments[0].body, 'Hello');
435
- return [2 /*return*/];
312
+ describe('#getAttachmentByTestStepId', () => {
313
+ it('looks up attachments', () => __awaiter(void 0, void 0, void 0, function* () {
314
+ const testCases = [];
315
+ yield execute(`Feature: hello
316
+ Scenario: ok
317
+ Given a passed step with attachment
318
+ `, (envelope) => {
319
+ if (envelope.testCase) {
320
+ testCases.push(envelope.testCase);
436
321
  }
437
322
  });
438
- }); });
323
+ const attachments = cucumberQuery.getTestStepsAttachments([testCases[0].testSteps[0].id]);
324
+ assert_1.default.strictEqual(attachments.length, 1);
325
+ assert_1.default.strictEqual(attachments[0].body, 'Hello');
326
+ }));
439
327
  });
440
328
  });
441
- function execute(gherkinSource, messagesHandler) {
442
- if (messagesHandler === void 0) { messagesHandler = function () { return null; }; }
443
- return __awaiter(this, void 0, void 0, function () {
444
- var newId, clock, stopwatch, makeErrorMessage, supportCode, queryUpdateStream, testPlan;
445
- return __generator(this, function (_a) {
446
- switch (_a.label) {
447
- case 0:
448
- newId = messages_1.IdGenerator.incrementing();
449
- clock = new IncrementClock_1.default();
450
- stopwatch = new IncrementStopwatch_1.default();
451
- makeErrorMessage = fake_cucumber_1.withFullStackTrace();
452
- supportCode = new fake_cucumber_1.SupportCode(newId, clock, stopwatch, makeErrorMessage);
453
- supportCode.defineBeforeHook(null, '@beforeHook', function () {
454
- // no-op
455
- });
456
- supportCode.defineAfterHook(null, '@afterHook', function () {
457
- // no-op
458
- });
459
- supportCode.defineStepDefinition(null, 'a passed step', function () {
460
- // no-op
461
- });
462
- supportCode.defineStepDefinition(null, 'a passed step with attachment', function () {
463
- this.attach('Hello', 'text/plain');
464
- });
465
- supportCode.defineStepDefinition(null, 'a failed step', function () {
466
- throw new Error("This step failed.");
467
- });
468
- supportCode.defineStepDefinition(null, 'I have {int} cukes in my {word}', function (cukes) {
469
- assert_1.default.ok(cukes);
470
- });
471
- queryUpdateStream = new stream_1.Writable({
472
- objectMode: true,
473
- write: function (envelope, encoding, callback) {
474
- try {
475
- messagesHandler(envelope);
476
- gherkinQuery.update(envelope);
477
- cucumberQuery.update(envelope);
478
- callback();
479
- }
480
- catch (err) {
481
- callback(err);
482
- }
483
- },
484
- });
485
- return [4 /*yield*/, pipelinePromise(gherkinMessages(gherkinSource, 'test.feature', newId), queryUpdateStream)];
486
- case 1:
487
- _a.sent();
488
- testPlan = fake_cucumber_2.makeTestPlan(gherkinQuery, supportCode, fake_cucumber_2.makeTestCase);
489
- return [4 /*yield*/, testPlan.execute(function (envelope) {
490
- messagesHandler(envelope);
491
- cucumberQuery.update(envelope);
492
- })];
493
- case 2:
494
- _a.sent();
495
- return [2 /*return*/];
496
- }
329
+ function execute(gherkinSource, messagesHandler = () => null) {
330
+ return __awaiter(this, void 0, void 0, function* () {
331
+ const newId = messages_1.IdGenerator.incrementing();
332
+ const clock = new fake_cucumber_1.IncrementClock();
333
+ const stopwatch = new fake_cucumber_1.IncrementStopwatch();
334
+ const makeErrorMessage = fake_cucumber_1.withFullStackTrace();
335
+ const supportCode = new fake_cucumber_1.SupportCode(newId, clock, stopwatch, makeErrorMessage);
336
+ supportCode.defineBeforeHook(null, '@beforeHook', () => {
337
+ // no-op
338
+ });
339
+ supportCode.defineAfterHook(null, '@afterHook', () => {
340
+ // no-op
341
+ });
342
+ supportCode.defineStepDefinition(null, 'a passed step', () => {
343
+ // no-op
344
+ });
345
+ supportCode.defineStepDefinition(null, 'a passed step with attachment', function () {
346
+ this.attach('Hello', 'text/plain');
347
+ });
348
+ supportCode.defineStepDefinition(null, 'a failed step', () => {
349
+ throw new Error(`This step failed.`);
350
+ });
351
+ supportCode.defineStepDefinition(null, 'I have {int} cukes in my {word}', (cukes) => {
352
+ assert_1.default.ok(cukes);
353
+ });
354
+ const queryUpdateStream = new stream_1.Writable({
355
+ objectMode: true,
356
+ write(envelope, encoding, callback) {
357
+ try {
358
+ messagesHandler(envelope);
359
+ gherkinQuery.update(envelope);
360
+ cucumberQuery.update(envelope);
361
+ callback();
362
+ }
363
+ catch (err) {
364
+ callback(err);
365
+ }
366
+ },
367
+ });
368
+ yield pipelinePromise(gherkinMessages(gherkinSource, 'test.feature', newId), queryUpdateStream);
369
+ const testPlan = fake_cucumber_1.makeTestPlan(gherkinQuery, supportCode, fake_cucumber_1.makeTestCase);
370
+ yield testPlan.execute((envelope) => {
371
+ messagesHandler(envelope);
372
+ cucumberQuery.update(envelope);
497
373
  });
498
374
  });
499
375
  }
500
376
  function gherkinMessages(gherkinSource, uri, newId) {
501
- var source = messages_1.messages.Envelope.fromObject({
377
+ const source = messages_1.messages.Envelope.fromObject({
502
378
  source: {
503
- uri: uri,
379
+ uri,
504
380
  data: gherkinSource,
505
381
  mediaType: 'text/x.cucumber.gherkin+plain',
506
382
  },
507
383
  });
508
- return gherkin_1.GherkinStreams.fromSources([source], { newId: newId });
384
+ return gherkin_streams_1.GherkinStreams.fromSources([source], { newId });
509
385
  }
510
386
  function findScenario(envelopes) {
511
- var gherkinDocument = envelopes.find(function (envelope) { return envelope.gherkinDocument; }).gherkinDocument;
512
- return gherkinDocument.feature.children.find(function (child) { return child.scenario; })
513
- .scenario;
387
+ const gherkinDocument = envelopes.find((envelope) => envelope.gherkinDocument).gherkinDocument;
388
+ return gherkinDocument.feature.children.find((child) => child.scenario).scenario;
514
389
  }
515
390
  function findBackground(envelopes) {
516
- var gherkinDocument = envelopes.find(function (envelope) { return envelope.gherkinDocument; }).gherkinDocument;
517
- return gherkinDocument.feature.children.find(function (child) { return child.background; })
518
- .background;
391
+ const gherkinDocument = envelopes.find((envelope) => envelope.gherkinDocument).gherkinDocument;
392
+ return gherkinDocument.feature.children.find((child) => child.background).background;
519
393
  }
520
394
  });
521
395
  //# sourceMappingURL=QueryTest.js.map