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

CI: Simplify run-tests.js and use it in editor tests workflow #1121

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/editor-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

- name: Run Tests
if: runner.os != 'Linux'
run: yarn start --test spec
run: node script/run-tests.js spec

- name: Run Tests with xvfb-run (Linux)
if: runner.os == 'Linux'
Expand Down
48 changes: 2 additions & 46 deletions script/run-tests.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,28 @@
const cp = require('child_process')

function runAllSpecs(files) {
runSpecs(files, [])
}

function runSpecs(files, retries) {
function runSpecs(files) {
let env = process.env
env.ATOM_JASMINE_REPORTER='list'
if(retries.length > 0) {
// Escape possible tests that can generate a regexp that will not match...
const escaped = retries.map(str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
env.SPEC_FILTER = escaped.join("|")
}

const res = cp.spawn('yarn', ['start', '--test', ...files], {
cwd: process.cwd(),
env: env
})

let out;
res.stdout.on('data', data => {
process.stdout.write(data.toString());
});

res.stderr.on('data', data => {
const strData = data.toString();
process.stderr.write(strData);

if(strData.match(/ALL TESTS THAT FAILED:/)) {
out = '';
} else if(out !== undefined) {
out += strData;
}
});

res.on('close', code => {
if(code !== 0 && retries.length === 0) {
const failed = filterSpecs(out)

console.log(`*********************
Tests failed. Retrying failed tests...
*********************

`)
runSpecs(files, failed)
} else {
process.exit(code)
}
});
}

function filterSpecs(output) {
if(!output) return ''
let descriptions = []
let start = true
for(let out of output.split("\n")) {
if(start) {
if(out !== '') {
start = false
descriptions.push(out)
}
} else if(out !== '') {
descriptions.push(out)
} else {
return descriptions
}
}
}

if(process.argv[0] === __filename) {
runAllSpecs(process.argv.splice(1))
} else if(process.argv[1] === __filename) {
Expand Down
Loading