├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── README.md ├── appveyor.yml ├── extend.js ├── gulpfile.js ├── index.js ├── package.json └── test ├── fixture-fail.html ├── fixture-pass.html └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "bitwise": true, 3 | "camelcase": true, 4 | "curly": true, 5 | "eqeqeq": true, 6 | "esnext": true, 7 | "freeze": true, 8 | "immed": true, 9 | "indent": 2, 10 | "latedef": "nofunc", 11 | "laxcomma": true, 12 | "newcap": true, 13 | "noarg": true, 14 | "noempty": true, 15 | "nonew": true, 16 | "quotmark": "single", 17 | "regexp": true, 18 | "smarttabs": true, 19 | "strict": true, 20 | "trailing": true, 21 | "undef": true, 22 | "unused": true, 23 | "white": true, 24 | "browser": true, 25 | "node": true, 26 | "globals": { 27 | "describe": false, 28 | "it": false, 29 | "before": false, 30 | "beforeEach": false, 31 | "after": false, 32 | "afterEach": false, 33 | "define": false 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | .jshintrc 3 | .npmignore 4 | .travis.yml 5 | gulpfile.js 6 | Makefile 7 | test/ 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "4.2" 4 | - "5.5" 5 | sudo: false 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [gulp](https://github.com/wearefractal/gulp)-mocha-phantomjs [](https://travis-ci.org/mrhooray/gulp-mocha-phantomjs) [](https://ci.appveyor.com/project/mrhooray/gulp-mocha-phantomjs) 2 | > run client-side [Mocha](https://github.com/visionmedia/mocha) tests with [PhantomJS](https://github.com/ariya/phantomjs) 3 | 4 | > a simple wrapper for [mocha-phantomjs-core](https://github.com/nathanboktae/mocha-phantomjs-core) library 5 | 6 | ## Warning 7 | This project is no longer maintained. 8 | 9 | ## Installation 10 | ### node 11 | ```shell 12 | $ npm install gulp-mocha-phantomjs --save-dev 13 | ``` 14 | 15 | ## Usage 16 | ```html 17 | 18 | 19 |
20 |",
19 | "main": "index.js",
20 | "scripts": {
21 | "test": "gulp test"
22 | },
23 | "dependencies": {
24 | "gulp-util": "^3.0.7",
25 | "mocha-phantomjs-core": "^2.0.0",
26 | "phantomjs-prebuilt": "^2.1.4",
27 | "through2": "^2.0.1"
28 | },
29 | "devDependencies": {
30 | "gulp": "^3.9.1",
31 | "gulp-jshint": "^2.0.0",
32 | "gulp-mocha": "^2.2.0",
33 | "jshint": "^2.9.1",
34 | "mocha": "^2.4.5",
35 | "should": "^8.2.1"
36 | },
37 | "homepage": "https://github.com/mrhooray/gulp-mocha-phantomjs",
38 | "repository": {
39 | "type": "git",
40 | "url": "git://github.com/mrhooray/gulp-mocha-phantomjs.git"
41 | },
42 | "bugs": {
43 | "url": "https://github.com/mrhooray/gulp-mocha-phantomjs/issues"
44 | },
45 | "license": "MIT"
46 | }
47 |
--------------------------------------------------------------------------------
/test/fixture-fail.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mocha
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
20 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/test/fixture-pass.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mocha
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
38 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 | var path = require('path');
5 | var gutil = require('gulp-util');
6 | var mochaPhantomJS = require('../index');
7 | var out = process.stdout.write.bind(process.stdout);
8 |
9 | describe('gulp-mocha-phantomjs', function () {
10 | this.timeout(0);
11 |
12 | it('should pass when test passed', function (cb) {
13 | var file = new gutil.File({path: path.join(__dirname, 'fixture-pass.html')});
14 | var stream = mochaPhantomJS();
15 | var passed = false;
16 |
17 | stream.on('error', function () {
18 | assert.fail(undefined, undefined, 'should not emit error');
19 | });
20 |
21 | stream.on('finish', function () {
22 | assert.equal(passed, true);
23 | process.stdout.write = out;
24 | cb();
25 | });
26 |
27 | process.stdout.write = function (str) {
28 | if (/3 passing/.test(str)) {
29 | passed = true;
30 | }
31 | };
32 |
33 | stream.write(file);
34 | stream.end();
35 | });
36 |
37 | it('should fail build when test failed', function (cb) {
38 | var file = new gutil.File({path: path.join(__dirname, 'fixture-fail.html')});
39 | var stream = mochaPhantomJS();
40 |
41 | stream.on('error', function (err) {
42 | assert.equal(err.plugin, require('../package.json').name);
43 | process.stdout.write = out;
44 | cb();
45 | });
46 |
47 | process.stdout.write = function () {};
48 |
49 | stream.write(file);
50 | stream.end();
51 | });
52 |
53 | it('should fail silently in silent mode', function (cb) {
54 | var file = new gutil.File({path: path.join(__dirname, 'fixture-fail.html')});
55 | var stream = mochaPhantomJS({silent: true});
56 |
57 | stream.on('error', function () {
58 | assert.fail(undefined, undefined, 'should not emit error');
59 | });
60 |
61 | stream.on('finish', function () {
62 | process.stdout.write = out;
63 | cb();
64 | });
65 |
66 | process.stdout.write = function () {};
67 |
68 | stream.write(file);
69 | stream.end();
70 | });
71 |
72 | it('should use the tap reporter when chosen', function (cb) {
73 | var file = new gutil.File({path: path.join(__dirname, 'fixture-pass.html')});
74 | var stream = mochaPhantomJS({reporter: 'tap'});
75 | var passed = false;
76 |
77 | stream.on('error', function () {
78 | assert.fail(undefined, undefined, 'should not emit error');
79 | });
80 |
81 | stream.on('finish', function () {
82 | assert.equal(passed, true);
83 | process.stdout.write = out;
84 | cb();
85 | });
86 |
87 | process.stdout.write = function (str) {
88 | if (/# pass 3/.test(str)) {
89 | passed = true;
90 | }
91 | };
92 |
93 | stream.write(file);
94 | stream.end();
95 | });
96 |
97 | it('should pass through mocha options', function (cb) {
98 | var file = new gutil.File({path: path.join(__dirname, 'fixture-pass.html')});
99 | var stream = mochaPhantomJS({mocha: {grep: 'viewport'}});
100 | var passed = false;
101 |
102 | stream.on('error', function () {
103 | assert.fail(undefined, undefined, 'should not emit error');
104 | });
105 |
106 | stream.on('finish', function () {
107 | assert.equal(passed, true);
108 | process.stdout.write = out;
109 | cb();
110 | });
111 |
112 | process.stdout.write = function (str) {
113 | if (/1 passing/.test(str)) {
114 | passed = true;
115 | }
116 | if (/should be false/.test(str) || /should be true/.test(str)) {
117 | assert.fail();
118 | }
119 | };
120 |
121 | stream.write(file);
122 | stream.end();
123 | });
124 |
125 | it('should pass through phantomjs options', function (cb) {
126 | var file = new gutil.File({path: path.join(__dirname, 'fixture-pass.html')});
127 | var stream = mochaPhantomJS({
128 | phantomjs: {
129 | viewportSize: {
130 | width: 1,
131 | height: 1
132 | }
133 | }
134 | });
135 | var passed = false;
136 |
137 | stream.on('error', function () {
138 | assert.fail(undefined, undefined, 'should not emit error');
139 | });
140 |
141 | stream.on('finish', function () {
142 | assert.equal(passed, true);
143 | process.stdout.write = out;
144 | cb();
145 | });
146 |
147 | process.stdout.write = function (str) {
148 | if (/3 passing/.test(str)) {
149 | passed = true;
150 | }
151 | };
152 |
153 | stream.write(file);
154 | stream.end();
155 | });
156 |
157 | it('should handle uri with querystring properly', function (cb) {
158 | // mocha options with higher precedence
159 | var file = new gutil.File({path: path.join(__dirname, 'fixture-pass.html?grep=should')});
160 | var stream = mochaPhantomJS({mocha: {grep: 'viewport'}});
161 | var passed = false;
162 |
163 | stream.on('error', function () {
164 | assert.fail(undefined, undefined, 'should not emit error');
165 | });
166 |
167 | stream.on('finish', function () {
168 | assert.equal(passed, true);
169 | process.stdout.write = out;
170 | cb();
171 | });
172 |
173 | process.stdout.write = function (str) {
174 | if (/1 passing/.test(str)) {
175 | passed = true;
176 | }
177 | if (/should be false/.test(str) || /should be true/.test(str)) {
178 | assert.fail();
179 | }
180 | };
181 |
182 | stream.write(file);
183 | stream.end();
184 | });
185 | });
186 |
--------------------------------------------------------------------------------