├── .editorconfig ├── .eslintrc.json ├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── bin └── node-qunit-phantomjs ├── gulpfile.js ├── index.js ├── package-lock.json ├── package.json └── test ├── fixtures ├── async.html ├── console-log.html ├── custom-viewport.html ├── failing.html └── passing.html └── main.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | 10 | # Change these settings to your own preference 11 | indent_style = space 12 | indent_size = 4 13 | 14 | # We recommend you to keep these unchanged 15 | end_of_line = lf 16 | charset = utf-8 17 | trim_trailing_whitespace = true 18 | insert_final_newline = true 19 | 20 | [*.md] 21 | trim_trailing_whitespace = false 22 | 23 | [{package,bower}.json] 24 | indent_style = space 25 | indent_size = 2 26 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true, 4 | "node": true 5 | }, 6 | "globals": {}, 7 | "extends": "eslint:recommended", 8 | 9 | // Stop ESLint from looking for a configuration file in parent folders 10 | "root": true, 11 | 12 | "parser": "babel-eslint", 13 | "parserOptions": { 14 | "ecmaVersion": 8, 15 | "sourceType": "script", 16 | "ecmaFeatures": { 17 | "experimentalObjectRestSpread": true 18 | } 19 | }, 20 | "rules": { 21 | "block-scoped-var": 2, 22 | "complexity": [ 23 | 1, 24 | 5 25 | ], 26 | "consistent-return": 2, 27 | "curly": [ 28 | 2, 29 | "all" 30 | ], 31 | "dot-notation": 2, 32 | "eqeqeq": 2, 33 | "no-caller": 2, 34 | "no-console": 0, 35 | "no-else-return": 2, 36 | "no-eq-null": 2, 37 | "no-extend-native": 2, 38 | "no-implicit-coercion": 2, 39 | "no-loop-func": 2, 40 | "no-multi-spaces": 2, 41 | "no-multi-str": 2, 42 | "no-new-func": 2, 43 | "no-new-wrappers": 2, 44 | "no-new": 2, 45 | "no-param-reassign": 2, 46 | "no-unused-expressions": 2, 47 | "no-useless-call": 2, 48 | "no-useless-concat": 2, 49 | "no-with": 2, 50 | "vars-on-top": 2, 51 | "wrap-iife": [2, "any"], 52 | "yoda": [ 53 | 2, 54 | "never" 55 | ], 56 | 57 | "no-shadow": 2, 58 | "no-use-before-define": 2, 59 | 60 | "callback-return": 2, 61 | "handle-callback-err": 2, 62 | "no-path-concat": 2, 63 | 64 | "array-bracket-spacing": [ 65 | 1, 66 | "always", { 67 | "objectsInArrays": false 68 | } 69 | ], 70 | "block-spacing": 1, 71 | "brace-style": 1, 72 | "camelcase": [ 73 | 1, { 74 | "properties": "never" 75 | } 76 | ], 77 | "comma-spacing": [ 78 | 1, { 79 | "before": false, 80 | "after": true 81 | } 82 | ], 83 | "comma-style": [ 84 | 1, 85 | "last" 86 | ], 87 | "computed-property-spacing": [ 88 | 1, 89 | "never" 90 | ], 91 | "consistent-this": [ 92 | 1, 93 | "self" 94 | ], 95 | "eol-last": 1, 96 | "indent": [ 97 | 2, 98 | 4, { 99 | "SwitchCase": 1 100 | } 101 | ], 102 | "key-spacing": [ 103 | 1, { 104 | "beforeColon": false, 105 | "afterColon": true 106 | } 107 | ], 108 | "keyword-spacing": 1, 109 | "linebreak-style": [ 110 | 1, 111 | "unix" 112 | ], 113 | "lines-around-comment": [ 114 | 1, { 115 | "allowBlockStart": true, 116 | "beforeBlockComment": true, 117 | "beforeLineComment": true 118 | } 119 | ], 120 | "max-depth": [ 121 | 1, 122 | 4 123 | ], 124 | "max-params": [ 125 | 1, 126 | 3 127 | ], 128 | "max-statements": [ 129 | 1, 130 | 10 131 | ], 132 | "new-cap": 2, 133 | "new-parens": 2, 134 | "padding-line-between-statements": [ 135 | "error", 136 | { "blankLine": "always", "prev": ["const", "let", "var"], "next": "*"}, 137 | { "blankLine": "any", "prev": ["const", "let", "var"], "next": ["const", "let", "var"]} 138 | ], 139 | "no-array-constructor": 2, 140 | "no-bitwise": 1, 141 | "no-lonely-if": 1, 142 | "no-multiple-empty-lines": 1, 143 | "no-new-object": 2, 144 | "no-spaced-func": 1, 145 | "no-trailing-spaces": 1, 146 | "no-unneeded-ternary": 1, 147 | "object-curly-spacing": [ 148 | 1, 149 | "always" 150 | ], 151 | "operator-assignment": [ 152 | 1, 153 | "always" 154 | ], 155 | "operator-linebreak": [ 156 | 1, 157 | "after" 158 | ], 159 | "quote-props": [ 160 | 1, 161 | "consistent" 162 | ], 163 | "quotes": [ 164 | 1, 165 | "single" 166 | ], 167 | "semi": [ 168 | 2, 169 | "always" 170 | ], 171 | "semi-spacing": [ 172 | 1, { 173 | "before": false, 174 | "after": true 175 | } 176 | ], 177 | "space-before-blocks": [ 178 | 1, 179 | "always" 180 | ], 181 | "space-before-function-paren": [1, { "anonymous": "always", "named": "never" }], 182 | "space-in-parens": [1, "never"], 183 | "space-infix-ops": 1, 184 | "space-unary-ops": 0, 185 | "spaced-comment": [1, "always", { "line": { "exceptions": ["-"] } }] 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .editorconfig 2 | .gitignore 3 | .jshintrc 4 | .travis.yml 5 | gulpfile.js 6 | test 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '12' 4 | - '10' 5 | 6 | # whitelist 7 | branches: 8 | only: 9 | - master 10 | 11 | notifications: 12 | email: 13 | - kempdogg@gmail.com 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jonathan Kemp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-qunit-phantomjs [![Build Status](https://travis-ci.org/jonkemp/node-qunit-phantomjs.svg?branch=master)](https://travis-ci.org/jonkemp/node-qunit-phantomjs) 2 | 3 | [![NPM](https://nodei.co/npm/node-qunit-phantomjs.png?downloads=true)](https://nodei.co/npm/node-qunit-phantomjs/) 4 | 5 | > Run QUnit unit tests in a headless PhantomJS instance without using Grunt. 6 | 7 | Run QUnit unit tests in a PhantomJS-powered headless test runner, providing basic console output for QUnit tests. Uses the [phantomjs](https://github.com/Obvious/phantomjs) node module and the [PhantomJS Runner QUnit Plugin](https://github.com/jonkemp/qunit-phantomjs-runner). 8 | 9 | If you're using [gulp](https://github.com/gulpjs/gulp), you should take a look at the [gulp-qunit](https://github.com/jonkemp/gulp-qunit) plugin. 10 | 11 | 12 | ## Install 13 | 14 | Install with [npm](https://npmjs.org/package/node-qunit-phantomjs) 15 | 16 | globally: 17 | ```bash 18 | $ npm install -g node-qunit-phantomjs 19 | ``` 20 | 21 | or locally: 22 | ```bash 23 | $ npm install --save-dev node-qunit-phantomjs 24 | ``` 25 | 26 | ## Usage 27 | 28 | Via command line: 29 | ```bash 30 | $ node-qunit-phantomjs ./test/fixture.html 31 | ``` 32 | With options: 33 | ```bash 34 | $ node-qunit-phantomjs ./test/fixture.html --verbose 35 | 36 | $ node-qunit-phantomjs ./test/fixtures/passing.html --timeout=5 37 | 38 | $ node-qunit-phantomjs ./test/fixtures/passing.html --timeout 5 39 | ``` 40 | Example setting the viewport size: 41 | 42 | ```bash 43 | $ node-qunit-phantomjs ./test/fixture.html 5 '{"viewportSize":{"width":1000,"height":1000}}' 44 | ``` 45 | 46 | Or require it as a module: 47 | ```js 48 | var qunit = require('node-qunit-phantomjs'); 49 | 50 | qunit('./test/fixture.html'); 51 | ``` 52 | 53 | Verbose option to output list as test cases pass or fail: 54 | ```js 55 | var qunit = require('node-qunit-phantomjs'); 56 | 57 | qunit('./test/fixture.html', { 'verbose': true }); 58 | ``` 59 | 60 | Page option example to set the viewport size:: 61 | ```js 62 | var qunit = require('node-qunit-phantomjs'); 63 | 64 | qunit('./test/fixture.html', {'page': { 65 | viewportSize: { width: 1280, height: 800 } 66 | }}); 67 | ``` 68 | 69 | Sample [gulp](https://github.com/gulpjs/gulp) task: 70 | ```js 71 | var gulp = require('gulp'), 72 | qunit = require('node-qunit-phantomjs'); 73 | 74 | gulp.task('qunit', function() { 75 | qunit('./test/fixture.html'); 76 | }); 77 | ``` 78 | 79 | ## API 80 | 81 | ### qunit(path-to-test-runner[, options]); 82 | 83 | Opens a test runner file in PhantomJS and logs test results to the console. 84 | 85 | #### options.verbose 86 | 87 | Type: `Boolean` 88 | Default: `none` 89 | 90 | Add list as test cases pass or fail to output. 91 | 92 | #### options.phantomjs-options 93 | 94 | Type: `Array` 95 | Default: `None` 96 | 97 | These options are passed on to PhantomJS. See the [PhantomJS documentation](http://phantomjs.org/api/command-line.html) for more information. 98 | 99 | #### options.page 100 | 101 | Type: `Object` 102 | Default: `None` 103 | 104 | These options are passed on to PhantomJS. See the [PhantomJS documentation](http://phantomjs.org/page-automation.html) for more information. 105 | 106 | #### options.timeout 107 | 108 | Type: `Number` 109 | Default: `5` 110 | 111 | Pass a number or string value to override the default timeout of 5 seconds. 112 | 113 | 114 | #### options.customRunner 115 | 116 | Type: `String` 117 | Default: `None` 118 | 119 | A path to a custom PhantomJS runner script. A custom runner can be used to have more control over PhantomJS (configuration, hooks, etc.). Default runner implementations are provided by the [PhantomJS Runner QUnit Plugin](https://github.com/jonkemp/qunit-phantomjs-runner). 120 | 121 | ## License 122 | 123 | MIT © [Jonathan Kemp](http://jonkemp.com) 124 | -------------------------------------------------------------------------------- /bin/node-qunit-phantomjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | var path = require('path'), 5 | fs = require('fs'), 6 | dir = path.join(path.dirname(fs.realpathSync(__filename)), '..'), 7 | argv = require('minimist')(process.argv.slice(2)), 8 | options = { 9 | 'phantomjs-options': [], 10 | }; 11 | 12 | var argKeys = Object.keys(argv); 13 | 14 | for (var i = 0; i < argKeys.length; i++) { 15 | var key = argKeys[i]; 16 | if (key === 'verbose' && argv.verbose) { 17 | options.verbose = true; 18 | } else if (key === 'timeout') { 19 | options.timeout = Number(argv.timeout); 20 | } else if (key === 'page') { 21 | options.page = JSON.parse(argv.page); 22 | } else if (key === 'custom-runner') { 23 | options.customRunner = argv['custom-runner'] 24 | } else if (key !== '_') { 25 | options['phantomjs-options'].push('--' + key + '=' + argv[key]); 26 | } 27 | } 28 | 29 | require(path.join(dir, 'index.js'))(argv._[0], options, function (code) { 30 | process.exit(code); 31 | }); 32 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | const gulp = require('gulp'); 3 | const eslint = require('gulp-eslint'); 4 | const mocha = require('gulp-mocha'); 5 | const qunit = require('./index'); 6 | 7 | const paths = { 8 | scripts: ['./*.js', '!./gulpfile.js'] 9 | }; 10 | 11 | gulp.task('lint', () => gulp.src(paths.scripts) 12 | .pipe(eslint({fix: true})) 13 | .pipe(eslint.format())); 14 | 15 | gulp.task('test', () => gulp.src('./test/*.js') 16 | .pipe(mocha())); 17 | 18 | gulp.task('qunit:pass', () => { 19 | qunit('./test/fixtures/passing.html'); 20 | }); 21 | 22 | gulp.task('qunit:fail', () => { 23 | qunit('./test/fixtures/failing.html'); 24 | }); 25 | 26 | gulp.task('qunit-verbose', () => { 27 | qunit('./test/fixtures/passing.html', { 'verbose': true }); 28 | }); 29 | 30 | gulp.task('watch', () => { 31 | gulp.watch(paths.scripts, gulp.parallel('lint', 'test')); 32 | }); 33 | 34 | gulp.task('default', gulp.parallel('lint', 'test', 'watch')); 35 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const chalk = require('chalk'); 3 | const childProcess = require('child_process'); 4 | const phantomjs = require('phantomjs-prebuilt'); 5 | const binPath = phantomjs.path; 6 | const phantomjsRunnerDir = path.dirname(require.resolve('qunit-phantomjs-runner')); 7 | const isUrl = uri => uri.match(/^http(s?):/) !== null; 8 | 9 | module.exports = (uri, options, callback) => { 10 | const opt = options || {}; 11 | const cb = callback || (() => {}); 12 | let runner = path.join(phantomjsRunnerDir, 'runner-json.js'); 13 | const testUri = isUrl(uri) ? uri : `file:///${path.resolve(uri).replace(/\\/g, '/')}`; 14 | let childArgs = []; 15 | let proc; 16 | 17 | if (opt.verbose) { 18 | runner = path.join(phantomjsRunnerDir, 'runner-list.js'); 19 | } else if (opt.customRunner) { 20 | // A custom phantomjs runner can be used to have more control 21 | // over phantomjs configuration or to customize phantomjs hooks. 22 | runner = opt.customRunner; 23 | } 24 | 25 | if (opt['phantomjs-options'] && opt['phantomjs-options'].length) { 26 | if (Array.isArray(opt['phantomjs-options'])) { 27 | childArgs = childArgs.concat(opt['phantomjs-options']); 28 | } else { 29 | childArgs.push(opt['phantomjs-options']); 30 | } 31 | } 32 | 33 | childArgs.push( 34 | runner, 35 | testUri 36 | ); 37 | 38 | if (opt.timeout) { 39 | childArgs.push(opt.timeout); 40 | } 41 | 42 | if (opt.page) { 43 | // Push default timeout value unless specified otherwise 44 | if (!opt.timeout) { 45 | childArgs.push(5); 46 | } 47 | 48 | childArgs.push(JSON.stringify(opt.page)); 49 | } 50 | 51 | console.log(`Testing ${chalk.blue(testUri)}`); 52 | 53 | // phantomjs [phantomjs-options] runner testuri [timeout [page]] 54 | proc = childProcess.spawn(binPath, childArgs); 55 | 56 | proc.stdout.on('data', data => { 57 | let out; 58 | let test; 59 | let message; 60 | const line = data.toString().trim(); 61 | 62 | try { 63 | out = JSON.parse(line); 64 | } catch (err) { 65 | console.log(line); 66 | return; 67 | } 68 | 69 | if (out.exceptions) { 70 | for (test in out.exceptions) { 71 | console.log(`\n${chalk.red('Test failed')}: ${chalk.red(test)}: \n${out.exceptions[test].join('\n ')}`); 72 | } 73 | } 74 | 75 | if (out.result) { 76 | message = `Took ${out.result.runtime} ms to run ${out.result.total} tests. ${out.result.passed} passed, ${out.result.failed} failed.`; 77 | 78 | console.log(out.result.failed > 0 ? chalk.red(message) : chalk.green(message)); 79 | } 80 | }); 81 | 82 | proc.stderr.on('data', data => { 83 | console.log(data.toString().trim()); 84 | }); 85 | 86 | proc.on('close', code => cb(code)); 87 | }; 88 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-qunit-phantomjs", 3 | "version": "2.1.1", 4 | "description": "Run QUnit unit tests in a headless PhantomJS instance without using Grunt.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/jonkemp/node-qunit-phantomjs.git" 12 | }, 13 | "keywords": [ 14 | "qunit", 15 | "phantomjs", 16 | "test", 17 | "testing" 18 | ], 19 | "author": "Jonathan Kemp (http://jonkemp.com/)", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/jonkemp/node-qunit-phantomjs/issues" 23 | }, 24 | "homepage": "https://github.com/jonkemp/node-qunit-phantomjs", 25 | "dependencies": { 26 | "chalk": "^3.0.0", 27 | "minimist": "^1.2.0", 28 | "phantomjs-prebuilt": "^2.1.16", 29 | "qunit-phantomjs-runner": "^2.4.1" 30 | }, 31 | "devDependencies": { 32 | "babel-eslint": "^10.0.3", 33 | "gulp": "^4.0.2", 34 | "gulp-eslint": "^6.0.0", 35 | "gulp-mocha": "^7.0.2", 36 | "mocha": "*", 37 | "qunit": "^2.9.3", 38 | "strip-ansi": "^6.0.0" 39 | }, 40 | "bin": { 41 | "node-qunit-phantomjs": "./bin/node-qunit-phantomjs" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/fixtures/async.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QUnit Test Suite 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 16 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /test/fixtures/console-log.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QUnit Test Suite 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 16 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /test/fixtures/custom-viewport.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QUnit Test Suite 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 16 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/fixtures/failing.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QUnit Test Suite 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 16 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /test/fixtures/passing.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QUnit Test Suite 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 16 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /test/main.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* global describe, it */ 3 | 4 | const assert = require('assert'); 5 | const stripAnsi = require('strip-ansi'); 6 | const qunit = require('../index'); 7 | const out = process.stdout.write.bind(process.stdout); 8 | 9 | describe('node-qunit-phantomjs', function () { 10 | this.timeout(10000); 11 | 12 | it('tests should pass', cb => { 13 | qunit('test/fixtures/passing.html'); 14 | 15 | process.stdout.write = str => { 16 | //out(str); 17 | str = stripAnsi(str); 18 | 19 | if (/10 passed. 0 failed./.test(str)) { 20 | assert(true); 21 | process.stdout.write = out; 22 | cb(); 23 | } 24 | }; 25 | }); 26 | 27 | it('tests should fail', done => { 28 | qunit('test/fixtures/failing.html'); 29 | 30 | process.stdout.write = str => { 31 | //out(str); 32 | str = stripAnsi(str); 33 | 34 | if (/10 passed. 1 failed./.test(str)) { 35 | assert(true); 36 | process.stdout.write = out; 37 | done(); 38 | } 39 | }; 40 | }); 41 | 42 | it('tests should not be affected by console.log in test code', cb => { 43 | qunit('test/fixtures/console-log.html'); 44 | 45 | process.stdout.write = str => { 46 | //out(str); 47 | str = stripAnsi(str); 48 | 49 | if (/10 passed. 0 failed./.test(str)) { 50 | assert(true); 51 | process.stdout.write = out; 52 | cb(); 53 | } 54 | }; 55 | }); 56 | 57 | it('tests should pass with options', cb => { 58 | qunit('test/fixtures/passing.html', {'phantomjs-options': ['--ssl-protocol=any']}); 59 | 60 | process.stdout.write = str => { 61 | //out(str); 62 | str = stripAnsi(str); 63 | 64 | if (/10 passed. 0 failed./.test(str)) { 65 | assert(true); 66 | process.stdout.write = out; 67 | cb(); 68 | } 69 | }; 70 | }); 71 | 72 | it('tests should pass with more than one options', cb => { 73 | qunit('test/fixtures/passing.html', {'phantomjs-options': ['--ignore-ssl-errors=true', '--web-security=false']}); 74 | 75 | process.stdout.write = str => { 76 | //out(str); 77 | str = stripAnsi(str); 78 | 79 | if (/10 passed. 0 failed./.test(str)) { 80 | assert(true); 81 | process.stdout.write = out; 82 | cb(); 83 | } 84 | }; 85 | }); 86 | 87 | it('should set custom viewport', done => { 88 | qunit('test/fixtures/custom-viewport.html', {'page': { 89 | viewportSize: { width: 1280, height: 800 } 90 | }}); 91 | 92 | process.stdout.write = str => { 93 | //out(str); 94 | str = stripAnsi(str); 95 | 96 | if (/2 passed. 0 failed./.test(str)) { 97 | assert(true); 98 | process.stdout.write = out; 99 | done(); 100 | } 101 | }; 102 | }); 103 | 104 | it('tests should not run when passing --help to PhantomJS', cb => { 105 | qunit('test/fixtures/passing.html', {'phantomjs-options': ['--help']}); 106 | 107 | process.stdout.write = str => { 108 | //out(str); 109 | 110 | if (/10 passed. 0 failed./.test(str)) { 111 | assert(false, 'No tests should run when passing --help to PhantomJS'); 112 | process.stdout.write = out; 113 | cb(); 114 | return; 115 | } 116 | 117 | const lines = str.split('\n'); 118 | for (let i = 0; i < lines.length; i++) { 119 | const line = lines[i]; 120 | if (/.*--help.*Shows this message and quits/.test(line)) { 121 | assert(true); 122 | process.stdout.write = out; 123 | cb(); 124 | } 125 | } 126 | }; 127 | }); 128 | 129 | it('tests should time out', cb => { 130 | 131 | qunit('test/fixtures/async.html', { 'timeout': 1 }); 132 | 133 | process.stdout.write = str => { 134 | //out(str); 135 | 136 | if (/The specified timeout of 1 seconds has expired. Aborting.../.test(str)) { 137 | assert(true); 138 | process.stdout.write = out; 139 | cb(); 140 | } 141 | }; 142 | }); 143 | }); 144 | --------------------------------------------------------------------------------