@motherofmeow/codeceptjs-qase 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 PeterNgTr <peter.nguyentr@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ ##### Qase TSM
2
+
3
+ Qase integration with CodeceptJS. The test run is created automatically after the test execution.
4
+
5
+
6
+ ##### Requirement
7
+
8
+ To use this plugin
9
+
10
+ ```sh
11
+ npm i @motherofmeow/codeceptjs-qase --save
12
+ ```
13
+
14
+ **Note:**
15
+
16
+ - You should include the test case id to make it works, otherwise, this plugin has no clue which case id to be added to test run on Qaseio.
17
+ - To avoid creating multiple testruns, add `--suites` to `run-workers` command
18
+
19
+ ```sh
20
+ npx codeceptjs run-workers 3 --suites
21
+ ```
22
+
23
+ An example:
24
+
25
+ ```js
26
+ ...
27
+ Scenario('Search function is displayed @C12345', ({I, homePage}) => {
28
+ I.seeElement(homePage.searchTextbox);
29
+ I.seeElement(homePage.searchButton);
30
+ });
31
+ ...
32
+ ```
33
+
34
+ **Data driven tests**
35
+
36
+ If you want to have different Data-driven test cases with different IDs in Qase for each iteration of the test you will need to populate the Data object with your a tag. This works because CodeceptJS extracts tags from test names, and data for Data-driven tests is populated in the test name.
37
+
38
+ An example:
39
+
40
+ ```js
41
+ ...
42
+ let accounts = new DataTable(['testRailTag', 'user', 'password']);
43
+ accounts.add(['@C12345', 'davert', '123456']); // add a tag for each user along with their test data
44
+ accounts.add(['@C45678', 'admin', '123456']);
45
+
46
+ Data(accounts).Scenario('Test Login', ({ I, current }) => {
47
+ I.fillField('Username', current.login); // current is reserved!
48
+ I.fillField('Password', current.password);
49
+ I.click('Sign In');
50
+ I.see('Welcome '+ current.login);
51
+ });
52
+ ...
53
+ ```
54
+
55
+ A Gherkin example:
56
+
57
+ ```gherkin
58
+ @smoke
59
+ @12345
60
+ Scenario: Search function is displayed
61
+ Given I am on the home page
62
+ Then I see search textbox
63
+ And I see search button
64
+ ```
65
+
66
+ ```gherkin
67
+ @someTag
68
+ Scenario Outline: Fill some field
69
+ When I fill some field by text <text>
70
+ Then I see text <text>
71
+
72
+ Examples:
73
+ | testRailTag | text |
74
+ | @C1234 | someText1 |
75
+ | @C1235 | someText2 |
76
+ ```
77
+
78
+ ##### Configuration
79
+
80
+ Adding this plugin to CodeceptJS config file:
81
+
82
+ ```js
83
+ ...
84
+ plugins: {
85
+ qase: {
86
+ require: "@motherofmeow/codeceptjs-qase",
87
+ apiKey: "your api token",
88
+ projectName: process.env.QASE_PROJECT_NAME,
89
+ enabled: process.env.QASE_REPORT || false,
90
+ runId: process.env.TEST_RUN_ID,
91
+ testRunTags: ['smoke-tests']
92
+ }
93
+ }
94
+ ...
95
+ ```
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const date_fns_1 = require("date-fns");
4
+ const qaseio_1 = require("qaseio");
5
+ const codeceptjs_1 = require("codeceptjs");
6
+ const helpers = codeceptjs_1.container.helpers();
7
+ const supportedHelpers = [
8
+ 'WebDriver',
9
+ 'Appium',
10
+ 'Nightmare',
11
+ 'Puppeteer',
12
+ 'Playwright',
13
+ 'TestCafe',
14
+ 'REST'
15
+ ];
16
+ const defaultConfig = {
17
+ apiKey: '',
18
+ projectName: '',
19
+ enabled: false,
20
+ };
21
+ let helper;
22
+ for (const helperName of supportedHelpers) {
23
+ if (Object.keys(helpers).indexOf(helperName) > -1) {
24
+ helper = helpers[helperName];
25
+ }
26
+ }
27
+ module.exports = (config) => {
28
+ config = Object.assign(defaultConfig, config);
29
+ if (config.apiKey === '' || config.apiKey === undefined)
30
+ throw new Error('Please provide proper Qaseio api key');
31
+ if (config.projectName === '' || config.projectName === undefined)
32
+ throw new Error('Please provide proper Qaseio project name');
33
+ const qase = new qaseio_1.QaseApi({ token: config.apiKey });
34
+ let runId;
35
+ let failedTests = [];
36
+ const passedTests = [];
37
+ const errors = {};
38
+ const prefixTag = '@C';
39
+ const defaultElapsedTime = '1000';
40
+ const ids = [];
41
+ const runName = config.runName ? config.runName : `New test run on ${(0, date_fns_1.format)(new Date(), 'yyyy-MM-dd\'T\'HH:mm:ss.s')}`;
42
+ async function _createTestRunResult(projectName, runId, results) {
43
+ try {
44
+ const resultCreate = { case_id: results.caseId, status: results.status, time_ms: results.time_ms, stacktrace: results.stacktrace };
45
+ return qase.results.createResult(projectName, Number(runId), resultCreate);
46
+ }
47
+ catch (error) {
48
+ console.log(`Cannot create test run result due to ${error}`);
49
+ }
50
+ }
51
+ async function _getRuns(projectName) {
52
+ try {
53
+ const res = await qase.runs.getRuns(projectName);
54
+ return res.data.result.entities;
55
+ }
56
+ catch (error) {
57
+ console.log(`Cannot get new test run due to ${JSON.stringify(error)}`);
58
+ }
59
+ }
60
+ async function _addTestRun(projectName, runName, cases, description, testRunTags) {
61
+ try {
62
+ const runCreate = { title: runName, cases, description, tags: testRunTags };
63
+ const res = await qase.runs.createRun(projectName, runCreate);
64
+ return res.data.result.id;
65
+ }
66
+ catch (error) {
67
+ console.log(`Cannot create new test run due to ${JSON.stringify(error)}`);
68
+ }
69
+ }
70
+ codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.test.started, async (test) => {
71
+ if (test.body) {
72
+ if (test.body.includes('addExampleInTable')) {
73
+ const qaseTag = /"qaseTag":"(@C\d+)"/.exec(test.title);
74
+ if (qaseTag) {
75
+ test.tags.push(qaseTag[1]);
76
+ }
77
+ }
78
+ }
79
+ test.startTime = Date.now();
80
+ });
81
+ const failedTestCaseIds = new Set();
82
+ codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.test.failed, async (test, err) => {
83
+ test.endTime = Date.now();
84
+ test.elapsed = Math.round(test.endTime - test.startTime);
85
+ test.tags.forEach((tag) => {
86
+ if (tag.includes(prefixTag)) {
87
+ const caseId = parseInt(tag.split(prefixTag)[1], 10);
88
+ if (!failedTestCaseIds.has(caseId)) {
89
+ // else it also failed on retry so we shouldnt add in a duplicate
90
+ failedTestCaseIds.add(caseId);
91
+ failedTests.push({ case_id: caseId, elapsed: test.elapsed === 0 ? defaultElapsedTime : test.elapsed });
92
+ }
93
+ errors[tag.split(prefixTag)[1]] = err;
94
+ }
95
+ });
96
+ });
97
+ codeceptjs_1.event.dispatcher.on(codeceptjs_1.event.test.passed, (test) => {
98
+ test.endTime = Date.now();
99
+ test.elapsed = Math.round(test.endTime - test.startTime);
100
+ test.tags.forEach(tag => {
101
+ if (tag.includes(prefixTag)) {
102
+ const caseId = parseInt(tag.split(prefixTag)[1], 10);
103
+ // remove duplicates caused by retries
104
+ if (failedTestCaseIds.has(caseId)) {
105
+ failedTests = failedTests.filter(({ case_id }) => case_id !== caseId);
106
+ }
107
+ passedTests.push({ case_id: caseId, elapsed: test.elapsed === 0 ? defaultElapsedTime : test.elapsed });
108
+ }
109
+ });
110
+ });
111
+ codeceptjs_1.event.dispatcher.once(codeceptjs_1.event.all.after, async () => {
112
+ const mergedTests = failedTests.concat(passedTests);
113
+ mergedTests.forEach(test => {
114
+ for (const [key, value] of Object.entries(test)) {
115
+ if (key === 'case_id') {
116
+ ids.push(value);
117
+ }
118
+ }
119
+ });
120
+ try {
121
+ if (config.runId) {
122
+ runId = config.runId;
123
+ }
124
+ else {
125
+ const existingRuns = await _getRuns(config.projectName);
126
+ if (existingRuns.length > 0) {
127
+ for (const run of existingRuns) {
128
+ if (run.title !== runName) {
129
+ runId = await _addTestRun(config.projectName, runName, ids, config.description, config.testRunTags);
130
+ break;
131
+ }
132
+ }
133
+ }
134
+ else {
135
+ runId = await _addTestRun(config.projectName, runName, ids, config.description, config.testRunTags);
136
+ }
137
+ }
138
+ }
139
+ catch (error) {
140
+ console.log(error);
141
+ }
142
+ if (ids.length > 0) {
143
+ passedTests.forEach(test => {
144
+ try {
145
+ _createTestRunResult(config.projectName, runId, { caseId: test.case_id, status: 'passed', time_ms: test.elapsed }).then(() => console.log());
146
+ }
147
+ catch (e) {
148
+ console.log(e);
149
+ }
150
+ });
151
+ failedTests.forEach(test => {
152
+ try {
153
+ const errorString = errors[test.case_id]['message'] ? errors[test.case_id]['message'].replace(/\u001b\[.*?m/g, '') : errors[test.case_id];
154
+ _createTestRunResult(config.projectName, runId, { caseId: test.case_id, status: 'failed', time_ms: test.elapsed, stacktrace: errorString }).then(() => console.log());
155
+ }
156
+ catch (e) {
157
+ console.log(e);
158
+ }
159
+ });
160
+ }
161
+ else {
162
+ console.log('There is no TC, hence no test run is created');
163
+ }
164
+ });
165
+ return this;
166
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@motherofmeow/codeceptjs-qase",
3
+ "version": "1.0.0",
4
+ "description": "CodeceptJS plugin for Qaseio",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/MotherOfMeow/codeceptjs-qaseio.git"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "keywords": [
15
+ "codeceptJS",
16
+ "codeceptjs",
17
+ "qaseio",
18
+ "qaseio-plugin"
19
+ ],
20
+ "author": "Anastasia M <motherofmeow77@gmail.com>",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/MotherOfMeow/codeceptjs-qaseio/issues"
24
+ },
25
+ "homepage": "https://github.com/MotherOfMeow/codeceptjs-qaseio#readme",
26
+ "engines": {
27
+ "node": ">=20.8.1"
28
+ },
29
+ "dependencies": {
30
+ "date-fns": "^4.4.0",
31
+ "qaseio": "^2.4.3",
32
+ "typescript": "^5.9.3",
33
+ "codeceptjs": "^4.1.0"
34
+ },
35
+ "scripts": {
36
+ "lint": "eslint . --fix",
37
+ "semantic-release": "semantic-release",
38
+ "build": "tsc"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^20.19",
42
+ "eslint": "^8.57.1",
43
+ "playwright": "^1.63.0",
44
+ "semantic-release": "^24.2.9"
45
+ },
46
+ "files": [
47
+ "dist/*"
48
+ ]
49
+ }