Skip to content

Commit

Permalink
fix: fix failure artifacts in edge and firefox
Browse files Browse the repository at this point in the history
They don't have getLogTypes.
  • Loading branch information
Kelly Selden committed Jan 13, 2023
1 parent 3f77a41 commit a9d442b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 13 deletions.
30 changes: 17 additions & 13 deletions packages/mocha/src/failure-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,27 @@ async function failureArtifacts(outputDir) {
let url = await this.browser.getUrl();
await writeArtifact(`${title}.url.txt`, url);

let logTypes = await this.browser._browser.getLogTypes();
for (let logType of logTypes) {
let logs = await this.browser._browser.getLogs(logType);
let logsText = JSON.stringify(logs, null, 2);
await writeArtifact(`${title}.${logType}.txt`, logsText);
if (this.browser._browser.getLogTypes) {
let logTypes = await this.browser._browser.getLogTypes();
for (let logType of logTypes) {
let logs = await this.browser._browser.getLogs(logType);
let logsText = JSON.stringify(logs, null, 2);
await writeArtifact(`${title}.${logType}.txt`, logsText);
}
}
}

async function flush() {
let logTypes = await this.browser._browser.getLogTypes();
for (let logType of logTypes) {
// https://v5.webdriver.io/docs/api/chromium.html#getlogs
// "Log buffer is reset after each request."
// For the failure logs to be useful, it should only include the failing test,
// not the whole test run up until the failure. So we need to clear the logs
// between each test.
await this.browser._browser.getLogs(logType);
if (this.browser._browser.getLogTypes) {
let logTypes = await this.browser._browser.getLogTypes();
for (let logType of logTypes) {
// https://v5.webdriver.io/docs/api/chromium.html#getlogs
// "Log buffer is reset after each request."
// For the failure logs to be useful, it should only include the failing test,
// not the whole test run up until the failure. So we need to clear the logs
// between each test.
await this.browser._browser.getLogs(logType);
}
}
}

Expand Down
32 changes: 32 additions & 0 deletions packages/mocha/test/acceptance/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,38 @@ describe(function() {
this.assertFilesExist('after without mocha-helpers !after all! hook for !failure');
});

it('works in firefox', async function() {
let stats = await this.runTests({
filter: 'it firefox ',
});

expect(stats).matches(sinon.match({
tests: 2,
failures: 1,
passes: 1,
}));

this.extensions = ['png', 'html', 'url.txt'];

this.assertFilesExist('it firefox failure');
});

it('works in edge', async function() {
let stats = await this.runTests({
filter: 'it edge ',
});

expect(stats).matches(sinon.match({
tests: 2,
failures: 1,
passes: 1,
}));

this.extensions = ['png', 'html', 'url.txt'];

this.assertFilesExist('it edge failure');
});

describe('retries', function() {
const retries = 2;

Expand Down
21 changes: 21 additions & 0 deletions packages/mocha/test/fixtures/failure-artifacts-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ describe('failure artifacts', function() {
assert.ok(this.test.currentRetry() === 2);
});
});

for (let browser of [
'firefox',
'edge',
]) {
describe(browser, function() {
setUpWebDriver.call(this, {
overrides: {
browser,
},
});

it('failure', function() {
assert.ok(false);
});

it('success', function() {
assert.ok(true);
});
});
}
});

describe('beforeEach', function() {
Expand Down

0 comments on commit a9d442b

Please sign in to comment.