-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Break parsers out into separate files
- Loading branch information
1 parent
45a29de
commit d96d3cd
Showing
5 changed files
with
86 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |