将值 fron conf.js 传递给咕噜咕噜的任务或在咕噜咕噜的任务之间传递
passing value fron conf.js to a grunt task or between grunt tasks
如何在grunt
任务之间传递信息?我想将一个值从一个grunt
任务传递到另一个grunt
任务。
我的情况是,在完成量角器测试后,我想将一个值传递给新的grunt
任务。为了实现这一点,我继续在process.env
中设置值,并尝试在新grunt
任务中使用process.env
。但这似乎行不通
这是conf.js
:
afterLaunch: function(exitCode) {
return new Promise(function(fulfill, reject) {
if (typeof jasmine.getEnv().testReportFilePath !== 'undefined' && jasmine.getEnv().testReportFilePath !== null) {
process.env.testReportFilePath = jasmine.getEnv().testReportFilePath;
console.log('Trying: ' + process.env.testReportFilePath);
fulfill('Success: Environment variable testReportFilePath is set in conf.js');
} else {
reject(new Error('Failed: Environment variable testReportFilePath not set in conf.js'));
}
});
这是我的Gruntfile
:
grunt.loadNpmTasks('grunt-protractor-runner');
grunt.loadNpmTasks('grunt-protractor-webdriver');
grunt.loadNpmTasks('grunt-execute');
grunt.config('protractor', {
require: [ setTesting ],
options: {
configFile: 'conf.js', // common 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.
},
run_specific_suite: {
options: {
args: {
baseUrl: '<%= grunt.option("testUrl") %>',
browser: '<%= grunt.option("testBrowser") %>',
params: {
environment: '<%= grunt.option("testEnv") %>'
},
suite: '<%= grunt.option("testSuite") %>'
}
}
},
});
grunt.config('execute', {
email_stakeholders: {
options: {
args: [
process.env.testReportFilePath,
'myemail@email.com'
]
},
src: ['toDelete.js']
}
});
但是process.env.testReportFilePath
似乎undefined
在gruntjs文件中。
这个答案早就应该了。我确实按照@mparnisari建议将变量写到文件中。所以我在我的 conf 中做了以下操作.js将值写入 yaml 文件:
fs.writeFileSync(path.join(process.cwd(),'_testReportFilePath.yml'),
'testReportFilePath: ' + jasmine.getEnv().testReportFilePath);
在gruntfile
中,使用 grunt API 读取的 yaml 文件:
// --- grunt execute task --- //
grunt.config('execute', {
email_stakeholders: {
options: {
args:[
grunt.file.readYAML(path.join(process.cwd(),'_testReportFilePath.yml')).testReportFilePath, // html report
'myemail@email.com'//enter the recipient emails here
]
},
src: ['test/scripts/nightlyPostTasks.js']
}
});
并且似乎做了我需要的。唯一的怪癖是,名称为 _testReportFilePath.yml
的虚拟 yaml 文件必须始终存在于CWD
中,以防止任何咕噜咕噜的错误。
相关文章:
- 函数参数中的数据与指定变量之间的任何性能差异
- 全局变量和全局对象的属性之间有什么区别吗
- java.net和javascript之间正则表达式的差异
- JavaScript中的函数和对象之间没有区别吗?
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- Jquery在函数之间传递表行
- 根据某些条件在视图之间切换
- 在控制器和数据对象之间同步数据
- d3中堆栈函数和嵌套函数之间的差异
- 当使用Watchify时,Browserify+Babelify Gulp任务没有终止
- Ext JS Gannt 在任务之间添加链接
- 将值 fron conf.js 传递给咕噜咕噜的任务或在咕噜咕噜的任务之间传递
- 繁重的任务:删除 HTML 文件中标记之间的行
- 事件循环上下文中的微任务和宏任务之间的区别
- 有效地减少时间约束任务之间的等待时间
- Javascript'使用未声明函数作为对象的能力如何帮助在计算机之间划分任务?
- 在dev和prod之间切换任务
- 浏览器中的事件循环和任务队列之间有区别吗
- Gruntjs:我可以在不同的ftpush任务之间共享“身份验证”部分吗?
- 在项目之间重用Gulp任务