testit-adapter-mocha 2.1.8 → 2.2.1

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
@@ -21,7 +21,7 @@ module.exports = {
21
21
 
22
22
  ## Configuration
23
23
 
24
- | Description | Property | Environment variable |
24
+ | Description | File property | Environment variable |
25
25
  |------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------|-----------------------------------|
26
26
  | Location of the TMS instance | url | TMS_URL |
27
27
  | API secret key <br/>[How to getting API secret key?](https://github.com/testit-tms/.github/tree/main/configuration#privatetoken) | privateToken | TMS_PRIVATE_TOKEN |
@@ -89,6 +89,26 @@ TMS_CONFIG_FILE=pathToAnotherConfigFile; #optional
89
89
  TMS_AUTOMATIC_CREATION_TEST_CASES=false; # or true, optional
90
90
  ```
91
91
 
92
+ #### Parallel run
93
+ To create and complete TestRun you can use the Test IT CLI (use adapterMode 1 for parallel run):
94
+
95
+ ```
96
+ $ export TMS_TOKEN=<YOUR_TOKEN>
97
+ $ testit testrun create
98
+ --url https://tms.testit.software \
99
+ --project-id 5236eb3f-7c05-46f9-a609-dc0278896464 \
100
+ --testrun-name "New test run" \
101
+ --output tmp/output.txt
102
+
103
+ $ export TMS_TEST_RUN_ID=$(cat tmp/output.txt)
104
+
105
+ $ npx mocha --parallel
106
+
107
+ $ testit testrun complete
108
+ --url https://tms.testit.software \
109
+ --testrun-id $(cat tmp/output.txt)
110
+ ```
111
+
92
112
  ## Usage
93
113
 
94
114
  Methods and properties can be used to specify information about autotest.
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const reporter_js_1 = require("./reporter.js");
4
+ module.exports = reporter_js_1.TmsReporter;
package/lib/reporter.d.ts CHANGED
@@ -1 +1,34 @@
1
+ import { reporters, Runner } from "mocha";
2
+ import { Attachment, Link } from "testit-js-commons";
3
+ import { ReporterOptions, Context, Test } from "./types";
4
+ import { ITestStep } from "./step";
5
+ declare const Reporter: typeof reporters.Base;
6
+ export declare class TmsReporter extends Reporter {
7
+ private readonly strategy;
8
+ private readonly additions;
9
+ private attachmentsQueue;
10
+ private autotestsQueue;
11
+ private autotestsForTestRun;
12
+ private currentType?;
13
+ private currentTest;
14
+ private currentStep;
15
+ constructor(runner: Runner, options: ReporterOptions);
16
+ private applyListeners;
17
+ onStartRun: () => void;
18
+ onEndRun: () => void;
19
+ private teardown;
20
+ clearContext(ctx: Context): void;
21
+ addMethods(context?: Context): void;
22
+ onStartTest(): void;
23
+ onEndTest(test: Test): void;
24
+ resetTest(test: Test): void;
25
+ addAttachments: (pathsOrContent: string | string[], fileName?: string) => Promise<Attachment[]>;
26
+ addLinks: (links: Link | Link[]) => void;
27
+ addMessage: (message: string) => void;
28
+ addSteps: (title: string, stepConstructor?: (step: ITestStep) => void) => void;
29
+ private _getNameSpace;
30
+ private _getClassName;
31
+ private _getOutcome;
32
+ private _getDuration;
33
+ }
1
34
  export {};
package/lib/reporter.js CHANGED
@@ -8,12 +8,17 @@ 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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.TmsReporter = void 0;
12
16
  const mocha_1 = require("mocha");
17
+ const deasync_promise_1 = __importDefault(require("deasync-promise"));
13
18
  const testit_js_commons_1 = require("testit-js-commons");
14
19
  const step_1 = require("./step");
15
20
  const utils_1 = require("./utils");
16
- const Reporter = mocha_1.reporters.List;
21
+ const Reporter = mocha_1.reporters.Base;
17
22
  const Events = mocha_1.Runner.constants;
18
23
  const emptyTest = () => ({
19
24
  autoTestExternalId: "",
@@ -33,27 +38,29 @@ const StateConstants = {
33
38
  STATE_PASSED: 'passed',
34
39
  STATE_PENDING: 'pending',
35
40
  };
36
- module.exports = class extends Reporter {
41
+ class TmsReporter extends Reporter {
37
42
  constructor(runner, options) {
43
+ var _a;
38
44
  super(runner, options);
39
45
  this.attachmentsQueue = [];
40
46
  this.autotestsQueue = [];
41
47
  this.autotestsForTestRun = [];
42
48
  this.currentTest = emptyTest();
43
49
  this.currentStep = emptyStep();
44
- this.onStartRun = () => __awaiter(this, void 0, void 0, function* () {
50
+ this.applyListeners = () => {
51
+ this.runner.on(Events.EVENT_RUN_BEGIN, () => this.onStartRun());
52
+ this.runner.on(Events.EVENT_RUN_END, () => this.onEndRun());
53
+ this.runner.on(Events.EVENT_TEST_BEGIN, (test) => this.addMethods(test.ctx));
54
+ this.runner.on(Events.EVENT_HOOK_BEGIN, (hook) => this.addMethods(hook.ctx));
55
+ this.runner.on(Events.EVENT_TEST_BEGIN, () => this.onStartTest());
56
+ this.runner.on(Events.EVENT_TEST_END, (test) => this.onEndTest(test));
57
+ };
58
+ this.onStartRun = () => {
45
59
  this.strategy.setup();
46
- });
47
- this.onEndRun = () => __awaiter(this, void 0, void 0, function* () {
48
- yield Promise.all(this.attachmentsQueue).catch((err) => {
49
- console.log("Error loading attachments. \n", err.body);
50
- });
51
- yield Promise.all(this.autotestsQueue);
52
- yield this.strategy.loadTestRun(this.autotestsForTestRun).catch((err) => {
53
- console.log("Error load test run. \n", err.body);
54
- });
55
- yield this.strategy.teardown();
56
- });
60
+ };
61
+ this.onEndRun = () => {
62
+ (0, deasync_promise_1.default)(this.teardown());
63
+ };
57
64
  this.addAttachments = (pathsOrContent, fileName) => {
58
65
  const target = this.currentType === "test" ? this.currentTest : this.currentStep;
59
66
  const promise = typeof pathsOrContent === "string"
@@ -101,12 +108,24 @@ module.exports = class extends Reporter {
101
108
  const client = new testit_js_commons_1.Client(config);
102
109
  this.strategy = testit_js_commons_1.StrategyFactory.create(client, config);
103
110
  this.additions = new testit_js_commons_1.Additions(client);
104
- this.runner.on(Events.EVENT_RUN_BEGIN, () => this.onStartRun());
105
- this.runner.on(Events.EVENT_RUN_END, () => this.onEndRun());
106
- this.runner.on(Events.EVENT_TEST_BEGIN, (test) => this.addMethods(test.ctx));
107
- this.runner.on(Events.EVENT_HOOK_BEGIN, (hook) => this.addMethods(hook.ctx));
108
- this.runner.on(Events.EVENT_TEST_BEGIN, () => this.onStartTest());
109
- this.runner.on(Events.EVENT_TEST_END, (test) => this.onEndTest(test));
111
+ if (options.parallel) {
112
+ options.require = [...((_a = options.require) !== null && _a !== void 0 ? _a : []), (0, utils_1.resolveParallelModeSetupFile)()];
113
+ }
114
+ else {
115
+ this.applyListeners();
116
+ }
117
+ }
118
+ teardown() {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ yield Promise.all(this.attachmentsQueue).catch((err) => {
121
+ console.log("Error loading attachments. \n", err.body);
122
+ });
123
+ yield Promise.all(this.autotestsQueue);
124
+ yield this.strategy.loadTestRun(this.autotestsForTestRun).catch((err) => {
125
+ console.log("Error load test run. \n", err.body);
126
+ });
127
+ yield this.strategy.teardown();
128
+ });
110
129
  }
111
130
  clearContext(ctx) {
112
131
  ctx.externalId = undefined;
@@ -200,4 +219,6 @@ module.exports = class extends Reporter {
200
219
  ? Date.now() - this.currentTest.startedOn.getTime()
201
220
  : 0;
202
221
  }
203
- };
222
+ }
223
+ exports.TmsReporter = TmsReporter;
224
+ ;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // @ts-ignore
7
+ const parallel_buffered_js_1 = __importDefault(require("mocha/lib/nodejs/reporters/parallel-buffered.js"));
8
+ const reporter_js_1 = require("./reporter.js");
9
+ const originalCreateListeners = parallel_buffered_js_1.default.prototype.createListeners;
10
+ parallel_buffered_js_1.default.prototype.createListeners = function (runner) {
11
+ new reporter_js_1.TmsReporter(runner, this.options);
12
+ return originalCreateListeners.call(this, runner);
13
+ };
package/lib/utils.d.ts CHANGED
@@ -8,3 +8,4 @@ export declare function extractHooks(suite?: Suite): {
8
8
  afterEach: Step[];
9
9
  beforeEach: Step[];
10
10
  };
11
+ export declare const resolveParallelModeSetupFile: () => string;
package/lib/utils.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractHooks = exports.hookToStep = void 0;
3
+ exports.resolveParallelModeSetupFile = exports.extractHooks = exports.hookToStep = void 0;
4
+ const path_1 = require("path");
4
5
  function hookToStep(hook) {
5
6
  var _a;
6
7
  return {
@@ -23,3 +24,5 @@ function extractHooks(suite) {
23
24
  };
24
25
  }
25
26
  exports.extractHooks = extractHooks;
27
+ const resolveParallelModeSetupFile = () => (0, path_1.join)(__dirname, `setupTmsMochaParallel${(0, path_1.extname)(__filename)}`);
28
+ exports.resolveParallelModeSetupFile = resolveParallelModeSetupFile;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "testit-adapter-mocha",
3
- "version": "2.1.8",
3
+ "version": "2.2.1",
4
4
  "description": "Mocha adapter for Test IT",
5
- "main": "lib/reporter.js",
5
+ "main": "lib/index.js",
6
6
  "types": "lib/types.d.ts",
7
7
  "scripts": {
8
8
  "prebuild": "npm --prefix ../testit-js-commons run build && npm link ../testit-js-commons",
@@ -15,6 +15,7 @@
15
15
  },
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
+ "@types/deasync-promise": "^1.0.2",
18
19
  "@types/mocha": "^10.0.1",
19
20
  "@types/node": "^20.2.4",
20
21
  "@types/request": "^2.48.8",
@@ -25,7 +26,8 @@
25
26
  },
26
27
  "dependencies": {
27
28
  "mocha": "^10.2.0",
28
- "testit-js-commons": "~2.1.8"
29
+ "deasync-promise": "^1.0.1",
30
+ "testit-js-commons": "~2.2.1"
29
31
  },
30
32
  "files": [
31
33
  "lib"