Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将conf.js的值传递给grunt任务或grunt任务之间_Javascript_Node.js_Gruntjs_Protractor - Fatal编程技术网

Javascript 将conf.js的值传递给grunt任务或grunt任务之间

Javascript 将conf.js的值传递给grunt任务或grunt任务之间,javascript,node.js,gruntjs,protractor,Javascript,Node.js,Gruntjs,Protractor,如何在grunt任务之间传递信息?我想将一个值从一个grunt任务传递到另一个grunt任务 我的情况是,在完成量角器测试后,我想将一个值传递给一个新的grunt任务。为了实现这一点,我继续在process.env中设置值,并尝试在新的grunt任务中使用process.env。但这似乎不起作用 这是conf.js: afterLaunch: function(exitCode) { return new Promise(function(fulfill, reject) {

如何在
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'));
      }
    });
这是我的
Grunfile

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']
  }
});
grunt.loadNpmTasks('grunt-progrator-runner');
loadNpmTasks('grunt-gragrator-webdriver');
glunt.loadNpmTasks('grunt-execute');
grunt.config('量角器'{
require:[setTesting],
选项:{
configFile:'conf.js',//公共配置文件
keepAlive:true,//如果为false,则当测试失败时grunt进程停止。
noColor:false//如果为true,量角器将不会在其输出中使用颜色。
},
运行特定的\u套件:{
选项:{
args:{
baseUrl:“”,
浏览器:“”,
参数:{
环境:“”
},
套件:“”
}
}
},
});
grunt.config('execute'{
向利益相关者发送电子邮件:{
选项:{
args:[
process.env.testReportFilePath,
'myemail@email.com'
]
},
src:['toDelete.js']
}
});

但是在gruntjs文件中,
process.env.testReportFilePath
似乎是
未定义的

这个答案早就应该给出了。我确实按照@mparnisari的建议将变量写到文件中。因此,我在conf.js中执行了以下操作,将值写入yaml文件:

fs.writeFileSync(path.join(process.cwd(),“\u 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']
    }
  });

而且似乎做了我需要的事情。唯一奇怪的是,名为
\u testReportFilePath.yml
的伪yaml文件必须始终存在于
CWD
中,以防止任何grunt错误

我看不到
conf.js
和您的Grunfile之间的关系。你什么时候调用conf.js?您不能将
testReportFilePath
变量写入一个文件,然后让Grunt任务从那里获取它吗?@mparnisari:conf.js是一个基于以下内容的量角器配置文件:,它是使用Grunt任务插件运行的:Grunt Digrator runner。我将更新OP以包含grunt量角器运行任务。@mparnisari:我不想持久化并销毁该值。但这就是grunt任务中传递值的方式吗?不,我认为最常用的方法就是使用共享变量。您案例中的问题是Grunt和Gradurator可能在不同的进程中运行