Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: some improvements #103

Merged
merged 9 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:

strategy:
matrix:
node-version: [12.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm i
- run: npm i --force
- run: npm run test-server
- run: npm run acceptance_test
52 changes: 42 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { event } = require('codeceptjs');
const { deepMerge, clearString } = require('codeceptjs/lib/utils');
const Container = require('codeceptjs').container;
const helpers = Container.helpers();
const output = require('./lib/output');
Expand Down Expand Up @@ -34,7 +35,7 @@ for (const helperName of supportedHelpers) {
}

module.exports = (config) => {
config = Object.assign(defaultConfig, config);
config = deepMerge (defaultConfig, config);
output.showDebugLog(config.debugLog);

if (config.host === '' || config.user === '' || config.password === '') throw new Error('Please provide proper Testrail host or credentials');
Expand Down Expand Up @@ -118,13 +119,13 @@ module.exports = (config) => {

event.dispatcher.on(event.test.failed, async (test, err) => {
test.endTime = Date.now();
test.elapsed = Math.round((test.endTime - test.startTime) / 1000);
test.tags.forEach(async (tag) => {
test.elapsed = test.duration ? test.duration / 1000 : Math.round((test.endTime - test.startTime) / 1000);
for (const tag of test.tags) {
const uuid = Math.floor(new Date().getTime() / 1000);
const fileName = `${uuid}.failed.png`;
try {
output.log('Saving the screenshot...');
if (helper) {
output.log('Saving the screenshot...');
await helper.saveScreenshot(fileName);
}
} catch (error) {
Expand All @@ -139,15 +140,15 @@ module.exports = (config) => {
failedTestCaseIds.add(caseId);
failedTests.push({ case_id: caseId, elapsed: elapsed });
}
errors[tag.split(prefixTag)[1]] = err;
errors[tag.split(prefixTag)[1]] = err || test.err;
attachments[tag.split(prefixTag)[1]] = fileName;
}
});
}
});

event.dispatcher.on(event.test.passed, (test) => {
test.endTime = Date.now();
test.elapsed = Math.round((test.endTime - test.startTime) / 1000);
test.elapsed = test.startTime ? Math.round((test.endTime - test.startTime) / 1000) : 0;
test.tags.forEach(tag => {
if (prefixRegExp.test(tag)) {
const caseId = tag.split(prefixTag)[1];
Expand All @@ -161,7 +162,38 @@ module.exports = (config) => {
});
});

event.dispatcher.on(event.workers.result, async (result) => {
for (test of result.tests.passed) {
test.tags.forEach(tag => {
if (prefixRegExp.test(tag)) {
const caseId = tag.split(prefixTag)[1];
const elapsed = !test.duration ? defaultElapsedTime : `${test.duration / 1000}s`
passedTests.push({ case_id: caseId , elapsed });
}
})
}

for (test of result.tests.failed) {
test.tags.forEach(tag => {
if (prefixRegExp.test(tag)) {
const caseId = tag.split(prefixTag)[1];
const elapsed = !test.duration ? defaultElapsedTime : `${test.duration / 1000}s`

failedTests.push({ case_id: caseId, elapsed });
errors[caseId] = test.err;
attachments[caseId] = clearString(test.title) + '.failed.png';
}
})
}

await _publishResultsToTestrail();
});

event.dispatcher.on(event.all.result, async () => {
if (!process.env.RUNS_WITH_WORKERS) await _publishResultsToTestrail();
});

async function _publishResultsToTestrail() {
const mergedTests = [...failedTests, ...passedTests, ...skippedTest]

let ids = [];
Expand Down Expand Up @@ -271,14 +303,14 @@ module.exports = (config) => {
// Assign extra/missing params for each FAILED test case
failedTests.forEach(test => {
let errorString = '';
if (errors[test.case_id]['message']) {
if (errors[test.case_id] && errors[test.case_id]['message']) {
errorString = errors[test.case_id]['message'].replace(/\u001b\[.*?m/g, '');
} else {
errorString = errors[test.case_id];
}
const testCase = {
failed: {
comment: config.testCase.failed.comment || `Test case C${test.case_id} is *FAILED* due to **${errorString}**`,
comment: config.testCase.failed.comment || `Test case C${test.case_id} is *FAILED* due to **${JSON.stringify(errorString)}**`,
status_id: config.testCase.failed.status_id,
version: config.version
}
Expand Down Expand Up @@ -336,7 +368,7 @@ module.exports = (config) => {
} else {
output.log('There is no TC, hence no test run is created');
}
});
}

return this;
};
Expand Down
Loading
Loading