testit-adapter-jest 2.3.0 → 3.0.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 CHANGED
@@ -91,6 +91,23 @@ module.exports = {
91
91
 
92
92
  You can also specify options via cli arguments `jest --testEnvironment testit-adapter-jest --testEnvironmentOptions "{\"url\":\"URL\",\"privateToken\":\"USER_PRIVATE_TOKEN\",\"projectId\":\"PROJECT_ID\",\"configurationId\":\"CONFIGURATION_ID\",\"testRunId\":\"TEST_RUN_ID\",\"adapterMode\":ADAPTER_MODE,\"automaticCreationTestCases\":AUTOMATIC_CREATION_TEST_CASES,\"automaticUpdationLinksToTestCases\":AUTOMATIC_UPDATION_LINKS_TO_TEST_CASES}" --globalSetup testit-adapter-jest/dist/globalSetup.js --globalTeardown testit-adapter-jest/dist/globalTeardown.js`
93
93
 
94
+ #### Run with filter
95
+ To create filter by autotests you can use the Test IT CLI (use adapterMode 1 for run with filter):
96
+
97
+ ```
98
+ $ export TMS_TOKEN=<YOUR_TOKEN>
99
+ $ testit autotests_filter
100
+ --url https://tms.testit.software \
101
+ --configuration-id 5236eb3f-7c05-46f9-a609-dc0278896464 \
102
+ --testrun-id 6d4ac4b7-dd67-4805-b879-18da0b89d4a8 \
103
+ --framework jest \
104
+ --output tmp/filter.txt
105
+
106
+ $ export TMS_TEST_RUN_ID=6d4ac4b7-dd67-4805-b879-18da0b89d4a8
107
+ $ export TMS_ADAPTER_MODE=1
108
+
109
+ $ npx jest -t "$(cat tmp/filter.txt)"
110
+ ```
94
111
 
95
112
  ### Methods
96
113
 
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const testit_js_commons_1 = require("testit-js-commons");
4
4
  exports.default = async (globalConfig, projectConfig) => {
5
5
  const config = new testit_js_commons_1.ConfigComposer().compose(projectConfig.testEnvironmentOptions);
6
- const client = new testit_js_commons_1.Client(config);
7
- const strategy = testit_js_commons_1.StrategyFactory.create(client, config);
6
+ const strategy = testit_js_commons_1.StrategyFactory.create(config);
8
7
  await strategy.setup();
9
8
  const testRunId = await strategy.testRunId;
10
- globalThis.client = client;
11
- projectConfig.globals["testRunId"] = testRunId;
9
+ projectConfig.testEnvironmentOptions["testRunId"] = testRunId;
10
+ projectConfig.testEnvironmentOptions["adapterMode"] = 1;
12
11
  };
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = async (globalConfig, projectConfig) => {
4
- const testRunId = projectConfig.globals['testRunId'];
5
- if (!testRunId) {
6
- return console.error('Looks like globalSetup was not called');
7
- }
8
4
  try {
9
- await globalThis.client.testRuns.completeTestRun(testRunId);
5
+ await globalThis.strategy.teardown();
10
6
  }
11
7
  catch (err) {
12
8
  console.error('Failed to complete test run');
@@ -13,7 +13,7 @@ export default class TestItEnvironment extends NodeEnvironment {
13
13
  private autotests;
14
14
  private readonly testPath;
15
15
  private attachmentsQueue;
16
- private readonly client;
16
+ private readonly strategy;
17
17
  private readonly additions;
18
18
  constructor(jestConfig: JestEnvironmentConfig, jestContext: EnvironmentContext);
19
19
  setup(): Promise<void>;
@@ -51,6 +51,7 @@ export default class TestItEnvironment extends NodeEnvironment {
51
51
  setParams(params: any): void;
52
52
  setNameSpace(nameSpace: string): void;
53
53
  setClassName(className: string): void;
54
+ setExternalKey(externalKey: string): void;
54
55
  startStep(name: string, description?: string): void;
55
56
  generateExternalId(testName: string): string;
56
57
  }
@@ -34,12 +34,8 @@ class TestItEnvironment extends jest_environment_node_1.default {
34
34
  this.autotests = [];
35
35
  this.attachmentsQueue = [];
36
36
  const config = new testit_js_commons_1.ConfigComposer().compose(jestConfig.projectConfig.testEnvironmentOptions);
37
- const testRunId = jestConfig.projectConfig.globals["testRunId"];
38
- if (!testRunId || typeof testRunId !== "string") {
39
- throw new Error("Looks like globalSetup was not called");
40
- }
41
- this.client = new testit_js_commons_1.Client({ ...config, testRunId });
42
- this.additions = new testit_js_commons_1.Additions(this.client);
37
+ this.additions = new testit_js_commons_1.Additions(config);
38
+ this.strategy = testit_js_commons_1.StrategyFactory.create(config);
43
39
  this.testPath = (0, utils_1.excludePath)(jestContext.testPath, jestConfig.globalConfig.rootDir);
44
40
  }
45
41
  async setup() {
@@ -141,6 +137,7 @@ class TestItEnvironment extends jest_environment_node_1.default {
141
137
  this.currentType = "test";
142
138
  this.setDisplayName(test.name);
143
139
  this.setExternalId(this.generateExternalId(test.name));
140
+ this.setExternalKey(test.name);
144
141
  }
145
142
  finishTestCapture(test) {
146
143
  log("Finishing test capture %s", test.name);
@@ -191,14 +188,9 @@ class TestItEnvironment extends jest_environment_node_1.default {
191
188
  setup: setupSteps,
192
189
  steps: autotest.testSteps,
193
190
  teardown: teardownSteps,
194
- shouldCreateWorkItem: this.client.getConfig().automaticCreationTestCases,
191
+ externalKey: autotest.externalKey,
195
192
  };
196
- await this.client.autoTests.loadAutotest(autotestPost, result.outcome === "Passed");
197
- if (Array.isArray(autotest.workItemIds) && autotest.workItemIds.length > 0) {
198
- await this.client.autoTests
199
- .linkToWorkItems(autotest.externalId, autotest.workItemIds)
200
- .catch((err) => console.error("Failed to link work items.", err));
201
- }
193
+ await this.strategy.loadAutotest(autotestPost, result.outcome === "Passed");
202
194
  results.push({
203
195
  autoTestExternalId: autotestPost.externalId,
204
196
  outcome: result.outcome,
@@ -215,8 +207,7 @@ class TestItEnvironment extends jest_environment_node_1.default {
215
207
  });
216
208
  }
217
209
  log("Loading results");
218
- const testRunId = this.client.getConfig().testRunId;
219
- await this.client.testRuns.loadAutotests(testRunId, results);
210
+ await this.strategy.loadTestRun(results);
220
211
  }
221
212
  resetTest() {
222
213
  this.autotestData = emptyAutotestData();
@@ -289,6 +280,10 @@ class TestItEnvironment extends jest_environment_node_1.default {
289
280
  log("Setting className to %s", className);
290
281
  this.autotestData.classname = className;
291
282
  }
283
+ setExternalKey(externalKey) {
284
+ log("Setting externalKey to %s", externalKey);
285
+ this.autotestData.externalKey = externalKey;
286
+ }
292
287
  startStep(name, description) {
293
288
  log("Starting step %s", name);
294
289
  if (this.currentType !== "test" && this.currentType !== "step") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-adapter-jest",
3
- "version": "2.3.0",
3
+ "version": "3.0.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": "~2.3.0"
19
+ "testit-js-commons": "~3.0.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/debug": "^4.1.7",