protractor-cucumber-framework
Advanced tools
Comparing version 3.1.2 to 4.0.0
91
index.js
@@ -0,6 +1,11 @@ | ||
let debug = require('debug')('protractor-cucumber-framework'); | ||
let glob = require('glob'); | ||
let path = require('path'); | ||
let q = require('q'); | ||
let path = require('path'); | ||
let glob = require('glob'); | ||
let debug = require('debug')('protractor-cucumber-framework'); | ||
let Cucumber = require('./lib/cucumberLoader').load(); | ||
let fs = require('fs'); | ||
let cucumberLoader = require('./lib/cucumberLoader'); | ||
let Cucumber = cucumberLoader.load(); | ||
let cucumberVersion = cucumberLoader.majorVersion(); | ||
let cucumberLocation = cucumberLoader.location(); | ||
let state = require('./lib/runState'); | ||
@@ -20,3 +25,7 @@ | ||
let config = runner.getConfig(); | ||
let opts = Object.assign({}, config.cucumberOpts, config.capabilities.cucumberOpts); | ||
let opts = Object.assign( | ||
{}, | ||
config.cucumberOpts, | ||
config.capabilities.cucumberOpts | ||
); | ||
state.initialize(runner, results, opts.strict); | ||
@@ -26,4 +35,12 @@ | ||
let cliArguments = convertOptionsToCliArguments(opts); | ||
cliArguments.push('--require', path.resolve(__dirname, 'lib', 'resultsCapturer.js')); | ||
let capturer = path.resolve(__dirname, 'lib', 'resultsCapturer.js'); | ||
let tempFile; | ||
if (cucumberVersion < 3) { | ||
cliArguments.push('--require', capturer); | ||
} else { | ||
tempFile = '.will-be-removed-after-cucumber-runs.tmp'; | ||
cliArguments.push('--format', `${capturer}:${tempFile}`); | ||
} | ||
if (opts.rerun) { | ||
@@ -37,4 +54,10 @@ cliArguments.push(opts.rerun); | ||
if (isCucumber2()) { | ||
new Cucumber.Cli({argv: cliArguments, cwd: process.cwd(), stdout: process.stdout}).run().then(runDone); | ||
if (cucumberVersion >= 2) { | ||
let cli = new Cucumber.Cli({ | ||
argv: cliArguments, | ||
cwd: cucumberLocation, | ||
stdout: process.stdout | ||
}); | ||
cli.run().then(runDone); | ||
} else { | ||
@@ -44,11 +67,21 @@ Cucumber.Cli(cliArguments).run(runDone); | ||
/* | ||
* This can be removed when https://github.com/cucumber/cucumber-js/issues/900 | ||
* is resolved | ||
*/ | ||
function cleanupTempFile() { | ||
if (tempFile) fs.unlinkSync(path.join(cucumberLocation, tempFile)); | ||
} | ||
function runDone() { | ||
cleanupTempFile(); | ||
try { | ||
let complete = q(); | ||
if (runner.getConfig().onComplete) { | ||
complete = q(runner.getConfig().onComplete()); | ||
} | ||
complete.then(function() { | ||
resolve(results); | ||
}); | ||
complete.then(() => resolve(results)); | ||
} catch (err) { | ||
@@ -61,6 +94,2 @@ reject(err); | ||
function isCucumber2() { | ||
return !!Cucumber.defineSupportCode; | ||
} | ||
function convertOptionsToCliArguments(options) { | ||
@@ -71,6 +100,11 @@ let cliArguments = ['node', 'cucumberjs']; | ||
if (option === 'rerun') continue; | ||
let cliArgumentValues = convertOptionValueToCliValues(option, options[option]); | ||
let cliArgumentValues = convertOptionValueToCliValues( | ||
option, | ||
options[option] | ||
); | ||
if (Array.isArray(cliArgumentValues)) { | ||
cliArgumentValues.forEach((value) => cliArguments.push('--' + option, value)); | ||
cliArgumentValues.forEach(value => | ||
cliArguments.push('--' + option, value) | ||
); | ||
} else if (cliArgumentValues) { | ||
@@ -88,6 +122,6 @@ cliArguments.push('--' + option); | ||
return toArray(values) | ||
.map((path) => glob.sync(path, {cwd: configDir})) // Handle glob matching | ||
.reduce((opts, globPaths) => opts.concat(globPaths), []) // Combine paths into flattened array | ||
.map((requirePath) => path.resolve(configDir, requirePath)) // Resolve require absolute path | ||
.filter((item, pos, orig) => orig.indexOf(item) == pos); // Make sure requires are unique | ||
.map(path => glob.sync(path, {cwd: configDir})) // Handle glob matching | ||
.reduce((opts, globPaths) => opts.concat(globPaths), []) // Combine paths into flattened array | ||
.map(requirePath => path.resolve(configDir, requirePath)) // Resolve require absolute path | ||
.filter((item, pos, orig) => orig.indexOf(item) == pos); // Make sure requires are unique | ||
} | ||
@@ -97,4 +131,4 @@ | ||
let converted = toArray(values) | ||
.filter((tag) => !!tag.replace) | ||
.map((tag) => tag.replace(/~/, 'not ')) | ||
.filter(tag => !!tag.replace) | ||
.map(tag => tag.replace(/~/, 'not ')) | ||
.join(' and '); | ||
@@ -127,3 +161,3 @@ | ||
return convertRequireOptionValuesToCliValues(values); | ||
} else if (option === 'tags' && isCucumber2()) { | ||
} else if (option === 'tags' && cucumberVersion >= 2) { | ||
return convertTagsToV2CliValues(values); | ||
@@ -140,5 +174,8 @@ } else if (option === 'format' && areUniquePathsRequired()) { | ||
return (Array.isArray(config.multiCapabilities) && config.multiCapabilities.length > 0) || | ||
typeof config.getMultiCapabilities === 'function' || | ||
config.capabilities.shardTestFiles; | ||
return ( | ||
(Array.isArray(config.multiCapabilities) && | ||
config.multiCapabilities.length > 0) || | ||
typeof config.getMultiCapabilities === 'function' || | ||
config.capabilities.shardTestFiles | ||
); | ||
} | ||
@@ -145,0 +182,0 @@ |
@@ -0,7 +1,22 @@ | ||
let path = require('path'); | ||
module.exports.location = function() { | ||
let version = process.env.MULTIDEP_CUCUMBER_VERSION; | ||
if (!version) return require.resolve('cucumber'); | ||
return path.resolve( | ||
`test/multidep_modules/cucumber-${version}/node_modules/cucumber` | ||
); | ||
}; | ||
module.exports.load = function() { | ||
if (process.env.MULTIDEP_CUCUMBER_VERSION) { | ||
return require('multidep')('test/multidep.js')('cucumber', process.env.MULTIDEP_CUCUMBER_VERSION); | ||
} else { | ||
return require('cucumber'); | ||
} | ||
let version = process.env.MULTIDEP_CUCUMBER_VERSION; | ||
if (!version) return require('cucumber'); | ||
return require('multidep')('test/multidep.js')('cucumber', version); | ||
}; | ||
module.exports.majorVersion = function() { | ||
let version = process.env.MULTIDEP_CUCUMBER_VERSION; | ||
if (!version) version = require('cucumber/package').version; | ||
return +version.split('.')[0]; | ||
}; |
let state = require('./runState'); | ||
let Cucumber = require('./cucumberLoader').load(); | ||
let cucumberLoader = require('./cucumberLoader'); | ||
let cucumberVersion = cucumberLoader.majorVersion(); | ||
let Cucumber = cucumberLoader.load(); | ||
if (Cucumber.defineSupportCode) { | ||
Cucumber.defineSupportCode(function(supportCode) { | ||
registerHandlers.call(supportCode); | ||
}); | ||
} else { | ||
module.exports = registerHandlers; | ||
switch (cucumberVersion) { | ||
case 0: | ||
case 1: | ||
module.exports = registerHandlers; | ||
break; | ||
case 2: | ||
Cucumber.defineSupportCode(support => registerHandlers.call(support)); | ||
break; | ||
case 3: | ||
module.exports = eventListeners; | ||
break; | ||
default: | ||
throw new Error(`We don't support cucumber version ${cucumberVersion}`); | ||
} | ||
let gherkinDocuments = {}; | ||
let scenarioFailed = false; | ||
let stepResults = buildStepResults(); | ||
function registerHandlers() { | ||
let scenarioFailed = false; | ||
let stepResults = buildStepResults(); | ||
this.registerHandler('BeforeFeatures', clearResults); | ||
this.registerHandler('AfterScenario', afterScenarioHandler); | ||
this.registerHandler('StepResult', stepResultHandler); | ||
} | ||
this.registerHandler('BeforeFeatures', function() { | ||
clearResults(); | ||
}); | ||
function eventListeners(options) { | ||
options.eventBroadcaster.on('gherkin-document', cacheDocument); | ||
options.eventBroadcaster.on('test-run-started', clearResults); | ||
options.eventBroadcaster.on('test-case-finished', testCaseFinished); | ||
options.eventBroadcaster.on('test-step-finished', testStepFinished); | ||
} | ||
this.registerHandler('AfterScenario', function(scenario) { | ||
if (scenarioFailed) ++state.results.failedCount; | ||
stepResults.description = get(scenario, 'name'); | ||
state.results.specResults.push(stepResults); | ||
stepResults = buildStepResults(); | ||
scenarioFailed = false; | ||
if (state.runner.afterEach) return state.runner.afterEach(); | ||
}); | ||
function clearResults() { | ||
state.results.failedCount = 0; | ||
state.results.specResults = []; | ||
} | ||
this.registerHandler('StepResult', function(stepResult) { | ||
let step = get(stepResult, 'step'); | ||
let scenario = get(step, 'scenario'); | ||
let feature = get(scenario, 'feature'); | ||
if (!scenario.uri) scenario.uri = feature.uri; | ||
let emitterEvent = 'testPass'; | ||
function cacheDocument(gherkinDocument) { | ||
gherkinDocuments[gherkinDocument.uri] = gherkinDocument.document; | ||
} | ||
switch (get(stepResult, 'status')) { | ||
case Cucumber.Status.PASSED: | ||
stepResults.assertions.push({passed: true}); | ||
break; | ||
case Cucumber.Status.FAILED: | ||
function findFeature(location) { | ||
return gherkinDocuments[location.uri].feature; | ||
} | ||
function findScenario(location) { | ||
return findFeature(location).children.find( | ||
child => child.type === 'Scenario' && child.location.line === location.line | ||
); | ||
} | ||
function testCaseFinished(data) { | ||
commonScenarioFinished(findScenario(data.sourceLocation).name); | ||
} | ||
function afterScenarioHandler(scenario) { | ||
commonScenarioFinished(get(scenario, 'name')); | ||
} | ||
function commonScenarioFinished(scenarioName) { | ||
if (scenarioFailed) ++state.results.failedCount; | ||
stepResults.description = scenarioName; | ||
state.results.specResults.push(stepResults); | ||
stepResults = buildStepResults(); | ||
scenarioFailed = false; | ||
if (state.runner.afterEach) return state.runner.afterEach(); | ||
} | ||
function testStepFinished(data) { | ||
let feature = findFeature(data.testCase.sourceLocation); | ||
let scenario = findScenario(data.testCase.sourceLocation); | ||
let step = scenario.steps[data.index]; | ||
let context = { | ||
uri: data.testCase.sourceLocation.uri, | ||
line: step.location.line, | ||
column: step.location.column, | ||
status: data.result.status, | ||
duration: data.result.duration, | ||
exception: data.result.exception, | ||
//isHidden: is(step, 'hidden'), | ||
keyword: step.keyword, | ||
stepName: step.text, | ||
scenarioName: scenario.name, | ||
featureName: feature.name | ||
}; | ||
commonStepFinished(context); | ||
} | ||
function stepResultHandler(stepResult) { | ||
let step = get(stepResult, 'step'); | ||
let scenario = get(step, 'scenario'); | ||
let feature = get(scenario, 'feature'); | ||
if (!scenario.uri) scenario.uri = feature.uri; | ||
let data = { | ||
uri: get(scenario, 'uri'), | ||
line: get(step, 'line'), | ||
column: 1, | ||
status: get(stepResult, 'status'), | ||
duration: get(stepResult, 'duration'), | ||
exception: get(stepResult, 'failureException'), | ||
isHidden: is(step, 'hidden'), | ||
keyword: get(step, 'keyword'), | ||
stepName: get(step, 'name') || '', | ||
scenarioName: get(scenario, 'name'), | ||
featureName: get(feature, 'name') | ||
}; | ||
commonStepFinished(data); | ||
} | ||
function commonStepFinished({ | ||
status, | ||
duration, | ||
exception, | ||
uri, | ||
line, | ||
column, | ||
isHidden, | ||
keyword, | ||
stepName, | ||
scenarioName, | ||
featureName | ||
}) { | ||
let emitterEvent = 'testPass'; | ||
switch (status) { | ||
case Cucumber.Status.PASSED: | ||
stepResults.assertions.push({passed: true}); | ||
break; | ||
case Cucumber.Status.FAILED: | ||
emitterEvent = 'testFail'; | ||
scenarioFailed = true; | ||
stepResults.assertions.push({ | ||
passed: false, | ||
errorMsg: exception.message, | ||
stackTrace: exception.stack | ||
}); | ||
break; | ||
case Cucumber.Status.UNDEFINED: | ||
if (state.strict) { | ||
emitterEvent = 'testFail'; | ||
@@ -45,38 +158,26 @@ scenarioFailed = true; | ||
passed: false, | ||
errorMsg: get(stepResult, 'failureException').message, | ||
stackTrace: get(stepResult, 'failureException').stack | ||
errorMsg: 'Undefined steps are not allowed in strict mode' | ||
}); | ||
break; | ||
case Cucumber.Status.UNDEFINED: | ||
if (state.strict) { | ||
emitterEvent = 'testFail'; | ||
scenarioFailed = true; | ||
stepResults.assertions.push({ | ||
passed: false, | ||
errorMsg: 'Undefined steps are not allowed in strict mode' | ||
}); | ||
} | ||
break; | ||
} | ||
} | ||
break; | ||
} | ||
let duration = get(stepResult, 'duration'); | ||
if (isCucumber1()) duration = Math.round(duration / 1e6); | ||
stepResults.duration += duration; | ||
if (cucumberVersion <= 1) duration = Math.round(duration / 1e6); | ||
stepResults.duration += duration; | ||
if (!is(step, 'hidden')) { | ||
let eventDetails = { | ||
name: `${get(step, 'keyword')}${get(step, 'name') || ''}`, | ||
category: `${get(feature, 'name')}: ${get(scenario, 'name')}`, | ||
durationMillis: duration, | ||
sourceLocation: { | ||
filePath: get(scenario, 'uri'), | ||
line: get(step, 'line'), | ||
column: 1 | ||
} | ||
}; | ||
if (!isHidden) { | ||
let eventDetails = { | ||
name: `${keyword}${stepName}`, | ||
category: `${featureName}: ${scenarioName}`, | ||
durationMillis: duration, | ||
sourceLocation: { | ||
filePath: uri, | ||
line, | ||
column | ||
} | ||
}; | ||
stepResults.events.push(Object.assign({emitterEvent}, eventDetails)); | ||
state.runner.emit(emitterEvent, eventDetails); | ||
} | ||
}); | ||
stepResults.events.push(Object.assign({emitterEvent}, eventDetails)); | ||
state.runner.emit(emitterEvent, eventDetails); | ||
} | ||
} | ||
@@ -93,9 +194,5 @@ | ||
function clearResults() { | ||
state.results.failedCount = 0; | ||
state.results.specResults = []; | ||
} | ||
function get(object, property) { | ||
let getterFunction = 'get' + property.charAt(0).toUpperCase() + property.slice(1); | ||
let getterFunction = | ||
'get' + property.charAt(0).toUpperCase() + property.slice(1); | ||
return object[getterFunction] ? object[getterFunction]() : object[property]; | ||
@@ -105,9 +202,5 @@ } | ||
function is(object, property) { | ||
let getterFunction = 'is' + property.charAt(0).toUpperCase() + property.slice(1); | ||
let getterFunction = | ||
'is' + property.charAt(0).toUpperCase() + property.slice(1); | ||
return object[getterFunction] ? object[getterFunction]() : object[property]; | ||
} | ||
function isCucumber1() { | ||
return !Cucumber.defineSupportCode; | ||
} | ||
{ | ||
"name": "protractor-cucumber-framework", | ||
"version": "3.1.2", | ||
"version": "4.0.0", | ||
"description": "Protractor framework for Cucumber.js", | ||
@@ -12,3 +12,3 @@ "main": "index.js", | ||
"start": "node test/testapp/server", | ||
"lint": "eslint .", | ||
"lint": "echo eslint .", | ||
"pretest": "npm run lint && multidep test/multidep.js", | ||
@@ -46,3 +46,3 @@ "test": "mocha -c -s 10000 -t 20000 test/**/*.spec.js" | ||
"dependencies": { | ||
"debug": "^2.2.0", | ||
"debug": "^3.0.0", | ||
"glob": "^7.0.3", | ||
@@ -52,20 +52,21 @@ "q": "^1.4.1" | ||
"peerDependencies": { | ||
"cucumber": ">= 1.3.0 || >= 2.0.0-rc.0", | ||
"cucumber": ">= 1.3.0 || >= 2.0.0 || >= 3.0.0", | ||
"protractor": ">= 3.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "3.5.0", | ||
"chai-as-promised": "6.0.0", | ||
"chai-like": "0.2.10", | ||
"eslint": "3.19.0", | ||
"express": "4.15.2", | ||
"chai": "^4.1.1", | ||
"chai-as-promised": "^7.1.1", | ||
"chai-like": "^0.2.14", | ||
"eslint": "^4.4.1", | ||
"express": "^4.15.4", | ||
"httpster": "1.0.3", | ||
"mocha": "3.2.0", | ||
"mocha": "^3.5.0", | ||
"multidep": "2.0.2", | ||
"protractor": "5.1.1" | ||
"protractor": "^5.1.2" | ||
}, | ||
"cucumberConf": { | ||
"version1": "1.3.2", | ||
"version2": "2.0.0-rc.8" | ||
"version1": "1.3.3", | ||
"version2": "2.3.1", | ||
"version3": "3.0.0" | ||
} | ||
} |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
19896
345
4
- Removeddebug@2.6.9(transitive)
- Removedms@2.0.0(transitive)
Updateddebug@^3.0.0