我试图在我的grunt脚本中使用grunt-protractor-coverage来获得量角器功能e2e测试的代码覆盖率。为了开始,我使用了this tutorial,进行了一些小修改,它完美无缺。以此为指导,我创建了一个新的gruntfile,用" express"应用程序与rails应用程序后端。
运行我的gruntfile时,我得到以下堆栈跟踪:
../dummy/node_modules/grunt-protractor-coverage/node_modules/protractor/node_modules/glob/glob.js:130
throw new Error("must provide pattern")
^
Error: must provide pattern
at new Glob (../dummy/node_modules/grunt-protractor-coverage/node_modules/protractor/node_modules/glob/glob.js:130:11)
at glob ../dummy/node_modules/grunt-protractor-coverage/node_modules/protractor/node_modules/glob/glob.js:57:11)
at Function.globSync [as sync] (../dummy/node_modules/grunt-protractor-coverage/node_modules/protractor/node_modules/glob/glob.js:76:10)
at Function.ConfigParser.resolveFilePatterns (../dummy/node_modules/grunt-protractor-coverage/node_modules/protractor/lib/configParser.js:89:26)
at Runner.run (../dummy/node_modules/grunt-protractor-coverage/node_modules/protractor/lib/runner.js:323:24)
at process.<anonymous> (../dummy/node_modules/grunt-protractor-coverage/node_modules/protractor/lib/runFromLauncher.js:32:14)
at process.EventEmitter.emit (events.js:98:17)
at handleMessage (child_process.js:318:10)
at Pipe.channel.onread (child_process.js:345:11)
[launcher] Runner Process Exited With Error Code: 8
通过[node-inspector](https://github.com/node-inspector/node-inspector)跟踪grunt的task.js文件中的代码,似乎有两个可能的问题:
知道为什么会抛出此错误吗?
protractor_coverage: {
options: {
configFile: '/usr/local/lib/node_modules/protractor/referenceConf.js', // Default config file
keepAlive: true, // If false, the grunt process stops when the test fails.
noColor: false, // If true, protractor will not use colors in its output.
coverageDir: '<%= dirs.instrumentedE2E %>',
args: {}
},
phantom: {
options: {
args: {
baseUrl: 'http://localhost:3000/',
// Arguments passed to the command
'browser': 'phantomjs'
}
}
},
chrome: {
options: {
args: {
baseUrl: 'http://localhost:3000/',
// Arguments passed to the command
'browser': 'chrome'
}
}
}
},
答案 0 :(得分:0)
此错误表示插件无法找到您的spec文件。最近发布的版本中有一些与此相关的错误。
您通常希望protractorConf.js成为您项目的一部分。我通常把它放在一个名为'tests'的目录中。
所以你的选择看起来像是:
options: {
configFile: 'tests/protractorConf.js',
keepAlive: true, // If false, the grunt process stops when the test fails.
noColor: false, // If true, protractor will not use colors in its output.
coverageDir: '<%= dirs.instrumentedE2E %>',
args: {}
},
然后您可以将您的规范放在'tests / specs'目录中,并在此protractorConf.js中,将它们引用为:
specs: [
'tests/specs/**/*.spec.js',
'!**/exclude.spec.js'
],
这将获得以/ tests / specs中的.spec.js及其中任何子目录结尾的任何文件,除非该文件名为exclude.spec.js。
答案 1 :(得分:0)
我也有这个问题,对于我来说,在我的protractorConf文件中,我不得不改变我的路径。
我最初有
specs: [
'./e2e/**/*.spec.js'
],
适用于量角器和grunt-protractor-runner
但由于某种原因,量角器覆盖,这没有运行。我把它改成了
specs: [
'test/e2e/**/*.spec.js'
],
这解决了我的问题。基本上,量角器覆盖范围从基础开始,而不是从配置文件中查看路径。