mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-11 11:15:24 +03:00
Added a new way to filter for tests
This commit is contained in:
parent
3e3709bc72
commit
921bb34a5f
@ -16,12 +16,17 @@ module.exports = function(filter) {
|
||||
}
|
||||
}
|
||||
|
||||
runSpecs(packagePath, true)
|
||||
runSpecs(packagePath, [])
|
||||
}
|
||||
|
||||
function runSpecs(files, retry) {
|
||||
function runSpecs(files, retries) {
|
||||
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
|
||||
@ -36,7 +41,7 @@ function runSpecs(files, retry) {
|
||||
const strData = data.toString();
|
||||
process.stderr.write(strData);
|
||||
|
||||
if(strData.match(/ALL FILES THAT FAILED/)) {
|
||||
if(strData.match(/ALL TESTS THAT FAILED:/)) {
|
||||
out = '';
|
||||
} else if(out !== undefined) {
|
||||
out += strData;
|
||||
@ -44,28 +49,28 @@ function runSpecs(files, retry) {
|
||||
});
|
||||
|
||||
res.on('close', code => {
|
||||
if(code !== 0 && retry) {
|
||||
const failed = filterFiles(out)
|
||||
runSpecs(failed, false)
|
||||
if(code !== 0 && retries.length === 0) {
|
||||
const failed = filterSpecs(out)
|
||||
runSpecs(files, failed)
|
||||
} else {
|
||||
process.exit(code)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function filterFiles(output) {
|
||||
let files = new Set()
|
||||
function filterSpecs(output) {
|
||||
let descriptions = []
|
||||
let start = true
|
||||
for(let out of output.split("\n")) {
|
||||
if(start) {
|
||||
if(out !== '') {
|
||||
start = false
|
||||
files.add(out.replace(/:\d+:\d+/, ''))
|
||||
descriptions.push(out)
|
||||
}
|
||||
} else if(out !== '') {
|
||||
files.add(out.replace(/:\d+:\d+/, ''))
|
||||
descriptions.push(out)
|
||||
} else {
|
||||
return files
|
||||
return descriptions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,7 @@ const { TerminalReporter } = require('jasmine-tagged');
|
||||
|
||||
class JasmineListReporter extends TerminalReporter {
|
||||
fullDescription(spec) {
|
||||
let fullDescription = 'it ' + spec.description;
|
||||
let currentSuite = spec.suite;
|
||||
while (currentSuite) {
|
||||
fullDescription = currentSuite.description + ' > ' + fullDescription;
|
||||
currentSuite = currentSuite.parentSuite;
|
||||
}
|
||||
return fullDescription;
|
||||
return getFullDescription(spec, true);
|
||||
}
|
||||
|
||||
reportSpecStarting(spec) {
|
||||
@ -26,13 +20,9 @@ class JasmineListReporter extends TerminalReporter {
|
||||
msg = "\u001b[34m[pass]\u001b[0m";
|
||||
} else {
|
||||
msg = "\u001b[1m\u001b[31m[FAIL]\u001b[0m";
|
||||
this.flatFailures ||= [];
|
||||
|
||||
for(let result of spec.results_.items_) {
|
||||
if(!result.passed_) {
|
||||
this.flatFailures.push(result)
|
||||
}
|
||||
}
|
||||
this.flatFailures ||= [];
|
||||
this.flatFailures.push(getFullDescription(spec, false))
|
||||
|
||||
this.addFailureToFailures_(spec);
|
||||
}
|
||||
@ -40,12 +30,29 @@ class JasmineListReporter extends TerminalReporter {
|
||||
}
|
||||
|
||||
reportFailures_(spec) {
|
||||
this.printLine_("\n\nALL FILES THAT FAILED:")
|
||||
super.reportFailures_(spec);
|
||||
|
||||
this.printLine_("\n\nALL TESTS THAT FAILED:")
|
||||
for(let failure of this.flatFailures) {
|
||||
const onlyFile = failure.filteredStackTrace.replace(/.*\((.*)\).*/, '$1')
|
||||
this.printLine_(onlyFile)
|
||||
this.printLine_(failure)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { JasmineListReporter };
|
||||
function getFullDescription(spec, tokens) {
|
||||
let fullDescription = spec.description;
|
||||
if(tokens) fullDescription = `it ${fullDescription}`;
|
||||
|
||||
let currentSuite = spec.suite;
|
||||
while (currentSuite) {
|
||||
if(tokens) {
|
||||
fullDescription = `${currentSuite.description} > ${fullDescription}`;
|
||||
} else {
|
||||
fullDescription = `${currentSuite.description} ${fullDescription}`;
|
||||
}
|
||||
currentSuite = currentSuite.parentSuite;
|
||||
}
|
||||
return fullDescription;
|
||||
}
|
||||
|
||||
module.exports = { JasmineListReporter, getFullDescription };
|
||||
|
@ -77,6 +77,12 @@ module.exports = function({logFile, headless, testPaths, buildAtomEnvironment})
|
||||
const jasmineEnv = jasmine.getEnv();
|
||||
jasmineEnv.addReporter(buildReporter({logFile, headless, resolveWithExitCode}));
|
||||
|
||||
if(process.env.SPEC_FILTER) {
|
||||
const {getFullDescription} = require('./jasmine-list-reporter');
|
||||
const regex = new RegExp(process.env.SPEC_FILTER)
|
||||
jasmineEnv.specFilter = (spec) => getFullDescription(spec, false).match(regex)
|
||||
}
|
||||
|
||||
if (process.env.TEST_JUNIT_XML_PATH) {
|
||||
const {JasmineJUnitReporter} = require('./jasmine-junit-reporter');
|
||||
process.stdout.write(`Outputting JUnit XML to <${process.env.TEST_JUNIT_XML_PATH}>\n`);
|
||||
|
Loading…
Reference in New Issue
Block a user