Skip to content

Commit f29ffb9

Browse files
authored
feat: resultProcessor (after rebase + resolve conflicts) (#2)
refactor: add links to Testrail doc to clarify custom fields config refactor: wrap text into anchor element refactor: add anchor to readme refactor: after code review fix: test title Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> feat: tests feat: use resultProcessor result for testrail chore: readme.md feat: add resultProcessor chore: get rid of unused deps Co-authored-by: Denis Shelest <dshelest@wiley.com>
1 parent 2a0e5af commit f29ffb9

File tree

7 files changed

+214
-126
lines changed

7 files changed

+214
-126
lines changed

.eslintrc.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
module.exports = {
2-
'env': {
3-
'browser': true,
4-
'es6': true,
5-
'node': true,
6-
'mocha': true
2+
env: {
3+
browser: true,
4+
es6: true,
5+
node: true,
6+
mocha: true
77
},
8-
'extends': ['eslint:recommended', 'plugin:codeceptjs/recommended'],
9-
'parserOptions': {
10-
'sourceType': 'module',
11-
'ecmaVersion': 2020
8+
extends: ['eslint:recommended', 'plugin:codeceptjs/recommended'],
9+
parserOptions: {
10+
sourceType: 'module',
11+
ecmaVersion: 2020
1212
},
13-
'rules': {
14-
'indent': [
13+
rules: {
14+
indent: [
1515
'error',
1616
'tab'
1717
],
1818
'linebreak-style': [
1919
'error',
2020
'unix'
2121
],
22-
'quotes': [
22+
quotes: [
2323
'error',
2424
'single'
2525
],
26-
'semi': [
26+
semi: [
2727
'error',
2828
'always'
2929
],

index.js

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ const defaultConfig = {
2222
passed: { status_id: 1 },
2323
failed: { status_id: 5 },
2424
},
25+
runId: undefined,
2526
closeTestRun: true,
26-
version: '1' // this is the build version - OPTIONAL
27+
version: '1', // this is the build version - OPTIONAL,
28+
resultProcessor: undefined
2729
};
2830

2931
let helper;
@@ -38,8 +40,13 @@ module.exports = (config) => {
3840
config = deepMerge (defaultConfig, config);
3941
output.showDebugLog(config.debugLog);
4042

41-
if (config.host === '' || config.user === '' || config.password === '') throw new Error('Please provide proper Testrail host or credentials');
43+
if (!config.host) throw new Error('Please provide proper Testrail host');
44+
if (!config.user) throw new Error('Please provide proper Testrail user');
45+
if (!config.password) throw new Error('Please provide proper Testrail password');
4246
if (!config.projectId) throw new Error('Please provide project id in config file');
47+
if (config.resultProcessor && typeof config.resultProcessor !== 'function') {
48+
throw new Error('Result processor (`resultProcessor` config option) has to be function');
49+
}
4350

4451
const testrail = new TestRail(config);
4552

@@ -202,7 +209,7 @@ module.exports = (config) => {
202209
let config_ids = [];
203210

204211
mergedTests.forEach(test => {
205-
for (let [key, value] of Object.entries(test)) {
212+
for (const [key, value] of Object.entries(test)) {
206213
if (key === 'case_id') {
207214
ids.push(value);
208215
}
@@ -334,20 +341,40 @@ module.exports = (config) => {
334341

335342
const allResults = passedTests.concat(failedTests.concat(skippedTest));
336343

337-
// Before POST-ing the results, filter the array for any non-existing tags in TR test bucket assigned to this test run
338-
// This is to avoid any failure to POST results due to labels in the results array not part of the test run
339-
let validResults = [];
340-
testrail.getCases(config.projectId, config.suiteId).then(res => {
341-
if (res.length) {
342-
validResults = allResults.filter(result => res.find(tag => tag.id == result.case_id));
343-
const missingLabels = allResults.filter(result => !validResults.find(vResult => vResult.case_id == result.case_id));
344+
testrail.getCases(config.projectId, config.suiteId).then(testCases => {
345+
if (testCases.length) {
346+
// Before POST-ing the results, filter the array for any non-existing tags in TR test bucket assigned to this test run
347+
// This is to avoid any failure to POST results due to labels in the results array not part of the test run
348+
const { validResults, missingLabels } = allResults.reduce(
349+
(acc, testResult) => {
350+
const testCase = testCases.find(it => it.id == testResult.case_id);
351+
// If there is `resultProcessor` callback in config, then we need to process test result
352+
const processedResult = config.resultProcessor
353+
? config.resultProcessor(testResult, { testCase, allResults, allTestCases: testCases })
354+
: testResult;
355+
356+
if (processedResult) {
357+
if (testCase) {
358+
acc.validResults.push(processedResult);
359+
} else {
360+
acc.missingLabels.push(processedResult);
361+
}
362+
}
363+
return acc;
364+
},
365+
{ validResults: [], missingLabels: [] }
366+
);
367+
344368
if (missingLabels.length) {
345369
output.error(`Error: some labels are missing from the test run and the results were not send through: ${JSON.stringify(missingLabels.map(l => l.case_id))}`);
346370
}
371+
372+
return { validResults };
347373
}
348-
}).then(() => {
374+
return { validResults: [] };
375+
}).then(({ validResults }) => {
349376
if (validResults.length) {
350-
testrail.addResultsForCases(runId, { results: validResults }).then(res => {
377+
testrail.addResultsForCases(runId, {results: validResults}).then(res => {
351378
output.log(`The run ${runId} is updated with ${JSON.stringify(res)}`);
352379

353380
for (const test of failedTests) {

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@
3939
"chalk": "4.0.0",
4040
"codeceptjs": "3.5.8",
4141
"eslint": "8.2.0",
42-
"eslint-config-airbnb-base": "15.0.0",
4342
"eslint-plugin-codeceptjs": "^1.3.0",
44-
"eslint-plugin-import": "2.29.0",
45-
"expect": "26.0.0",
4643
"json-server": "0.17.0",
4744
"mocha": "10.2.0",
4845
"semantic-release": "21.0.1"

0 commit comments

Comments
 (0)