testit-adapter-jest 1.1.2 → 1.1.4

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
@@ -1,198 +1,173 @@
1
- # Test IT TMS adapters for Jest
2
- ![Test IT](https://raw.githubusercontent.com/testit-tms/adapters-js/master/images/banner.png)
3
-
4
- ## Getting Started
5
-
6
- ### Compatibility
7
-
8
- | Test IT | Adapter |
9
- |---------|---------|
10
- | 3.5 | 1.0 |
11
- | 4.0 | 1.1 |
12
-
13
- ### Installation
14
- ```
15
- npm install testit-adapter-jest
16
- ```
17
-
18
- ## Usage
19
-
20
- ### API client
21
-
22
- To use adapter you need to install `testit-api-client`:
23
- ```
24
- npm install testit-api-client
25
- ```
26
-
27
- ### Configuration
28
-
29
- #### File
30
-
31
- 1. You need to set custom jest test environment, setup and teardown in `jest.config.js`.
32
-
33
- ```js
34
- module.exports = {
35
- testEnvironment: 'testit-adapter-jest',
36
- globalSetup: 'testit-adapter-jest/dist/globalSetup.js',
37
- globalTeardown: 'testit-adapter-jest/dist/globalTeardown.js',
38
- testEnvironmentOptions: {
39
- url: '<url>',
40
- privateToken: '<token>',
41
- projectId: '<id>',
42
- configurationId: '<id>',
43
- testRunId: '<optional id>',
44
- },
45
- };
46
- ```
47
-
48
- 2. You also can extract environment configuration to external config and launch tests with `jest --config ./testit.jest.config.js`.
49
-
50
- ```js
51
- // testit.jest.config.js
52
- const defaultConfig = require('./jest.config');
53
-
54
- module.exports = {
55
- ...defaultConfig,
56
- testEnvironment: 'testit-adapter-jest',
57
- globalSetup: 'testit-adapter-jest/dist/globalSetup.js',
58
- globalTeardown: 'testit-adapter-jest/dist/globalTeardown.js',
59
- testEnvironmentOptions: {
60
- url: '<url>',
61
- privateToken: '<token>',
62
- projectId: '<id>',
63
- configurationId: '<id>',
64
- testRunId: '<optional id>',
65
- adapterMode: <optional>,
66
- automaticCreationTestCases: <optional boolean>
67
- },
68
- };
69
- ```
70
-
71
- 3. Fill parameters with your configuration, where:
72
- * `url` - location of the TMS instance
73
-
74
- * `privateToken` - API secret key
75
- 1. go to the https://{DOMAIN}/user-profile profile
76
- 2. copy the API secret key
77
-
78
- * `projectId` - ID of project in TMS instance.
79
-
80
- 1. create a project
81
- 2. open DevTools -> network
82
- 3. go to the project https://{DOMAIN}/projects/{PROJECT_ID}/tests
83
- 4. GET-request project, Preview tab, copy id field
84
-
85
- * `configurationId` - ID of configuration in TMS instance.
86
-
87
- 1. create a project
88
- 2. open DevTools -> network
89
- 3. go to the project https://{DOMAIN}/projects/{PROJECT_ID}/tests
90
- 4. GET-request configurations, Preview tab, copy id field
91
-
92
- * `testRunId` - id of the created test run in TMS instance. `testRunId` is optional. If it is not provided, it is created automatically.
93
-
94
- * `testRunName` - parameter for specifying the name of test run in TMS instance. `testRunName` is optional. If it is not provided, it is created automatically.
95
-
96
- * `adapterMode` - adapter mode. Default value - 0. The adapter supports following modes:
97
- * 0 - in this mode, the adapter filters tests by test run ID and configuration ID, and sends the results to the test run.
98
- * 1 - in this mode, the adapter sends all results to the test run without filtering.
99
- * 2 - in this mode, the adapter creates a new test run and sends results to the new test run.
100
-
101
- * `automaticCreationTestCases` - mode of automatic creation test cases. Default value - false. The adapter supports following modes:
102
- * true - in this mode, the adapter will create a test case linked to the created autotest (not to the updated autotest).
103
- * false - in this mode, the adapter will not create a test case.
104
-
105
- #### Command line
106
-
107
- You can also specify options via cli arguments `jest --testEnvironment testit-adapter-jest --testEnvironmentOptions "{\"url\":\"<url>\",\"privateToken\":\"<token>\",\"projectId\":\"<id>\",\"configurationId\":\"<id>\",\"testRunId\":\"<optional id>\",\"automaticCreationTestCases\": <optional boolean>}" --globalSetup testit-adapter-jest/dist/globalSetup.js --globalTeardown testit-adapter-jest/dist/globalTeardown.js`
108
-
109
-
110
- ### Methods
111
-
112
- Methods can be used to specify information about autotest.
113
-
114
- Description of metadata methods:
115
- - `testit.workItemIds` - linking an autotest to a test case
116
- - `testit.displayName` - name of the autotest in the Test IT system (can be replaced with documentation strings)
117
- - `testit.externalId` - ID of the autotest within the project in the Test IT System
118
- - `testit.title` - title in the autotest card
119
- - `testit.description` - description in the autotest card
120
- - `testit.labels` - tags in the work item
121
- - `testit.link` - links in the autotest card
122
-
123
- Description of methods:
124
- - `testit.addLinks` - links in the autotest result
125
- - `testit.addAttachments` - uploading files in the autotest result
126
- - `testit.addMessage` - information about autotest in the autotest result
127
-
128
- ### Examples
129
-
130
- #### Simple test
131
- ```js
132
- test('All annotations', () => {
133
- testit.externalId('all_annotations');
134
- testit.displayName('All annotations');
135
- testit.title('All annotations title');
136
- testit.description('Test with all annotations');
137
- testit.labels(['label1', 'label2']);
138
-
139
- testit.addMessage('This is a message');
140
- testit.addLinks([
141
- {
142
- url: 'https://www.google.com',
143
- title: 'Google',
144
- description: 'This is a link to Google',
145
- type: 'Related',
146
- },
147
- ]);
148
-
149
- testit.addAttachments([join(__dirname, 'attachment1.txt')]);
150
- testit.addAttachments('This is a custom attachment', 'custom.txt');
151
-
152
- expect(1).toBe(1);
153
- });
154
- ```
155
-
156
- #### Parameterized test
157
- ```js
158
- test.each([1, 2, 3, 4])('Primitive params', (number) => {
159
- testit.params(number);
160
- expect(number).toBe(number);
161
- });
162
-
163
- test.each([
164
- {
165
- a: 1,
166
- b: 2,
167
- sum: 3,
168
- },
169
- {
170
- a: 2,
171
- b: 3,
172
- sum: 5,
173
- },
174
- {
175
- a: 4,
176
- b: 3,
177
- sum: 5,
178
- }
179
- ])('Object params', (params) => {
180
- testit.params(params);
181
- expect(params.a + params.b).toBe(params.sum);
182
- });
183
- ```
184
-
185
-
186
- # Contributing
187
-
188
- You can help to develop the project. Any contributions are **greatly appreciated**.
189
-
190
- * If you have suggestions for adding or removing projects, feel free to [open an issue](https://github.com/testit-tms/adapters-js/issues/new) to discuss it, or directly create a pull request after you edit the *README.md* file with necessary changes.
191
- * Please make sure you check your spelling and grammar.
192
- * Create individual PR for each suggestion.
193
- * Please also read through the [Code Of Conduct](https://github.com/testit-tms/adapters-js/blob/master/CODE_OF_CONDUCT.md) before posting your first idea as well.
194
-
195
- # License
196
-
197
- Distributed under the Apache-2.0 License. See [LICENSE](https://github.com/testit-tms/adapters-js/blob/master/LICENSE.md) for more information.
198
-
1
+ # Test IT TMS adapters for Jest
2
+ ![Test IT](https://raw.githubusercontent.com/testit-tms/adapters-js/master/images/banner.png)
3
+
4
+ ## Getting Started
5
+
6
+ ### Installation
7
+ ```
8
+ npm install testit-adapter-jest
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### API client
14
+
15
+ To use adapter you need to install `testit-api-client`:
16
+ ```
17
+ npm install testit-api-client
18
+ ```
19
+
20
+ ### Configuration
21
+
22
+ | Description | Property | Environment variable | CLI argument |
23
+ |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------|-----------------------------------|-------------------------------|
24
+ | Location of the TMS instance | url | TMS_URL | tmsUrl |
25
+ | API secret key [How to getting API secret key?](https://github.com/testit-tms/.github/tree/main/configuration#privatetoken) | privateToken | TMS_PRIVATE_TOKEN | tmsPrivateToken |
26
+ | ID of project in TMS instance [How to getting project ID?](https://github.com/testit-tms/.github/tree/main/configuration#projectid) | projectId | TMS_PROJECT_ID | tmsProjectId |
27
+ | ID of configuration in TMS instance [How to getting configuration ID?](https://github.com/testit-tms/.github/tree/main/configuration#configurationid) | configurationId | TMS_CONFIGURATION_ID | tmsConfigurationId |
28
+ | ID of the created test run in TMS instance.<br/>It's necessary for **adapterMode** 0 or 1 | testRunId | TMS_TEST_RUN_ID | tmsTestRunId |
29
+ | Parameter for specifying the name of test run in TMS instance (**It's optional**). If it is not provided, it is created automatically | testRunName | TMS_TEST_RUN_NAME | tmsTestRunName |
30
+ | Adapter mode. Default value - 0. The adapter supports following modes:<br/>0 - in this mode, the adapter filters tests by test run ID and configuration ID, and sends the results to the test run<br/>1 - in this mode, the adapter sends all results to the test run without filtering<br/>2 - in this mode, the adapter creates a new test run and sends results to the new test run | adapterMode | TMS_ADAPTER_MODE | tmsAdapterMode |
31
+ | It enables/disables certificate validation (**It's optional**). Default value - true | certValidation | TMS_CERT_VALIDATION | tmsCertValidation |
32
+ | Mode of automatic creation test cases (**It's optional**). Default value - false. The adapter supports following modes:<br/>true - in this mode, the adapter will create a test case linked to the created autotest (not to the updated autotest)<br/>false - in this mode, the adapter will not create a test case | automaticCreationTestCases | TMS_AUTOMATIC_CREATION_TEST_CASES | tmsAutomaticCreationTestCases |
33
+
34
+ #### File
35
+
36
+ 1. You need to set custom jest test environment, setup and teardown in `jest.config.js`.
37
+
38
+ ```js
39
+ module.exports = {
40
+ testEnvironment: 'testit-adapter-jest',
41
+ globalSetup: 'testit-adapter-jest/dist/globalSetup.js',
42
+ globalTeardown: 'testit-adapter-jest/dist/globalTeardown.js',
43
+ testEnvironmentOptions: {
44
+ url: 'URL',
45
+ privateToken: 'USER_PRIVATE_TOKEN',
46
+ projectId: 'PROJECT_ID',
47
+ configurationId: 'CONFIGURATION_ID',
48
+ testRunId: 'TEST_RUN_ID',
49
+ adapterMode: ADAPTER_MODE,
50
+ automaticCreationTestCases: AUTOMATIC_CREATION_TEST_CASES
51
+ },
52
+ };
53
+ ```
54
+
55
+ 2. You also can extract environment configuration to external config and launch tests with `jest --config ./testit.jest.config.js`.
56
+
57
+ ```js
58
+ // testit.jest.config.js
59
+ const defaultConfig = require('./jest.config');
60
+
61
+ module.exports = {
62
+ ...defaultConfig,
63
+ testEnvironment: 'testit-adapter-jest',
64
+ globalSetup: 'testit-adapter-jest/dist/globalSetup.js',
65
+ globalTeardown: 'testit-adapter-jest/dist/globalTeardown.js',
66
+ testEnvironmentOptions: {
67
+ url: 'URL',
68
+ privateToken: 'USER_PRIVATE_TOKEN',
69
+ projectId: 'PROJECT_ID',
70
+ configurationId: 'CONFIGURATION_ID',
71
+ testRunId: 'TEST_RUN_ID',
72
+ adapterMode: ADAPTER_MODE,
73
+ automaticCreationTestCases: AUTOMATIC_CREATION_TEST_CASES
74
+ },
75
+ };
76
+ ```
77
+
78
+ #### Command line
79
+
80
+ 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}" --globalSetup testit-adapter-jest/dist/globalSetup.js --globalTeardown testit-adapter-jest/dist/globalTeardown.js`
81
+
82
+
83
+ ### Methods
84
+
85
+ Methods can be used to specify information about autotest.
86
+
87
+ Description of metadata methods:
88
+ - `testit.workItemIds` - linking an autotest to a test case
89
+ - `testit.displayName` - name of the autotest in the Test IT system (can be replaced with documentation strings)
90
+ - `testit.externalId` - ID of the autotest within the project in the Test IT System
91
+ - `testit.title` - title in the autotest card
92
+ - `testit.description` - description in the autotest card
93
+ - `testit.labels` - tags in the work item
94
+ - `testit.link` - links in the autotest card
95
+ - `testit.nameSpace` - directory in the TMS system (default - directory's name of test)
96
+ - `testit.className` - subdirectory in the TMS system (default - file's name of test)
97
+
98
+ Description of methods:
99
+ - `testit.addLinks` - links in the autotest result
100
+ - `testit.addAttachments` - uploading files in the autotest result
101
+ - `testit.addMessage` - information about autotest in the autotest result
102
+
103
+ ### Examples
104
+
105
+ #### Simple test
106
+ ```js
107
+ test('All annotations', () => {
108
+ testit.externalId('all_annotations');
109
+ testit.displayName('All annotations');
110
+ testit.title('All annotations title');
111
+ testit.description('Test with all annotations');
112
+ testit.labels(['label1', 'label2']);
113
+
114
+ testit.addMessage('This is a message');
115
+ testit.addLinks([
116
+ {
117
+ url: 'https://www.google.com',
118
+ title: 'Google',
119
+ description: 'This is a link to Google',
120
+ type: 'Related',
121
+ },
122
+ ]);
123
+
124
+ testit.addAttachments([join(__dirname, 'attachment1.txt')]);
125
+ testit.addAttachments('This is a custom attachment', 'custom.txt');
126
+
127
+ expect(1).toBe(1);
128
+ });
129
+ ```
130
+
131
+ #### Parameterized test
132
+ ```js
133
+ test.each([1, 2, 3, 4])('Primitive params', (number) => {
134
+ testit.params(number);
135
+ expect(number).toBe(number);
136
+ });
137
+
138
+ test.each([
139
+ {
140
+ a: 1,
141
+ b: 2,
142
+ sum: 3,
143
+ },
144
+ {
145
+ a: 2,
146
+ b: 3,
147
+ sum: 5,
148
+ },
149
+ {
150
+ a: 4,
151
+ b: 3,
152
+ sum: 5,
153
+ }
154
+ ])('Object params', (params) => {
155
+ testit.params(params);
156
+ expect(params.a + params.b).toBe(params.sum);
157
+ });
158
+ ```
159
+
160
+
161
+ # Contributing
162
+
163
+ You can help to develop the project. Any contributions are **greatly appreciated**.
164
+
165
+ * If you have suggestions for adding or removing projects, feel free to [open an issue](https://github.com/testit-tms/adapters-js/issues/new) to discuss it, or directly create a pull request after you edit the *README.md* file with necessary changes.
166
+ * Please make sure you check your spelling and grammar.
167
+ * Create individual PR for each suggestion.
168
+ * Please also read through the [Code Of Conduct](https://github.com/testit-tms/adapters-js/blob/master/CODE_OF_CONDUCT.md) before posting your first idea as well.
169
+
170
+ # License
171
+
172
+ Distributed under the Apache-2.0 License. See [LICENSE](https://github.com/testit-tms/adapters-js/blob/master/LICENSE.md) for more information.
173
+
package/dist/config.d.ts CHANGED
@@ -1 +1 @@
1
- export type AdapterMode = 0 | 1 | 2;
1
+ export type AdapterMode = 0 | 1 | 2;
package/dist/config.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/debug.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import d from 'debug';
2
- export declare const debug: d.Debugger;
1
+ import d from 'debug';
2
+ export declare const debug: d.Debugger;
package/dist/debug.js CHANGED
@@ -1,8 +1,8 @@
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
- exports.debug = void 0;
7
- const debug_1 = __importDefault(require("debug"));
8
- exports.debug = (0, debug_1.default)('testit');
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
+ exports.debug = void 0;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ exports.debug = (0, debug_1.default)('testit');
@@ -1,3 +1,3 @@
1
- import { Config } from '@jest/reporters';
2
- declare const _default: (globalConfig: Config.GlobalConfig, projectConfig: Config.ProjectConfig) => Promise<void>;
3
- export default _default;
1
+ import { Config } from '@jest/reporters';
2
+ declare const _default: (globalConfig: Config.GlobalConfig, projectConfig: Config.ProjectConfig) => Promise<void>;
3
+ export default _default;
@@ -1,35 +1,35 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const testClient_1 = require("./testClient");
4
- const utils_1 = require("./utils");
5
- exports.default = async (globalConfig, projectConfig) => {
6
- const adapterMode = projectConfig.testEnvironmentOptions?.adapterMode ?? 0;
7
- const automaticCreationTestCases = projectConfig.testEnvironmentOptions?.automaticCreationTestCases ?? false;
8
- let testRunId;
9
- try {
10
- switch (adapterMode) {
11
- case 0:
12
- case 1: {
13
- testRunId = projectConfig.testEnvironmentOptions?.testRunId;
14
- if (!testRunId) {
15
- throw new Error('testRunId is required when mode is 1');
16
- }
17
- globalThis.testClient = new testClient_1.TestClient(projectConfig.testEnvironmentOptions);
18
- break;
19
- }
20
- case 2: {
21
- globalThis.testClient = new testClient_1.TestClient(projectConfig.testEnvironmentOptions);
22
- testRunId = await globalThis.testClient.createTestRun();
23
- break;
24
- }
25
- default:
26
- throw new Error(`Unknown adapter mode ${adapterMode}`);
27
- }
28
- }
29
- catch (err) {
30
- console.error('Failed to setup', (0, utils_1.formatError)(err));
31
- process.exit(1);
32
- }
33
- projectConfig.globals['testRunId'] = testRunId;
34
- projectConfig.globals['automaticCreationTestCases'] = automaticCreationTestCases;
35
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const testClient_1 = require("./testClient");
4
+ const utils_1 = require("./utils");
5
+ exports.default = async (globalConfig, projectConfig) => {
6
+ const adapterMode = projectConfig.testEnvironmentOptions?.adapterMode ?? 0;
7
+ const automaticCreationTestCases = projectConfig.testEnvironmentOptions?.automaticCreationTestCases ?? false;
8
+ let testRunId;
9
+ try {
10
+ switch (adapterMode) {
11
+ case 0:
12
+ case 1: {
13
+ testRunId = projectConfig.testEnvironmentOptions?.testRunId;
14
+ if (!testRunId) {
15
+ throw new Error('testRunId is required when mode is 1');
16
+ }
17
+ globalThis.testClient = new testClient_1.TestClient(projectConfig.testEnvironmentOptions);
18
+ break;
19
+ }
20
+ case 2: {
21
+ globalThis.testClient = new testClient_1.TestClient(projectConfig.testEnvironmentOptions);
22
+ testRunId = await globalThis.testClient.createTestRun();
23
+ break;
24
+ }
25
+ default:
26
+ throw new Error(`Unknown adapter mode ${adapterMode}`);
27
+ }
28
+ }
29
+ catch (err) {
30
+ console.error('Failed to setup', (0, utils_1.formatError)(err));
31
+ process.exit(1);
32
+ }
33
+ projectConfig.globals['testRunId'] = testRunId;
34
+ projectConfig.globals['automaticCreationTestCases'] = automaticCreationTestCases;
35
+ };
@@ -1,3 +1,3 @@
1
- import { Config } from '@jest/reporters';
2
- declare const _default: (globalConfig: Config.GlobalConfig, projectConfig: Config.ProjectConfig) => Promise<void>;
3
- export default _default;
1
+ import { Config } from '@jest/reporters';
2
+ declare const _default: (globalConfig: Config.GlobalConfig, projectConfig: Config.ProjectConfig) => Promise<void>;
3
+ export default _default;
@@ -1,16 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("./utils");
4
- exports.default = async (globalConfig, projectConfig) => {
5
- const testRunId = projectConfig.globals['testRunId'];
6
- if (!testRunId) {
7
- console.error('Looks like globalSetup was not called');
8
- return;
9
- }
10
- try {
11
- await globalThis.testClient.completeTestRun();
12
- }
13
- catch (err) {
14
- console.error('Failed to complete test run', (0, utils_1.formatError)(err));
15
- }
16
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("./utils");
4
+ exports.default = async (globalConfig, projectConfig) => {
5
+ const testRunId = projectConfig.globals['testRunId'];
6
+ if (!testRunId) {
7
+ console.error('Looks like globalSetup was not called');
8
+ return;
9
+ }
10
+ try {
11
+ await globalThis.testClient.completeTestRun();
12
+ }
13
+ catch (err) {
14
+ console.error('Failed to complete test run', (0, utils_1.formatError)(err));
15
+ }
16
+ };
package/dist/mappers.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { AttachmentPut, AttachmentPutModelAutotestStepResults, AutotestStep, Parameters } from 'testit-api-client';
2
- import { StepData } from './types';
3
- export declare function mapDate(date: number): string;
4
- export declare function mapStep(step: StepData): AutotestStep;
5
- export declare function mapParams(params: any): Parameters;
6
- export declare function mapStepResult(step: StepData): AttachmentPutModelAutotestStepResults;
7
- export declare function mapAttachments(attachments: string[]): AttachmentPut[];
1
+ import { AttachmentPut, AttachmentPutModelAutotestStepResults, AutotestStep, Parameters } from 'testit-api-client';
2
+ import { StepData } from './types';
3
+ export declare function mapDate(date: number): string;
4
+ export declare function mapStep(step: StepData): AutotestStep;
5
+ export declare function mapParams(params: any): Parameters;
6
+ export declare function mapStepResult(step: StepData): AttachmentPutModelAutotestStepResults;
7
+ export declare function mapAttachments(attachments: string[]): AttachmentPut[];