Skip to content
Merged
Changes from 2 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
74 changes: 55 additions & 19 deletions packages/E2ETest/run_wdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const xml2js = require('xml2js');
const parser = new xml2js.Parser({ attrkey: 'ATTR' });
const child_process = require('child_process');
const prompt = require('prompt-sync')();
const chalk = require('chalk');

const specFolder = 'wdio/test';

Expand Down Expand Up @@ -53,7 +54,7 @@ function SelectSpecs(folder) {
let opts = SelectSpecs(specFolder);
console.log(`Selected tests: ${opts}`);

function OverrideHyperV() {
function EnsureRunningInHyperV() {
const baseboardMfr = child_process
.execSync('powershell.exe (gwmi Win32_BaseBoard).Manufacturer')
.toString()
Expand All @@ -69,26 +70,39 @@ function OverrideHyperV() {
}
}

OverrideHyperV();

const Launcher = require('@wdio/cli').default;

const wdio = new Launcher('wdio.conf.js', { specs: opts });

function parseLog(logfile) {
const xmlString = fs.readFileSync(logfile);
let name;
let failures = {};
parser.parseString(xmlString, (err, res) => {
if (!res.testsuites) {
name = 'something went wrong';
failures = 'something went wrong';
} else {
const attr = res.testsuites.testsuite[0].ATTR;
if (attr.errors > 0 || attr.failures > 0) {
name = attr.name;
for (let i = 0; i < res.testsuites.testsuite.length; i++) {
const attr = res.testsuites.testsuite[i].ATTR;
if (attr.errors > 0 || attr.failures > 0) {
let name = attr.name;
failures[name] = {};
const testcases = res.testsuites.testsuite[i].testcase;
for (let j = 0; j < testcases.length; j++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this could really use some whitespace to make it a bit more readable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also named variables instead of indices. See the other comment about not using raw for loops.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the spacing matches what lint expects

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean new lines. Lint doesn't care about those.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't seem to be the case.
image
image

Copy link
Contributor

@NickGerleman NickGerleman May 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asklar Prettier will warn about Windows style line feeds depending on config. You'll want to change what your editor is set to likely. It should not complain about single new lines.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think it will also complain about empty lines that start directly after a conditional.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant with "lint doesn't care about those" is that it won't add them for you,

if (testcases[j].error && testcases[j].error[0].ATTR) {
failures[name].testcase = testcases[j].ATTR.name;
failures[name].error = testcases[j].error[0].ATTR.message;
const systemErr = testcases[j]['system-err'][0];
const stack = systemErr.substr(
systemErr.indexOf('\n at ') + 1
);
failures[name].stack = stack;
}
}
}
}
}
});
return name;
return failures;
}

function parseLogs() {
Expand All @@ -100,20 +114,42 @@ function parseLogs() {
return names;
}

function PrintFailedTests(ft) {
for (let i = 0; i < Object.keys(ft).length; i++) {
const key = Object.keys(ft)[i];
console.log(chalk.redBright(key));
console.log(
' ',
chalk.underline('testcase'),
chalk.bold(ft[key].testcase)
);
console.log(' ', chalk.underline('error'), chalk.bold(ft[key].error));
console.log(' ', chalk.underline('stack'));
console.log(ft[key].stack);
}
}

function Process(code) {
const failedTests = parseLogs();
for (let i = 0; i < failedTests.length; i++) {
console.log(`Failed test: ${failedTests[i]}`);
console.log('Failed tests: ');
PrintFailedTests(failedTests[i]);
}
process.exit(code);
}

wdio.run().then(
code => {
Process(code);
},
error => {
console.error('Launcher failed to start the test', error.stacktrace);
process.exit(1);
}
);
function RunWdio() {
EnsureRunningInHyperV();

wdio.run().then(
code => {
Process(code);
},
error => {
console.error('Launcher failed to start the test', error.stacktrace);
process.exit(1);
}
);
}

RunWdio();