我遇到了一个有趣的问题,似乎在任务期间写入终端的某些任务在并发运行时似乎会覆盖另一个任务。例如:
我试图同时运行两个任务,一个用于单元测试,另一个用于e2e测试。这两个文件都应该是我正在处理的自动孵化文件,因此,我的Gruntfile.js中有以下内容(这些只是有趣的部分:
Gruntfile.js:
concurrent: {
options: { logConcurrentOutput: true },
server: [
'copy:styles'
],
test: [
'copy:styles'
],
dist: [
'copy:styles',
'imagemin',
'svgmin'
],
continuous: {
tasks: [
'karma:unit_auto',
'karma:e2e_auto'
]
}
},
karma: {
unit: {
configFile: 'karma.conf.js',
singleRun: true
},
unit_auto: {
configFile: 'karma.conf.js',
autoWatch: true,
singleRun: false
},
e2e: {
configFile: 'karma-e2e.conf.js',
singleRun: true
},
e2e_auto: {
configFile: 'karma-e2e.conf.js',
autoWatch: true,
singleRun: false
}
}
////////// and later in the file....... ///////////
grunt.registerTask('continuous', [
'clean:server',
'concurrent:continuous'
]);
当我从命令行运行“咕噜连续”时,我会看到两个浏览器窗口弹出,正如我所期望的那样。通常在第一次运行时,我从我想要看到的终端获得输出:
在$grunt连续运行的初始阶段:
user@myMachine:/path/to/working/directory$ grunt continuous
Running "clean:server" (clean) task
Running "concurrent:continuous" (concurrent) task
Running "karma:e2e_auto" (karma) task
Running "karma:unit_auto" (karma) task
INFO [karma]: Karma v0.12.10 server started at http://localhost:9999/
WARN [karma]: Port 9998 in use
INFO [launcher]: Starting browser Chrome
WARN [karma]: Port 9999 in use
INFO [karma]: Karma v0.12.10 server started at http://localhost:10000/_e2e/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 33.0.1750 (Linux)]: Connected on socket raGtr-40ZhPP7nCFXwvB with id 67817341
INFO [Chrome 33.0.1750 (Linux)]: Connected on socket IM2e8gy38Np1dL4fXwuy with id 77648855
Chrome 33.0.1750 (Linux): Executed 4 of 4 SUCCESS (0.11 secs / 0.104 secs)
Chrome 33.0.1750 (Linux): Executed 1 of 1 SUCCESS (0.206 secs / 0.167 secs)
但是,当我更改(并保存)所监视的文件时,我开始看到奇怪的结果。请注意,一次又一次保存同一个文件通常会给出来自并发任务的不同输出:
在一次又一次保存相同文件后的:
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/app.js".
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/app.js".
Chrome 33.0.1750 (Linux): Executed 4 of 4 SUCCESS (0.114 secs / 0.103 secs)
Chrome 33.0.1750 (Linux): Executed 1 of 1 SUCCESS (0.159 secs / 0.12 secs)
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/app.js".
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/app.js".
Chrome 33.0.1750 (Linux): Executed 0 of 4 SUCCESS (0 secs / 0 secs)
Chrome 33.0.1750 (Linux): Executed 1 of 1 SUCCESS (0.181 secs / 0.148 secs)
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/app.js".
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/app.js".
Chrome 33.0.1750 (Linux): Executed 0 of 4 SUCCESS (0 secs / 0 secs)
Chrome 33.0.1750 (Linux): Executed 1 of 1 SUCCESS (0.141 secs / 0.12 secs)
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/app.js".
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/app.js".
Chrome 33.0.1750 (Linux): Executed 0 of 4 SUCCESS (0 secs / 0 secs)
Chrome 33.0.1750 (Linux): Executed 1 of 1 SUCCESS (0.241 secs / 0.219 secs)
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/app.js".
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/app.js".
Chrome 33.0.1750 (Linux): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
Chrome 33.0.1750 (Linux): Executed 1 of 1 SUCCESS (0.253 secs / 0.227 secs)
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/controllers/mmsLandingPageCtrl.js".
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/controllers/mmsLandingPageCtrl.js".
Chrome 33.0.1750 (Linux): Executed 3 of 4 SUCCESS (0 secs / 0.091 secs)
Chrome 33.0.1750 (Linux): Executed 1 of 1 SUCCESS (0.208 secs / 0.151 secs)
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/controllers/mmsLandingPageCtrl.js".
INFO [watcher]: Changed file "/var/www/web-tcad/app/scripts/controllers/mmsLandingPageCtrl.js".
Chrome 33.0.1750 (Linux): Executed 0 of 4 SUCCESS (0 secs / 0 secs)
Chrome 33.0.1750 (Linux): Executed 1 of 1 SUCCESS (0.249 secs / 0.218 secs)
我认为这里的问题来自于日志是如何写到终端的.也就是说,我认为每次运行测试时,繁重的任务都会擦除终端的最后一行,并将其替换为当前的进度。有没有任何建议认为你们都必须控制这种行为,或者以不同的方式设置我的任务来避免这个问题?
干杯!
发布于 2014-04-24 18:31:39
在我的业力咕噜设置中,我实际上使用咕噜-控制-观察和运行业力任务从手表。实际上,在我的构建设置中还有其他步骤,所以让它从监视任务中运行是非常有用的。
你可能想要这样的东西:
karma: {
e2e: {
configFile: 'karma-e2e.conf.js',
background: true
},
unit: {
configFile: 'karma.conf.js',
background: true
}
},
watch: {
karma_e2e: {
files: [<<list of your files to watch for e2e>>],
tasks: ['karma:e2e:run'],
options: {
atBegin: true,
spawn: false // necessary to preserve console output
}
},
karma_unit: {
files: [<<list of your files to watch for unit>>],
tasks: ['karma:unit:run'],
options: {
atBegin: true,
spawn: false // necessary to preserve console output
}
}
}
grunt.registerTask('continuous', [
'clean:server',
'watch'
]);
https://stackoverflow.com/questions/23279013
复制