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/dist/mappers.js CHANGED
@@ -1,46 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapAttachments = exports.mapStepResult = exports.mapParams = exports.mapStep = exports.mapDate = void 0;
4
- function mapDate(date) {
5
- return new Date(date).toISOString();
6
- }
7
- exports.mapDate = mapDate;
8
- function mapStep(step) {
9
- return {
10
- title: step.title,
11
- description: step.description,
12
- };
13
- }
14
- exports.mapStep = mapStep;
15
- function mapParams(params) {
16
- switch (typeof params) {
17
- case 'string':
18
- case 'bigint':
19
- case 'number':
20
- case 'boolean':
21
- return { value: params.toString() };
22
- case 'object':
23
- if (params === null) {
24
- return {};
25
- }
26
- return Object.keys(params).reduce((acc, key) => {
27
- acc[key] = params[key].toString();
28
- return acc;
29
- }, {});
30
- default:
31
- return {};
32
- }
33
- }
34
- exports.mapParams = mapParams;
35
- function mapStepResult(step) {
36
- return {
37
- title: step.title,
38
- description: step.description,
39
- attachments: mapAttachments(step.attachments),
40
- };
41
- }
42
- exports.mapStepResult = mapStepResult;
43
- function mapAttachments(attachments) {
44
- return attachments.map((id) => ({ id }));
45
- }
46
- exports.mapAttachments = mapAttachments;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapAttachments = exports.mapStepResult = exports.mapParams = exports.mapStep = exports.mapDate = void 0;
4
+ function mapDate(date) {
5
+ return new Date(date).toISOString();
6
+ }
7
+ exports.mapDate = mapDate;
8
+ function mapStep(step) {
9
+ return {
10
+ title: step.title,
11
+ description: step.description,
12
+ };
13
+ }
14
+ exports.mapStep = mapStep;
15
+ function mapParams(params) {
16
+ switch (typeof params) {
17
+ case 'string':
18
+ case 'bigint':
19
+ case 'number':
20
+ case 'boolean':
21
+ return { value: params.toString() };
22
+ case 'object':
23
+ if (params === null) {
24
+ return {};
25
+ }
26
+ return Object.keys(params).reduce((acc, key) => {
27
+ acc[key] = params[key].toString();
28
+ return acc;
29
+ }, {});
30
+ default:
31
+ return {};
32
+ }
33
+ }
34
+ exports.mapParams = mapParams;
35
+ function mapStepResult(step) {
36
+ return {
37
+ title: step.title,
38
+ description: step.description,
39
+ attachments: mapAttachments(step.attachments),
40
+ };
41
+ }
42
+ exports.mapStepResult = mapStepResult;
43
+ function mapAttachments(attachments) {
44
+ return attachments.map((id) => ({ id }));
45
+ }
46
+ exports.mapAttachments = mapAttachments;
@@ -1,18 +1,18 @@
1
- import { AutotestPost, AutotestResultsForTestRun, ClientConfig } from 'testit-api-client';
2
- export declare class TestClient {
3
- constructor(clientConfig?: Partial<ClientConfig>);
4
- private client;
5
- private _testRunId;
6
- get testRunId(): string;
7
- get projectId(): string;
8
- get configurationId(): string;
9
- createTestRun(): Promise<string>;
10
- startTestRun(): Promise<void>;
11
- completeTestRun(): Promise<void>;
12
- loadAutotest(autotestPost: AutotestPost): Promise<string>;
13
- loadPassedAutotest(autotest: AutotestPost): Promise<void>;
14
- getAutotestId(externalId: string): Promise<string>;
15
- linkWorkItem(externalId: string, workItemId: string): Promise<void>;
16
- loadAutotestResults(results: AutotestResultsForTestRun[]): Promise<void>;
17
- uploadAttachments(attachments: string[]): Promise<string[]>;
18
- }
1
+ import { AutotestPost, AutotestResultsForTestRun, ClientConfig } from 'testit-api-client';
2
+ export declare class TestClient {
3
+ constructor(clientConfig?: Partial<ClientConfig>);
4
+ private client;
5
+ private _testRunId;
6
+ get testRunId(): string;
7
+ get projectId(): string;
8
+ get configurationId(): string;
9
+ createTestRun(): Promise<string>;
10
+ startTestRun(): Promise<void>;
11
+ completeTestRun(): Promise<void>;
12
+ loadAutotest(autotestPost: AutotestPost): Promise<string>;
13
+ loadPassedAutotest(autotest: AutotestPost): Promise<void>;
14
+ getAutotestId(externalId: string): Promise<string>;
15
+ linkWorkItem(externalId: string, workItemId: string): Promise<void>;
16
+ loadAutotestResults(results: AutotestResultsForTestRun[]): Promise<void>;
17
+ uploadAttachments(attachments: string[]): Promise<string[]>;
18
+ }
@@ -1,128 +1,128 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TestClient = void 0;
4
- const testit_api_client_1 = require("testit-api-client");
5
- const debug_1 = require("./debug");
6
- const utils_1 = require("./utils");
7
- const log = debug_1.debug.extend('client');
8
- class TestClient {
9
- constructor(clientConfig = {}) {
10
- this.client = new testit_api_client_1.Client(clientConfig);
11
- this._testRunId = clientConfig.testRunId;
12
- }
13
- get testRunId() {
14
- if (this._testRunId === undefined) {
15
- throw new Error('Test run id is not set');
16
- }
17
- return this._testRunId;
18
- }
19
- get projectId() {
20
- return this.client.getConfig().projectId;
21
- }
22
- get configurationId() {
23
- return this.client.getConfig().configurationId;
24
- }
25
- async createTestRun() {
26
- const { projectId, testRunId } = this.client.getConfig();
27
- if (testRunId === undefined) {
28
- log('Test run id is not provided, creating test run for project %s', projectId);
29
- this._testRunId = await this.client
30
- .createTestRun({ projectId })
31
- .then((testRun) => testRun.id);
32
- }
33
- else {
34
- log('Using provided test run id %s', testRunId);
35
- this._testRunId = testRunId;
36
- }
37
- log('Starting test run %s', this.testRunId);
38
- return this.testRunId;
39
- }
40
- async startTestRun() {
41
- log('Starting test run %s', this.testRunId);
42
- await this.client.startTestRun(this.testRunId);
43
- }
44
- async completeTestRun() {
45
- log('Completing test run %s', this.testRunId);
46
- const testRun = await this.client.getTestRun(this.testRunId);
47
- if (testRun.stateName === 'InProgress') {
48
- await this.client.completeTestRun(this.testRunId);
49
- }
50
- }
51
- async loadAutotest(autotestPost) {
52
- try {
53
- log('Creating autotest %o', autotestPost);
54
- const { id } = await this.client.createAutotest(autotestPost);
55
- return id;
56
- }
57
- catch (err) {
58
- const axiosError = err;
59
- if (axiosError.response?.status === 409) {
60
- log('Autotest %s already exists, updating with %o', autotestPost.externalId, autotestPost);
61
- const [autotest] = await this.client.getAutotest({
62
- projectId: this.client.getConfig().projectId,
63
- externalId: autotestPost.externalId,
64
- });
65
- await this.client.updateAutotest({
66
- ...autotest,
67
- links: autotest.links,
68
- });
69
- return autotest.id;
70
- }
71
- else {
72
- console.error((0, utils_1.formatError)(err));
73
- throw err;
74
- }
75
- }
76
- }
77
- async loadPassedAutotest(autotest) {
78
- try {
79
- log('Creating autotest %o', autotest);
80
- await this.client.createAutotest(autotest);
81
- }
82
- catch (err) {
83
- const axiosError = err;
84
- if (axiosError.response?.status === 409) {
85
- log('Autotest %s already exists, updating with %o', autotest.externalId, autotest);
86
- await this.client.updateAutotest(autotest);
87
- }
88
- else {
89
- console.error((0, utils_1.formatError)(err));
90
- throw err;
91
- }
92
- }
93
- }
94
- async getAutotestId(externalId) {
95
- const [autotest] = await this.client.getAutotest({
96
- projectId: this.client.getConfig().projectId,
97
- externalId,
98
- });
99
- return autotest.id;
100
- }
101
- async linkWorkItem(externalId, workItemId) {
102
- log('Linking work item %s to autotest %s', workItemId, externalId);
103
- return this.client.linkToWorkItem(externalId, { id: workItemId });
104
- }
105
- async loadAutotestResults(results) {
106
- log('Loading autotest results %o', results);
107
- await this.client.loadTestRunResults(this.testRunId, results);
108
- }
109
- async uploadAttachments(attachments) {
110
- const attachmentIds = [];
111
- for (const attachment of attachments) {
112
- try {
113
- log('Uploading attachment %s', attachment);
114
- const { id } = await this.client.loadAttachment(attachment);
115
- if (!id) {
116
- log('Attachment id is not returned');
117
- continue;
118
- }
119
- attachmentIds.push(id);
120
- }
121
- catch (err) {
122
- console.error(`Failed to load attachment`, (0, utils_1.formatError)(err));
123
- }
124
- }
125
- return attachmentIds;
126
- }
127
- }
128
- exports.TestClient = TestClient;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestClient = void 0;
4
+ const testit_api_client_1 = require("testit-api-client");
5
+ const debug_1 = require("./debug");
6
+ const utils_1 = require("./utils");
7
+ const log = debug_1.debug.extend('client');
8
+ class TestClient {
9
+ constructor(clientConfig = {}) {
10
+ this.client = new testit_api_client_1.Client(clientConfig);
11
+ this._testRunId = clientConfig.testRunId;
12
+ }
13
+ get testRunId() {
14
+ if (this._testRunId === undefined) {
15
+ throw new Error('Test run id is not set');
16
+ }
17
+ return this._testRunId;
18
+ }
19
+ get projectId() {
20
+ return this.client.getConfig().projectId;
21
+ }
22
+ get configurationId() {
23
+ return this.client.getConfig().configurationId;
24
+ }
25
+ async createTestRun() {
26
+ const { projectId, testRunId } = this.client.getConfig();
27
+ if (testRunId === undefined) {
28
+ log('Test run id is not provided, creating test run for project %s', projectId);
29
+ this._testRunId = await this.client
30
+ .createTestRun({ projectId })
31
+ .then((testRun) => testRun.id);
32
+ }
33
+ else {
34
+ log('Using provided test run id %s', testRunId);
35
+ this._testRunId = testRunId;
36
+ }
37
+ log('Starting test run %s', this.testRunId);
38
+ return this.testRunId;
39
+ }
40
+ async startTestRun() {
41
+ log('Starting test run %s', this.testRunId);
42
+ await this.client.startTestRun(this.testRunId);
43
+ }
44
+ async completeTestRun() {
45
+ log('Completing test run %s', this.testRunId);
46
+ const testRun = await this.client.getTestRun(this.testRunId);
47
+ if (testRun.stateName === 'InProgress') {
48
+ await this.client.completeTestRun(this.testRunId);
49
+ }
50
+ }
51
+ async loadAutotest(autotestPost) {
52
+ try {
53
+ log('Creating autotest %o', autotestPost);
54
+ const { id } = await this.client.createAutotest(autotestPost);
55
+ return id;
56
+ }
57
+ catch (err) {
58
+ const axiosError = err;
59
+ if (axiosError.response?.status === 409) {
60
+ log('Autotest %s already exists, updating with %o', autotestPost.externalId, autotestPost);
61
+ const [autotest] = await this.client.getAutotest({
62
+ projectId: this.client.getConfig().projectId,
63
+ externalId: autotestPost.externalId,
64
+ });
65
+ await this.client.updateAutotest({
66
+ ...autotest,
67
+ links: autotest.links,
68
+ });
69
+ return autotest.id;
70
+ }
71
+ else {
72
+ console.error((0, utils_1.formatError)(err));
73
+ throw err;
74
+ }
75
+ }
76
+ }
77
+ async loadPassedAutotest(autotest) {
78
+ try {
79
+ log('Creating autotest %o', autotest);
80
+ await this.client.createAutotest(autotest);
81
+ }
82
+ catch (err) {
83
+ const axiosError = err;
84
+ if (axiosError.response?.status === 409) {
85
+ log('Autotest %s already exists, updating with %o', autotest.externalId, autotest);
86
+ await this.client.updateAutotest(autotest);
87
+ }
88
+ else {
89
+ console.error((0, utils_1.formatError)(err));
90
+ throw err;
91
+ }
92
+ }
93
+ }
94
+ async getAutotestId(externalId) {
95
+ const [autotest] = await this.client.getAutotest({
96
+ projectId: this.client.getConfig().projectId,
97
+ externalId,
98
+ });
99
+ return autotest.id;
100
+ }
101
+ async linkWorkItem(externalId, workItemId) {
102
+ log('Linking work item %s to autotest %s', workItemId, externalId);
103
+ return this.client.linkToWorkItem(externalId, { id: workItemId });
104
+ }
105
+ async loadAutotestResults(results) {
106
+ log('Loading autotest results %o', results);
107
+ await this.client.loadTestRunResults(this.testRunId, results);
108
+ }
109
+ async uploadAttachments(attachments) {
110
+ const attachmentIds = [];
111
+ for (const attachment of attachments) {
112
+ try {
113
+ log('Uploading attachment %s', attachment);
114
+ const { id } = await this.client.loadAttachment(attachment);
115
+ if (!id) {
116
+ log('Attachment id is not returned');
117
+ continue;
118
+ }
119
+ attachmentIds.push(id);
120
+ }
121
+ catch (err) {
122
+ console.error(`Failed to load attachment`, (0, utils_1.formatError)(err));
123
+ }
124
+ }
125
+ return attachmentIds;
126
+ }
127
+ }
128
+ exports.TestClient = TestClient;
@@ -1,56 +1,58 @@
1
- /// <reference types="node" />
2
- import type { EnvironmentContext, JestEnvironmentConfig } from '@jest/environment';
3
- import { Event, State } from 'jest-circus';
4
- import NodeEnvironment from 'jest-environment-node';
5
- import { LinkPost } from 'testit-api-client';
6
- export default class TestItEnvironment extends NodeEnvironment {
7
- private autotestData;
8
- private currentStepData;
9
- private testClient;
10
- private beforeAllSteps;
11
- private afterAllSteps;
12
- private currentType;
13
- private autotestResults;
14
- private autotests;
15
- private testPath;
16
- private attachmentsQueue;
17
- private automaticCreationTestCases;
18
- constructor(config: JestEnvironmentConfig, context: EnvironmentContext);
19
- setup(): Promise<void>;
20
- teardown(): Promise<void>;
21
- getVmContext(): import("vm").Context | null;
22
- exportConditions(): string[];
23
- handleTestEvent(event: Event, state: State): Promise<void>;
24
- startHookCapture(hook: Extract<Event, {
25
- name: 'hook_start';
26
- }>['hook']): void;
27
- finishHookCapture(hook: Extract<Event, {
28
- name: 'hook_start';
29
- }>['hook']): void;
30
- startTestCapture(test: Extract<Event, {
31
- name: 'test_fn_start';
32
- }>['test']): void;
33
- finishTestCapture(test: Extract<Event, {
34
- name: 'test_fn_success';
35
- }>['test']): void;
36
- saveResult(test: Extract<Event, {
37
- name: 'test_done';
38
- }>['test']): void;
39
- loadResults(): Promise<void>;
40
- resetTest(): void;
41
- resetStep(): void;
42
- setExternalId(id: string): void;
43
- setDisplayName(name: string): void;
44
- setTitle(title: string): void;
45
- setDescription(description: string): void;
46
- addAttachments(attachment: string, name?: string): void;
47
- addAttachments(attachments: string[]): void;
48
- addLinks(links: LinkPost[]): void;
49
- addMessage(message: string): void;
50
- setAutotestLinks(links: LinkPost[]): void;
51
- setLabels(labels: string[]): void;
52
- setWorkItems(workItems: string[]): void;
53
- setParams(params: any): void;
54
- startStep(name: string, description?: string): void;
55
- generateExternalId(testName: string): string;
56
- }
1
+ /// <reference types="node" />
2
+ import type { EnvironmentContext, JestEnvironmentConfig } from '@jest/environment';
3
+ import { Event, State } from 'jest-circus';
4
+ import NodeEnvironment from 'jest-environment-node';
5
+ import { LinkPost } from 'testit-api-client';
6
+ export default class TestItEnvironment extends NodeEnvironment {
7
+ private autotestData;
8
+ private currentStepData;
9
+ private testClient;
10
+ private beforeAllSteps;
11
+ private afterAllSteps;
12
+ private currentType;
13
+ private autotestResults;
14
+ private autotests;
15
+ private testPath;
16
+ private attachmentsQueue;
17
+ private automaticCreationTestCases;
18
+ constructor(config: JestEnvironmentConfig, context: EnvironmentContext);
19
+ setup(): Promise<void>;
20
+ teardown(): Promise<void>;
21
+ getVmContext(): import("vm").Context | null;
22
+ exportConditions(): string[];
23
+ handleTestEvent(event: Event, state: State): Promise<void>;
24
+ startHookCapture(hook: Extract<Event, {
25
+ name: 'hook_start';
26
+ }>['hook']): void;
27
+ finishHookCapture(hook: Extract<Event, {
28
+ name: 'hook_start';
29
+ }>['hook']): void;
30
+ startTestCapture(test: Extract<Event, {
31
+ name: 'test_fn_start';
32
+ }>['test']): void;
33
+ finishTestCapture(test: Extract<Event, {
34
+ name: 'test_fn_success';
35
+ }>['test']): void;
36
+ saveResult(test: Extract<Event, {
37
+ name: 'test_done';
38
+ }>['test']): void;
39
+ loadResults(): Promise<void>;
40
+ resetTest(): void;
41
+ resetStep(): void;
42
+ setExternalId(id: string): void;
43
+ setDisplayName(name: string): void;
44
+ setTitle(title: string): void;
45
+ setDescription(description: string): void;
46
+ addAttachments(attachment: string, name?: string): void;
47
+ addAttachments(attachments: string[]): void;
48
+ addLinks(links: LinkPost[]): void;
49
+ addMessage(message: string): void;
50
+ setAutotestLinks(links: LinkPost[]): void;
51
+ setLabels(labels: string[]): void;
52
+ setWorkItems(workItems: string[]): void;
53
+ setParams(params: any): void;
54
+ setNameSpace(nameSpace: string): void;
55
+ setClassName(className: string): void;
56
+ startStep(name: string, description?: string): void;
57
+ generateExternalId(testName: string): string;
58
+ }