【发布时间】:2014-11-28 11:46:31
【问题描述】:
我正在尝试将我当前的 AngularJS 项目与 Protractor Coverage 集成。请在 package.json 和我的量角器配置下方找到。
Package.json
"devDependencies": {
"chromedriver": "~2.8.1",
"grunt": "~0.4.0",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-jshint": "~0.2.0",
"grunt-contrib-concat": "~0.1.3",
"grunt-contrib-uglify": "~0.1.1",
"grunt-contrib-watch": "~0.3.1",
"grunt-html2js": "~0.1.0",
"grunt-karma": "~0.4.4",
"grunt-protractor-runner": "~1.1.4",
"grunt-contrib-less": "~0.11.3",
"grunt-shell": "~0.6.0",
"selenium": "~2.20.0",
"grunt-protractor-coverage": "^0.2.1",
"grunt-istanbul": "^0.2.5",
"grunt-express-server": "~0.4.5",
"protractor": "~1.4.0",
"grunt-contrib-connect": "~0.7.1"
}
量角器配置
exports.config = {
seleniumServerJar: '../../node_modules/selenium/lib/runner/selenium-server-standalone-2.20.0.jar',
chromeDriver: '../../node_modules/chromedriver/lib/chromedriver/chromedriver',
baseUrl: 'http://localhost:3000/',
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['incognito', 'disable-extensions', 'start-maximized']
}
},
onPrepare: function() {
exports.server = require('../../server.js');
},
specs: ['../e2e/**/*.spec.js'],
jasmineNodeOpts: {
onComplete: function () {},
isVerbose: true,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 90000
}
};
我的繁重任务
grunt.registerTask('test', ['clean:coverage', 'copy:instrument', 'instrument', 'protractor_coverage:chrome', 'makeReport']);
copy: {
instrument: {
files: [{
src: ['src/app/**/*', '!src/app/**/*.js'],
dest: 'coverage/e2e/instrumented/'
}]
},
},
clean: {
coverage: ['coverage', 'instrumented', 'reports']
}
instrument: {
files: 'src/app/**/*.js',
options: {
lazy: true,
basePath: 'coverage/e2e/instrumented'
}
},
makeReport: {
src: 'coverage/e2e/instrumented/*.json',
options: {
type: 'lcov',
dir: 'coverage/e2e/reports',
print: 'detail'
}
},
protractor_coverage: {
options: {
configFile: 'test/config/protractor-config.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: 'coverage/e2e/instrumented',
args: {}
},
chrome: {
options: {
args: {
baseUrl: 'http://localhost:3000/',
// Arguments passed to the command
'browser': 'chrome'
}
}
},
},
当我尝试运行 grunt task 时,所有测试都成功运行,但量角器覆盖率报告完全为空。我尝试了几个选项,但无法显示报告。
问题:我在这里做错了吗?如何使量角器覆盖加载我的 src js 文件?
【问题讨论】:
-
您能否查看您的coverage/e2e/instrumented 文件夹以查看您的*.js 文件是否已被检测?如果是这样,您会在其中看到很多丑陋的代码。您必须设置您的应用程序以加载这些文件而不是“正常”文件。一旦工作正常,请在浏览器调试器中检查它们,以确保您的测试实际上正在使用检测文件。根据您的服务器/后端,这可以通过许多不同的方式完成。如果您使用的是 node,我建议您检查并运行与 Protractor Coverage 代码一起打包的示例应用程序。
-
是的,*.js 文件正在被检测,代码看起来正在缩小。我们正在使用“grunt-protractor-coverage”依赖项。但是我们在运行“grunt test”时在控制台中收到“浏览器中没有覆盖对象”警告。
-
可能您的覆盖服务器没有启动。尝试将 run:{} 选项添加到任务的末尾:此帖子之后的答案块中的代码
标签: angularjs gruntjs code-coverage protractor angularjs-e2e