Skip to content

Commit

Permalink
feat: Break parsers out into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
NickTomlin committed Jul 15, 2016
1 parent 45a29de commit d96d3cd
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 45 deletions.
51 changes: 6 additions & 45 deletions src/failed-spec-parser.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
export default function (output = '') {
let match = null
let CUCUMBERJS_TEST = /^\d+ scenarios?/m
let failedSpecs = new Set()
let PROTRACTOR_SHARDED = /------------------------------------/g
let SPECFILE_REG = /.+Specs:\s(.*\.js)/g
import parsers from './parsers/all'

if (PROTRACTOR_SHARDED.test(output) && SPECFILE_REG.test(output)) {
console.log('sharded test found')
let testsOutput = output.split('------------------------------------')
testsOutput.shift()
let RESULT_REG = /\d+\sspec|assertions?,\s(\d+)\sfailures?/g
testsOutput.forEach(function (test) {
let specfile
let result = 'failed'
// retrieve specfile from run;
while (match = SPECFILE_REG.exec(test)) { // eslint-disable-line no-cond-assign
specfile = match[1]
}
// check for string 'X specs, X failures' and verify that failures === 0;
while (match = RESULT_REG.exec(test)) { // eslint-disable-line no-cond-assign
if (match[1] === '0') {
result = 'passed'
}
}
if (result === 'failed') {
if (!/node_modules/.test(specfile)) {
failedSpecs.add(specfile)
}
}
})
} else if (CUCUMBERJS_TEST.test(output)) {
let FAILED_LINES = /(.*?):\d+ # Scenario:.*/g
while (match = FAILED_LINES.exec(output)) { // eslint-disable-line no-cond-assign
failedSpecs.add(match[1])
}
} else {
let FAILED_LINES = /at (?:\[object Object\]|Object)\.<anonymous> \((([A-Za-z]:\\)?.*?):.*\)/g
while (match = FAILED_LINES.exec(output)) { // eslint-disable-line no-cond-assign
// windows output includes stack traces from
// webdriver so we filter those out here
if (!/node_modules/.test(match[1])) {
failedSpecs.add(match[1])
}
}
}
export default function (output = '') {
let parser = parsers.find((p) => {
return p.test(output)
})
let failedSpecs = parser.parse(new Set(), output)

return [...failedSpecs]
}
5 changes: 5 additions & 0 deletions src/parsers/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import CucumberParser from './cucumber'
import ShardedParser from './sharded'
import StandardParser from './standard'

export default [CucumberParser, ShardedParser, StandardParser]
18 changes: 18 additions & 0 deletions src/parsers/cucumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const CUCUMBERJS_TEST = /^\d+ scenarios?/m

export default {
name: 'CucumberParser',
test (output) {
return CUCUMBERJS_TEST.test(output)
},

parse (failedSpecs, output) {
let match = null
let FAILED_LINES = /(.*?):\d+ # Scenario:.*/g
while (match = FAILED_LINES.exec(output)) { // eslint-disable-line no-cond-assign
failedSpecs.add(match[1])
}

return failedSpecs
}
}
37 changes: 37 additions & 0 deletions src/parsers/sharded.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const PROTRACTOR_SHARDED = /------------------------------------/g
const SPECFILE_REG = /.+Specs:\s(.*\.js)/g

export default {
name: 'ShardedParser',
test (output) {
return PROTRACTOR_SHARDED.test(output) && SPECFILE_REG.test(output)
},

parse (failedSpecs, output) {
let match = null
let testsOutput = output.split('------------------------------------')
testsOutput.shift()
let RESULT_REG = /\d+\sspec|assertions?,\s(\d+)\sfailures?/g
testsOutput.forEach(function (test) {
let specfile
let result = 'failed'
// retrieve specfile from run;
while (match = SPECFILE_REG.exec(test)) { // eslint-disable-line no-cond-assign
specfile = match[1]
}
// check for string 'X specs, X failures' and verify that failures === 0;
while (match = RESULT_REG.exec(test)) { // eslint-disable-line no-cond-assign
if (match[1] === '0') {
result = 'passed'
}
}
if (result === 'failed') {
if (!/node_modules/.test(specfile)) {
failedSpecs.add(specfile)
}
}
})

return failedSpecs
}
}
20 changes: 20 additions & 0 deletions src/parsers/standard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
name: 'StandardParser',
test (output) {
return true;
},

parse (failedSpecs, output) {
let match = null
let FAILED_LINES = /at (?:\[object Object\]|Object)\.<anonymous> \((([A-Za-z]:\\)?.*?):.*\)/g
while (match = FAILED_LINES.exec(output)) { // eslint-disable-line no-cond-assign
// windows output includes stack traces from
// webdriver so we filter those out here
if (!/node_modules/.test(match[1])) {
failedSpecs.add(match[1])
}
}

return failedSpecs
}
}

0 comments on commit d96d3cd

Please sign in to comment.