testit-adapter-jest 5.0.9-TMS-5.8 → 5.1.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/README.md +6 -1
- package/dist/testitEnvironment.d.ts +6 -0
- package/dist/testitEnvironment.js +57 -47
- package/package.json +2 -2
- package/types.d.ts +6 -0
package/README.md
CHANGED
|
@@ -123,12 +123,14 @@ $ npx jest -t "$(cat tmp/filter.txt)"
|
|
|
123
123
|
Methods can be used to specify information about autotest.
|
|
124
124
|
|
|
125
125
|
Description of metadata methods:
|
|
126
|
-
- `testit.
|
|
126
|
+
- `testit.workItemId` - a method that links an autotest with a manual test. Receives a single globalId
|
|
127
|
+
- `testit.workItemIds` - deprecated, use `testit.workItemId` instead
|
|
127
128
|
- `testit.displayName` - internal autotest name (used in Test IT)
|
|
128
129
|
- `testit.externalId` - unique internal autotest ID (used in Test IT)
|
|
129
130
|
- `testit.title` - autotest name specified in the autotest card. If not specified, the name from the displayName method is used
|
|
130
131
|
- `testit.description` - autotest description specified in the autotest card
|
|
131
132
|
- `testit.labels` - labels listed in the autotest card
|
|
133
|
+
- `testit.layer` - test pyramid layer in the autotest card (source **Run**). Use `TestLayers` from `testit-js-commons` for recommended values (`E2E`, `UI`, `API`, `Contract`, `Integration`, `Component`, `Unit`), or any custom string
|
|
132
134
|
- `testit.tags` - tags listed in the autotest card
|
|
133
135
|
- `testit.link` - links listed in the autotest card
|
|
134
136
|
- `testit.namespace` - directory in the TMS system (default - directory's name of test)
|
|
@@ -144,12 +146,15 @@ Description of methods:
|
|
|
144
146
|
|
|
145
147
|
#### Simple test
|
|
146
148
|
```js
|
|
149
|
+
import { TestLayers } from 'testit-js-commons';
|
|
150
|
+
|
|
147
151
|
test('All annotations', () => {
|
|
148
152
|
testit.externalId('all_annotations');
|
|
149
153
|
testit.displayName('All annotations');
|
|
150
154
|
testit.title('All annotations title');
|
|
151
155
|
testit.description('Test with all annotations');
|
|
152
156
|
testit.labels(['label1', 'label2']);
|
|
157
|
+
testit.layer(TestLayers.API);
|
|
153
158
|
|
|
154
159
|
testit.addMessage('This is a message');
|
|
155
160
|
testit.addLinks([
|
|
@@ -47,6 +47,7 @@ export default class TestItEnvironment extends NodeEnvironment {
|
|
|
47
47
|
private snapshotAutotestData;
|
|
48
48
|
private buildSetupSteps;
|
|
49
49
|
private buildTeardownSteps;
|
|
50
|
+
private buildAutotestPost;
|
|
50
51
|
private sendRealtimePayload;
|
|
51
52
|
/** afterAll hooks run after all tests; patch teardown when importRealtime is enabled. */
|
|
52
53
|
private flushRealtimeTeardown;
|
|
@@ -61,7 +62,12 @@ export default class TestItEnvironment extends NodeEnvironment {
|
|
|
61
62
|
addAttachments(attachments: string[]): void;
|
|
62
63
|
setLinks(links: Link[]): void;
|
|
63
64
|
setLabels(labels: string[]): void;
|
|
65
|
+
setLayer(layer: string): void;
|
|
64
66
|
setTags(tags: string[]): void;
|
|
67
|
+
setWorkItemId(globalId: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated Use workItemId with a single globalId instead.
|
|
70
|
+
*/
|
|
65
71
|
setWorkItems(workItems: string[]): void;
|
|
66
72
|
setParams(params: any): void;
|
|
67
73
|
setNameSpace(nameSpace: string): void;
|
|
@@ -94,7 +94,9 @@ class TestItEnvironment extends jest_environment_node_1.default {
|
|
|
94
94
|
displayName: this.setDisplayName.bind(this),
|
|
95
95
|
links: this.setLinks.bind(this),
|
|
96
96
|
labels: this.setLabels.bind(this),
|
|
97
|
+
layer: this.setLayer.bind(this),
|
|
97
98
|
tags: this.setTags.bind(this),
|
|
99
|
+
workItemId: this.setWorkItemId.bind(this),
|
|
98
100
|
workItemIds: this.setWorkItems.bind(this),
|
|
99
101
|
params: this.setParams.bind(this),
|
|
100
102
|
step: this.startStep.bind(this),
|
|
@@ -241,9 +243,9 @@ class TestItEnvironment extends jest_environment_node_1.default {
|
|
|
241
243
|
startedOn: test.startedAt ? new Date(test.startedAt) : undefined,
|
|
242
244
|
duration: test.duration ?? undefined,
|
|
243
245
|
traces: errorTraces,
|
|
244
|
-
attachments: this.additions.attachments,
|
|
246
|
+
attachments: [...this.additions.attachments],
|
|
245
247
|
message: this.additions.messages.join("\n").concat(errorMessage ?? ""),
|
|
246
|
-
links: this.additions.links,
|
|
248
|
+
links: [...this.additions.links],
|
|
247
249
|
};
|
|
248
250
|
if (this.importRealtime) {
|
|
249
251
|
this.realtimeSent.push({ autotest: autotestSnapshot, result });
|
|
@@ -259,6 +261,8 @@ class TestItEnvironment extends jest_environment_node_1.default {
|
|
|
259
261
|
catch (err) {
|
|
260
262
|
testit_js_commons_2.logger.error("Failed realtime send in Jest environment:", this.formatError(err));
|
|
261
263
|
}
|
|
264
|
+
// Keep sync-storage LastStatus fresh; otherwise Force Work X fires after ~60s.
|
|
265
|
+
await Promise.resolve(this.strategy.touchWorker?.()).catch(() => undefined);
|
|
262
266
|
}
|
|
263
267
|
else {
|
|
264
268
|
this.autotests.push(autotestSnapshot);
|
|
@@ -286,24 +290,15 @@ class TestItEnvironment extends jest_environment_node_1.default {
|
|
|
286
290
|
const afterEach = autotest.afterEach;
|
|
287
291
|
return includeAfterAll ? afterEach.concat(this.afterAllSteps) : afterEach;
|
|
288
292
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const teardownSteps = this.buildTeardownSteps(autotest, includeAfterAll);
|
|
292
|
-
testit_js_commons_2.logger.debug("[jest-env] sendRealtimePayload", {
|
|
293
|
-
externalId: autotest.externalId,
|
|
294
|
-
outcome: result.outcome,
|
|
295
|
-
includeAfterAll,
|
|
296
|
-
setupSteps: setupSteps.length,
|
|
297
|
-
teardownSteps: teardownSteps.length,
|
|
298
|
-
testSteps: autotest.testSteps.length,
|
|
299
|
-
});
|
|
300
|
-
const autotestPost = {
|
|
293
|
+
buildAutotestPost(autotest, setupSteps, teardownSteps) {
|
|
294
|
+
return {
|
|
301
295
|
externalId: autotest.externalId,
|
|
302
296
|
title: autotest.title,
|
|
303
297
|
name: autotest.name,
|
|
304
298
|
description: autotest.description,
|
|
305
299
|
links: autotest.links,
|
|
306
300
|
labels: autotest.labels,
|
|
301
|
+
layer: autotest.layer,
|
|
307
302
|
tags: autotest.tags,
|
|
308
303
|
namespace: autotest.namespace ?? testit_js_commons_1.Utils.getDir(this.testPath),
|
|
309
304
|
classname: autotest.classname ?? testit_js_commons_1.Utils.getFileName(this.testPath),
|
|
@@ -311,24 +306,34 @@ class TestItEnvironment extends jest_environment_node_1.default {
|
|
|
311
306
|
steps: autotest.testSteps,
|
|
312
307
|
teardown: teardownSteps,
|
|
313
308
|
externalKey: autotest.externalKey,
|
|
309
|
+
workItemIds: autotest.workItemIds,
|
|
314
310
|
};
|
|
311
|
+
}
|
|
312
|
+
async sendRealtimePayload(autotest, result, includeAfterAll) {
|
|
313
|
+
const setupSteps = this.buildSetupSteps(autotest);
|
|
314
|
+
const teardownSteps = this.buildTeardownSteps(autotest, includeAfterAll);
|
|
315
|
+
testit_js_commons_2.logger.debug("[jest-env] sendRealtimePayload", {
|
|
316
|
+
externalId: autotest.externalId,
|
|
317
|
+
outcome: result.outcome,
|
|
318
|
+
includeAfterAll,
|
|
319
|
+
setupSteps: setupSteps.length,
|
|
320
|
+
teardownSteps: teardownSteps.length,
|
|
321
|
+
testSteps: autotest.testSteps.length,
|
|
322
|
+
});
|
|
323
|
+
// Mutate the same AutotestResult instance that may be queued as deferred InProgress final.
|
|
324
|
+
// flushRealtimeTeardown patches teardownResults on this ref before strategy.teardown().
|
|
325
|
+
result.stepResults = autotest.testSteps;
|
|
326
|
+
result.setupResults = setupSteps;
|
|
327
|
+
result.teardownResults = teardownSteps;
|
|
328
|
+
result.parameters = autotest.parameters !== undefined ? (0, utils_1.mapParams)(autotest.parameters) : undefined;
|
|
329
|
+
const autotestPost = this.buildAutotestPost(autotest, setupSteps, teardownSteps);
|
|
330
|
+
// Avoid writing empty teardown to the Autotest card before afterAll is known —
|
|
331
|
+
// a full replace with [] would clear a previously uploaded afterAll until flush.
|
|
332
|
+
if (!includeAfterAll) {
|
|
333
|
+
autotestPost.teardown = undefined;
|
|
334
|
+
}
|
|
315
335
|
await this.strategy.loadAutotest(autotestPost, result.outcome);
|
|
316
|
-
await this.strategy.loadTestRun([
|
|
317
|
-
{
|
|
318
|
-
autoTestExternalId: autotestPost.externalId,
|
|
319
|
-
outcome: result.outcome,
|
|
320
|
-
startedOn: result.startedOn,
|
|
321
|
-
duration: result.duration,
|
|
322
|
-
attachments: result.attachments,
|
|
323
|
-
message: result.message,
|
|
324
|
-
links: result.links,
|
|
325
|
-
stepResults: autotest.testSteps,
|
|
326
|
-
traces: result.traces,
|
|
327
|
-
setupResults: setupSteps,
|
|
328
|
-
teardownResults: teardownSteps,
|
|
329
|
-
parameters: autotest.parameters !== undefined ? (0, utils_1.mapParams)(autotest.parameters) : undefined,
|
|
330
|
-
},
|
|
331
|
-
]);
|
|
336
|
+
await this.strategy.loadTestRun([result]);
|
|
332
337
|
}
|
|
333
338
|
/** afterAll hooks run after all tests; patch teardown when importRealtime is enabled. */
|
|
334
339
|
async flushRealtimeTeardown() {
|
|
@@ -344,13 +349,20 @@ class TestItEnvironment extends jest_environment_node_1.default {
|
|
|
344
349
|
tests: this.realtimeSent.length,
|
|
345
350
|
afterAllSteps: this.afterAllSteps.length,
|
|
346
351
|
});
|
|
352
|
+
// Patch shared result refs first so deferred final POST (strategy.teardown) includes afterAll.
|
|
353
|
+
for (const { autotest, result } of this.realtimeSent) {
|
|
354
|
+
result.setupResults = this.buildSetupSteps(autotest);
|
|
355
|
+
result.teardownResults = this.buildTeardownSteps(autotest, true);
|
|
356
|
+
}
|
|
347
357
|
for (const { autotest, result } of this.realtimeSent) {
|
|
348
358
|
try {
|
|
349
|
-
const setupSteps =
|
|
350
|
-
const teardownSteps =
|
|
359
|
+
const setupSteps = result.setupResults ?? [];
|
|
360
|
+
const teardownSteps = result.teardownResults ?? [];
|
|
351
361
|
if (setupSteps.length === 0 && teardownSteps.length === 0) {
|
|
352
362
|
continue;
|
|
353
363
|
}
|
|
364
|
+
const autotestPost = this.buildAutotestPost(autotest, setupSteps, teardownSteps);
|
|
365
|
+
await this.strategy.loadAutotest(autotestPost, result.outcome);
|
|
354
366
|
await this.strategy.updateSetupTeardown([
|
|
355
367
|
{
|
|
356
368
|
autoTestExternalId: autotest.externalId,
|
|
@@ -380,21 +392,7 @@ class TestItEnvironment extends jest_environment_node_1.default {
|
|
|
380
392
|
log("Mapping autotest %s", autotest.name);
|
|
381
393
|
const setupSteps = this.beforeAllSteps.concat(autotest.beforeEach);
|
|
382
394
|
const teardownSteps = autotest.afterEach.concat(this.afterAllSteps);
|
|
383
|
-
const autotestPost =
|
|
384
|
-
externalId: autotest.externalId,
|
|
385
|
-
title: autotest.title,
|
|
386
|
-
name: autotest.name,
|
|
387
|
-
description: autotest.description,
|
|
388
|
-
links: autotest.links,
|
|
389
|
-
labels: autotest.labels,
|
|
390
|
-
tags: autotest.tags,
|
|
391
|
-
namespace: autotest.namespace ?? testit_js_commons_1.Utils.getDir(this.testPath),
|
|
392
|
-
classname: autotest.classname ?? testit_js_commons_1.Utils.getFileName(this.testPath),
|
|
393
|
-
setup: setupSteps,
|
|
394
|
-
steps: autotest.testSteps,
|
|
395
|
-
teardown: teardownSteps,
|
|
396
|
-
externalKey: autotest.externalKey,
|
|
397
|
-
};
|
|
395
|
+
const autotestPost = this.buildAutotestPost(autotest, setupSteps, teardownSteps);
|
|
398
396
|
try {
|
|
399
397
|
await this.strategy.loadAutotest(autotestPost, result.outcome);
|
|
400
398
|
}
|
|
@@ -486,11 +484,23 @@ class TestItEnvironment extends jest_environment_node_1.default {
|
|
|
486
484
|
log("Setting labels to %s", this.autotestData.name);
|
|
487
485
|
this.autotestData.labels = labels.map((label) => ({ name: label }));
|
|
488
486
|
}
|
|
487
|
+
setLayer(layer) {
|
|
488
|
+
log("Setting layer to %s for %s", layer, this.autotestData.name);
|
|
489
|
+
this.autotestData.layer = layer;
|
|
490
|
+
}
|
|
489
491
|
setTags(tags) {
|
|
490
492
|
log("Setting tags to %s", this.autotestData.name);
|
|
491
493
|
this.autotestData.tags = tags;
|
|
492
494
|
}
|
|
495
|
+
setWorkItemId(globalId) {
|
|
496
|
+
log("Setting work item id to %s", this.autotestData.name);
|
|
497
|
+
this.autotestData.workItemIds = [globalId];
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* @deprecated Use workItemId with a single globalId instead.
|
|
501
|
+
*/
|
|
493
502
|
setWorkItems(workItems) {
|
|
503
|
+
testit_js_commons_2.logger.warn("workItemIds is deprecated. Use workItemId with a single globalId instead.");
|
|
494
504
|
log("Setting work items to %s", this.autotestData.name);
|
|
495
505
|
this.autotestData.workItemIds = workItems;
|
|
496
506
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testit-adapter-jest",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Jest adapter for Test IT",
|
|
5
5
|
"main": "dist/testitEnvironment.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"debug": "^4.3.4",
|
|
19
|
-
"testit-js-commons": "5.0
|
|
19
|
+
"testit-js-commons": "5.1.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/debug": "^4.1.7",
|
package/types.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ declare global {
|
|
|
6
6
|
displayName(name: string): void;
|
|
7
7
|
links(links: Link[]): void;
|
|
8
8
|
labels(labels: string[]): void;
|
|
9
|
+
layer(layer: string): void;
|
|
10
|
+
tags(tags: string[]): void;
|
|
11
|
+
workItemId(globalId: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use workItemId with a single globalId instead.
|
|
14
|
+
*/
|
|
9
15
|
workItemIds(workItemsIds: string[]): void;
|
|
10
16
|
params(params: any): void;
|
|
11
17
|
step(name: string, description?: string): void;
|