跳到主要内容
CNode

Gulp.js插件 gulp-mocha-phantomjs

社区
Mmrhooray发布于 13 年前
057490

如果你需要写客户端测试,可以试试看gulp-mocha-phantomjs 用Mocha作为测试框架,Gulp.js作为build system,测试跑在PhantomJS里

安装

node

$ npm install gulp-mocha-phantomjs --save-dev

用法

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mocha Test Runner</title>
    <link rel="stylesheet" href="bower_components/mocha/mocha.css">
  </head>
  <body>
    <div id="mocha"></div>
    <script src="bower_components/mocha/mocha.js"></script>
    <script src="bower_components/should/should.js"></script>
    <script>mocha.setup('bdd')</script>
    <script src="spec/test.js"></script>
    <script>
      if (window.mochaPhantomJS) {
        mochaPhantomJS.run();
      } else {
        mocha.run();
      }
    </script>
  </body>
</html>
var gulp = require('gulp');
var mochaPhantomJS = require('gulp-mocha-phantomjs');

gulp.task('test', function () {
  return gulp
  .src('test/runner.html')
  .pipe(mochaPhantomJS());
});

也可指定Mocha的reporter类型

gulp.task('test', function () {
  return gulp
  .src('test/runner.html')
  .pipe(mochaPhantomJS({reporter: 'nyan'}));
});
查看回复

回复 (0)

暂无回复,成为第一个参与讨论的人。

参与回复

登录后即可参与回复。登录