Node.js Webpack dev server:一旦服务器运行,就会为触发器命令提供钩子或机制
在我的开发工作流程中,我打开了两个终端窗口,在一个我的Node.js Webpack dev server:一旦服务器运行,就会为触发器命令提供钩子或机制,node.js,continuous-integration,webpack-dev-server,functional-testing,cucumberjs,Node.js,Continuous Integration,Webpack Dev Server,Functional Testing,Cucumberjs,在我的开发工作流程中,我打开了两个终端窗口,在一个我的npm启动任务中运行,一旦服务器在第二个窗口中运行,我就运行cucumberjs的功能测试套件,这正如我预期的那样工作。但我的问题是,在我的CI环境中,我需要在单个进程中运行它。我一直在尝试: npm开始| cucumberjs——需要测试/功能性/——编译器js:babel寄存器测试/功能性/ 问题是任务npm start需要一段时间才能运行,同时cucumber任务尝试访问localhost:3000(webpack dev服务器运行时的
npm启动任务中运行,一旦服务器在第二个窗口中运行,我就运行cucumberjs的功能测试套件,这正如我预期的那样工作。但我的问题是,在我的CI环境中,我需要在单个进程中运行它。我一直在尝试:
npm开始| cucumberjs——需要测试/功能性/——编译器js:babel寄存器测试/功能性/
问题是任务npm start需要一段时间才能运行,同时cucumber任务尝试访问localhost:3000(webpack dev服务器运行时的url),但服务器尚未就绪,测试失败
那么,我该如何处理这个问题呢?
项目:
package.json
...
"scripts": {
"start": "npm run stubs & webpack-dev-server",
"dev": "npm start -- --open",
"stubs": "stubby -w -d stubs/fakeserver.yml -s 5000",
"tdd": "cross-env NODE_PATH=./src jest --watch --verbose",
"test": "cross-env NODE_PATH=./src jest --coverage --verbose",
"test:functional": "cucumberjs --require test/functional/ --compiler js:babel-register test/functional/",
//I want in the test:functional-ci task run the npm start and once that is serving the project, run npm run test:functional task
"test:functional-ci": "cross-env NODE_ENV=staging npm run test:functional",
"test-debug": "cross-env NODE_PATH=./src node --inspect --inspect-brk node_modules/.bin/jest -i",
"build": "webpack",
"check-coverage": "npm test | http-server -so -p 9000 coverage/lcov-report"
},
...
"scripts": {
"start": "sh -c \"npm run stubs & webpack-dev-server\"",
...
"test:functional": "cucumberjs --require test/functional/ --compiler
...
webpack.config.js
module.exports = {
entry: [
'core-js/shim',
'babel-polyfill',
'angular',
'./src/index.js'
],
output: {
path: 'dist',
filename: 'index.bundle.js'
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'},
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" },
{ test: /\.(html)$/, loader: 'html-loader' },
{ test: /\.(woff|woff2)$/, loader:"url?prefix=font/&limit=5000" },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" }]
},
cache: true,
devtool: 'eval-source-map',
devServer: {
filename: "index.bundle.js",
contentBase: "./src",
port: 3000,
watch: true,
publicPath: "/",
historyApiFallback: true,
stats: {
colors: true,
chunks: false
}
}
};
最后,我不能用一些网页选项直接解决我的问题。在我的CI系统上,我运行以下操作:
package.json
...
"scripts": {
"start": "npm run stubs & webpack-dev-server",
"dev": "npm start -- --open",
"stubs": "stubby -w -d stubs/fakeserver.yml -s 5000",
"tdd": "cross-env NODE_PATH=./src jest --watch --verbose",
"test": "cross-env NODE_PATH=./src jest --coverage --verbose",
"test:functional": "cucumberjs --require test/functional/ --compiler js:babel-register test/functional/",
//I want in the test:functional-ci task run the npm start and once that is serving the project, run npm run test:functional task
"test:functional-ci": "cross-env NODE_ENV=staging npm run test:functional",
"test-debug": "cross-env NODE_PATH=./src node --inspect --inspect-brk node_modules/.bin/jest -i",
"build": "webpack",
"check-coverage": "npm test | http-server -so -p 9000 coverage/lcov-report"
},
...
"scripts": {
"start": "sh -c \"npm run stubs & webpack-dev-server\"",
...
"test:functional": "cucumberjs --require test/functional/ --compiler
...
.travis.yml
before_script: npm start & sleep 7
script: npm run test:functional
因此,当我运行npm start&sleep 7
时,我会给npm start
7秒钟,让任务完成任务,然后运行npm run test:functional
脚本
这是我的回购协议:
这是CI travis日志中的结果:最后,我无法通过一些网页选项直接解决我的问题。在我的CI系统上,我运行以下操作:
package.json
...
"scripts": {
"start": "npm run stubs & webpack-dev-server",
"dev": "npm start -- --open",
"stubs": "stubby -w -d stubs/fakeserver.yml -s 5000",
"tdd": "cross-env NODE_PATH=./src jest --watch --verbose",
"test": "cross-env NODE_PATH=./src jest --coverage --verbose",
"test:functional": "cucumberjs --require test/functional/ --compiler js:babel-register test/functional/",
//I want in the test:functional-ci task run the npm start and once that is serving the project, run npm run test:functional task
"test:functional-ci": "cross-env NODE_ENV=staging npm run test:functional",
"test-debug": "cross-env NODE_PATH=./src node --inspect --inspect-brk node_modules/.bin/jest -i",
"build": "webpack",
"check-coverage": "npm test | http-server -so -p 9000 coverage/lcov-report"
},
...
"scripts": {
"start": "sh -c \"npm run stubs & webpack-dev-server\"",
...
"test:functional": "cucumberjs --require test/functional/ --compiler
...
.travis.yml
before_script: npm start & sleep 7
script: npm run test:functional
因此,当我运行npm start&sleep 7
时,我会给npm start
7秒钟,让任务完成任务,然后运行npm run test:functional
脚本
这是我的回购协议:
这是CI travis日志中的结果:你不能在cucumber任务中添加一个逻辑来检查服务器是否正在运行(并重复检查5次,每分钟一次),并且只有在服务器确实在运行时才继续吗?你不能在cucumber任务中添加一个逻辑来检查服务器是否正在运行吗(并反复检查,比如说5次,每分钟检查一次),只有在服务器确实在运行时才继续?