如何将NodeJS测试包含在Gradle和Hudson中?

pat*_*rit 6 hudson gradle node.js hudson-plugins npm

我们是Scala/Java商店,我们使用Gradle进行构建,使用Hudson进行CI.我们最近在mocha中编写了一些带有测试的node.js代码.反正有没有把它包含在我们的哈德森的gradle工作流程和设置中?我查看了gradle-javascript-plugin,但我无法弄清楚如何通过它运行npm test或npm install,并且不确定如何让它通过gradle-build或gradle-test命令运行,并让Hudson选择它.

tec*_*don 3

我可以帮助你完成部分任务,我也在完成这项任务。确保您至少有 Gradle 1.2。

import org.gradle.plugins.javascript.coffeescript.CoffeeScriptCompile


apply plugin: 'coffeescript-base'

repositories {
  mavenCentral()
  maven {
    url 'http://repo.gradle.org/gradle/javascript-public'
  }
}

task compileCoffee(type: CoffeeScriptCompile){
  source fileTree('src')
  destinationDir file('lib')
}
Run Code Online (Sandbox Code Playgroud)

参考:http://gradle.1045684.n5.nabble.com/State-of-javascript-stuff-in-master-td5709818.html

提供了一种编译咖啡脚本的方法,我现在可以将 npm install cmd 添加到 groovy exec 请求和 barf 中,具体取决于提供 stdout/stderr 的 exec cmd 结果

npm install
echo $?
0
npm install
npm ERR! install Couldn't read dependencies
npm ERR! Failed to parse json
npm ERR! Unexpected token }
npm ERR! File: /<>/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! System Darwin 11.4.2
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! cwd /<>/
npm ERR! node -v v0.8.14
npm ERR! npm -v 1.1.65
npm ERR! file /<>/package.json
npm ERR! code EJSONPARSE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /<>/npm-debug.log
npm ERR! not ok code 0
echo $?
1
Run Code Online (Sandbox Code Playgroud)

结果是:

task npmDependencies {
  def proc = 'npm install'.execute()
  proc.in.eachLine { line -> println line}
  proc.err.eachLine { line -> println 'ERROR: '+line }
  proc.waitFor()
  if (proc.exitValue()!=0){
    throw new RuntimeException('NPM dependency installation failed!')
  }
}
Run Code Online (Sandbox Code Playgroud)

至于摩卡测试,我没有这方面的第一手知识,但我怀疑你可以类似地处理。