├── .gitignore ├── .eslintrc ├── .npmignore ├── CONTRIBUTING.md ├── test └── add.spec.js ├── .travis.yml ├── LICENSE ├── capture.template.js ├── gruntfile.js ├── CHANGELOG.md ├── karma.conf.js ├── README.md ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea/* -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "standard" 3 | } -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | 3 | Gruntfile.coffee 4 | CONTRIBUTING.md 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Please see the [Contributing to Karma] guide for information on contributing to this project. 2 | 3 | [Contributing to Karma]: https://github.com/karma-runner/karma/blob/master/CONTRIBUTING.md 4 | -------------------------------------------------------------------------------- /test/add.spec.js: -------------------------------------------------------------------------------- 1 | /* globals describe, it, expect */ 2 | describe('add', function () { 3 | it('adds two numbers', function () { 4 | function add (a, b) { 5 | return a + b 6 | } 7 | 8 | expect(add(1, 4)).toBe(5) 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | - "0.12" 5 | - "0.4" 6 | - "stable" 7 | 8 | before_install: 9 | - npm install -g npm 10 | - npm config set loglevel warn 11 | 12 | before_script: 13 | - npm install -g grunt-cli 14 | 15 | script: 16 | - grunt 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (C) 2011-2013 Google, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /capture.template.js: -------------------------------------------------------------------------------- 1 | (function (phantom) { 2 | var page = require('webpage').create(); 3 | 4 | <% if (exitOnResourceError) { %> 5 | page.onResourceError = function() { 6 | phantom.exit(1) 7 | } 8 | <% } %> 9 | 10 | <% _.forOwn(pageOptions, function(value, key) { %> 11 | page.<%= key %> = <%= value %> 12 | <% }) %> 13 | 14 | <% _.forOwn(pageSettingsOptions, function(value, key) { %> 15 | page.settings.<%= key %> = <%= value %> 16 | <% }) %> 17 | 18 | page.onConsoleMessage = function () { 19 | console.log.apply(console, arguments) 20 | } 21 | 22 | <% if (debug) { %> 23 | function debugPage() { 24 | console.log('Launch the debugger page at http://localhost:9000/webkit/inspector/inspector.html?page=2') 25 | 26 | var debuggerWait = 15000 27 | console.log('Waiting ' + (debuggerWait / 1000) + ' seconds for debugger page to launch...') 28 | 29 | var launchPage = function () { 30 | console.log('Launching page <%= url %>...') 31 | page.open('<%= url %>') 32 | } 33 | 34 | setTimeout(launchPage, 15000) 35 | } 36 | debugPage() 37 | <% } else { %> 38 | page.open('<%= url %>') 39 | <% } %> 40 | }(phantom)) 41 | -------------------------------------------------------------------------------- /gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | grunt.initConfig({ 3 | pkgFile: 'package.json', 4 | 'npm-contributors': { 5 | options: { 6 | commitMessage: 'chore: update contributors' 7 | } 8 | }, 9 | bump: { 10 | options: { 11 | commitFiles: [ 12 | 'package.json', 13 | 'CHANGELOG.md' 14 | ], 15 | commitMessage: 'chore: release v%VERSION%', 16 | pushTo: 'upstream' 17 | } 18 | }, 19 | 'auto-release': { 20 | options: { 21 | checkTravisBuild: false 22 | } 23 | }, 24 | eslint: { 25 | target: ['index.js', 'gruntfile.js', 'karma.conf.js', 'test/*.js'] 26 | }, 27 | karma: { 28 | all: { 29 | configFile: 'karma.conf.js' 30 | } 31 | } 32 | }) 33 | require('load-grunt-tasks')(grunt) 34 | grunt.registerTask('test', ['karma']) 35 | grunt.registerTask('default', ['eslint', 'test']) 36 | return grunt.registerTask('release', 'Bump the version and publish to NPM.', function (type) { 37 | return grunt.task.run(['npm-contributors', 'bump-only:' + (type || 'patch'), 'changelog', 'bump-commit', 'npm-publish']) 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | ### 0.2.2 (2015-12-24) 3 | 4 | 5 | #### Bug Fixes 6 | 7 | * pass PhantomJS script as the first cmd-line argument ([1c195c6b](https://github.com/karma-runner/karma-phantomjs-launcher/commit/1c195c6b)) 8 | * do not duplicate cmd-line flags on repeated PhantomJS runs ([76228f18](https://github.com/karma-runner/karma-phantomjs-launcher/commit/76228f18)) 9 | 10 | 11 | 12 | ### 0.2.1 (2015-08-05) 13 | 14 | 15 | #### Bug Fixes 16 | 17 | * ensure console output from phantomjs is available in karma debug logs ([eed281b5](https://github.com/karma-runner/karma-phantomjs-launcher/commit/eed281b5)) 18 | 19 | 20 | ## 0.2.0 (2015-05-29) 21 | 22 | 23 | #### Bug Fixes 24 | 25 | * **npm:** Make .npmignore more sensible to dot files ([1322a89d](https://github.com/karma-runner/karma-phantomjs-launcher/commit/1322a89d), closes [#68](https://github.com/karma-runner/karma-phantomjs-launcher/issues/68)) 26 | 27 | 28 | #### Features 29 | 30 | * Move phantomjs to peerDeps, #37, #42, #56 ([a0f399de](https://github.com/karma-runner/karma-phantomjs-launcher/commit/a0f399de), closes [#25](https://github.com/karma-runner/karma-phantomjs-launcher/issues/25)) 31 | * Support option for phantom to exit on ResourceError ([2b90c6b9](https://github.com/karma-runner/karma-phantomjs-launcher/commit/2b90c6b9)) 32 | * debug option ([c6dfe786](https://github.com/karma-runner/karma-phantomjs-launcher/commit/c6dfe786)) 33 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration 2 | // Generated on Fri May 29 2015 21:48:48 GMT+0200 (CEST) 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | // base path that will be used to resolve all patterns (eg. files, exclude) 7 | basePath: '', 8 | 9 | // frameworks to use 10 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 11 | frameworks: ['jasmine'], 12 | 13 | // list of files / patterns to load in the browser 14 | files: [ 15 | 'test/*.spec.js' 16 | ], 17 | 18 | // list of files to exclude 19 | exclude: [], 20 | 21 | // preprocess matching files before serving them to the browser 22 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 23 | preprocessors: { 24 | }, 25 | 26 | // test results reporter to use 27 | // possible values: 'dots', 'progress' 28 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter 29 | reporters: ['progress'], 30 | 31 | // web server port 32 | port: 9876, 33 | 34 | // enable / disable colors in the output (reporters and logs) 35 | colors: true, 36 | 37 | // level of logging 38 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 39 | logLevel: config.LOG_INFO, 40 | 41 | // enable / disable watching file and executing tests whenever any file changes 42 | autoWatch: false, 43 | 44 | // start these browsers 45 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 46 | browsers: ['PhantomJS2'], 47 | 48 | // Continuous Integration mode 49 | // if true, Karma captures browsers, runs the tests and exits 50 | singleRun: true, 51 | 52 | plugins: [ 53 | require('karma-jasmine'), 54 | require('./index') 55 | ] 56 | }) 57 | } 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | karma-phantomjs2-launcher 2 | ========================= 3 | 4 | karma-phantomjs2-launcher is depricated, use karma-phantomjs-launcher@1.0.0 instead 5 | ---------------------------------------------------------------------------------- 6 | 7 | > Launcher for [PhantomJS 2]. As for now it is temporary solution, until default karma-phantomjs-launcher is not support of the PhantomJS 2. PhantomJS 2 is not stable [PhantomJS-2](https://github.com/ariya/phantomjs/wiki/PhantomJS-2) Loading PhantomJS from custom URL can be done by setting the `PHANTOMJS2_DOWNLOAD_URL` environment variable. 8 | 9 | Installation 10 | ------------ 11 | 12 | The easiest way is to keep `karma-phantomjs2-launcher` as a devDependency in your `package.json`, 13 | by running 14 | 15 | ```bash 16 | $ npm install --save-dev karma-phantomjs2-launcher 17 | ``` 18 | 19 | Configuration 20 | ------------- 21 | 22 | ```js 23 | // karma.conf.js 24 | module.exports = function(config) { 25 | config.set({ 26 | browsers: ['PhantomJS2', 'PhantomJS2_custom'], 27 | 28 | // you can define custom flags 29 | customLaunchers: { 30 | 'PhantomJS2_custom': { 31 | base: 'PhantomJS2', 32 | options: { 33 | windowName: 'my-window', 34 | settings: { 35 | webSecurityEnabled: false 36 | }, 37 | }, 38 | flags: ['--load-images=true'], 39 | debug: true 40 | } 41 | }, 42 | 43 | phantomjsLauncher: { 44 | // Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom) 45 | exitOnResourceError: true 46 | } 47 | }) 48 | } 49 | ``` 50 | 51 | The `options` attribute allows you to initialize properties on 52 | the phantomjs `page` object, so 53 | 54 | ```js 55 | options: { 56 | windowName: 'my-window', 57 | settings: { 58 | webSecurityEnabled: false 59 | }, 60 | } 61 | ``` 62 | 63 | is equivalent to: 64 | 65 | ```js 66 | var webPage = require('webpage') 67 | var page = webPage.create() 68 | 69 | page.windowName = 'my-window' 70 | page.settings.webSecurityEnabled = false 71 | ``` 72 | 73 | You can pass list of browsers as a CLI argument too: 74 | 75 | ```bash 76 | $ karma start --browsers PhantomJS2_custom 77 | ``` 78 | 79 | --- 80 | 81 | For more information on Karma see the [homepage](http://karma-runner.github.com). 82 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "karma-phantomjs2-launcher", 3 | "version": "0.5.0", 4 | "description": "A Karma plugin. Launcher for PhantomJS 2. Slightly changed karma-phantomjs-launcher plugin.ß", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/gskachkov/karma-phantomjs2-launcher.git" 12 | }, 13 | "keywords": [ 14 | "karma-plugin", 15 | "karma-launcher", 16 | "phantomjs", 17 | "phantomjs2" 18 | ], 19 | "author": "Alexandr Skackhov ", 20 | "dependencies": { 21 | "lodash": "^3.10.1", 22 | "phantomjs2-ext": "^0.2.1" 23 | }, 24 | "peerDependencies": { 25 | "karma": ">=0.9" 26 | }, 27 | "license": "MIT", 28 | "devDependencies": { 29 | "eslint": "^1.0.0", 30 | "eslint-config-standard": "^4.0.0", 31 | "eslint-plugin-react": "^3.2.0", 32 | "eslint-plugin-standard": "^1.3.1", 33 | "grunt": "~0.4.5", 34 | "grunt-auto-release": "~0.0.6", 35 | "grunt-bump": "~0.3.1", 36 | "grunt-conventional-changelog": "^1.2.2", 37 | "grunt-eslint": "^17.0.0", 38 | "grunt-karma": "^0.12.1", 39 | "grunt-npm": "~0.0.2", 40 | "jasmine-core": "^2.3.4", 41 | "karma": "^0.13.6", 42 | "karma-jasmine": "^0.3.5", 43 | "load-grunt-tasks": "^3.2.0", 44 | "phantomjs2-ext": "^0.2.1" 45 | }, 46 | "contributors": [ 47 | "Vojta Jina ", 48 | "dignifiedquire ", 49 | "Friedel Ziegelmayer ", 50 | "Jurko Gospodnetić ", 51 | "Friedel Ziegelmayer ", 52 | "Dan Siwiec ", 53 | "Huafu Gandon ", 54 | "Sylvain Hamel ", 55 | "nherzing ", 56 | "Chad Smith ", 57 | "sylvain-hamel ", 58 | "Edward Hutchins ", 59 | "Eryk Napierała ", 60 | "Jason Dobry ", 61 | "Jonathan Park ", 62 | "Mark Derbecker ", 63 | "Nick Malaguti ", 64 | "Rob Barreca ", 65 | "kibin " 66 | ], 67 | "bugs": { 68 | "url": "https://github.com/gskachkov/karma-phantomjs2-launcher/issues" 69 | }, 70 | "homepage": "https://github.com/gskachkov/karma-phantomjs2-launcher" 71 | } 72 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | var path = require('path') 3 | var _ = require('lodash') 4 | 5 | function serializeOption (value) { 6 | if (typeof value === 'function') { 7 | return value.toString() 8 | } 9 | return JSON.stringify(value) 10 | } 11 | 12 | var phantomJSExePath = function () { 13 | // If the path we're given by phantomjs is to a .cmd, it is pointing to a global copy. 14 | // Using the cmd as the process to execute causes problems cleaning up the processes 15 | // so we walk from the cmd to the phantomjs.exe and use that instead. 16 | 17 |  var phantomSource = require('phantomjs2-ext').path 18 | 19 |  if (path.extname(phantomSource).toLowerCase() === '.cmd') { 20 |    return path.join(path.dirname( phantomSource ), '//node_modules//phantomjs2-ext//lib//phantom//phantomjs.exe') 21 |  } 22 | 23 | return phantomSource 24 | } 25 | 26 | var PhantomJSBrowser = function (baseBrowserDecorator, config, args, logger) { 27 | var log = logger.create('phantomjs.launcher') 28 | 29 | baseBrowserDecorator(this) 30 | 31 | var options = args && args.options || config && config.options || {} 32 | var providedFlags = args && args.flags || config && config.flags || [] 33 | 34 | this._start = function (url) { 35 | // create the js file that will open karma 36 | var captureFile = this._tempDir + '/capture.js' 37 | var pageOptions = {} 38 | var pageSettingsOptions = {} 39 | 40 | _.forOwn(options, function (optionsValue, optionsKey) { 41 | if (optionsKey !== 'settings') { // settings cannot be overriden, it should be extended! 42 | pageOptions[optionsKey] = serializeOption(optionsValue) 43 | } else { 44 | // key === settings 45 | _.forOwn(optionsValue, function (settingsValue, settingsKey) { 46 | pageSettingsOptions[settingsKey] = serializeOption(settingsValue) 47 | }) 48 | } 49 | }) 50 | 51 | var file = fs.readFileSync(path.join(__dirname, 'capture.template.js')) 52 | 53 | var compiled = _.template(file.toString()) 54 | var captureCode = compiled({ 55 | debug: args.debug, 56 | exitOnResourceError: config && config.exitOnResourceError, 57 | pageOptions: pageOptions, 58 | pageSettingsOptions: pageSettingsOptions, 59 | url: url 60 | }) 61 | 62 | fs.writeFileSync(captureFile, captureCode) 63 | 64 | // PhantomJS takes its script file as the first cmd-line argument 65 | var flags = [captureFile].concat(providedFlags) 66 | if (args.debug) { 67 | flags.push('--remote-debugger-port=9000') 68 | flags.push('--remote-debugger-autorun=yes') 69 | } 70 | 71 | // and start phantomjs 72 | this._execCommand(this._getCommand(), flags) 73 | 74 | this._process.stderr.on('data', function (data) { 75 | log.error('' + data) 76 | }) 77 | 78 | this._process.stdout.on('data', function (data) { 79 | log.debug('' + data) 80 | }) 81 | 82 | if (args.debug) { 83 | log.info('ACTION REQUIRED:') 84 | log.info('') 85 | log.info(' Launch browser at') 86 | log.info(' http://localhost:9000/webkit/inspector/inspector.html?page=2') 87 | log.info('') 88 | log.info('Waiting 15 seconds ...') 89 | } 90 | } 91 | } 92 | 93 | PhantomJSBrowser.prototype = { 94 | name: 'PhantomJS2', 95 | 96 | DEFAULT_CMD: { 97 | linux: require('phantomjs2-ext').path, 98 | darwin: require('phantomjs2-ext').path, 99 | win32: phantomJSExePath() 100 | }, 101 | ENV_CMD: 'PHANTOMJS_BIN' 102 | } 103 | 104 | PhantomJSBrowser.$inject = ['baseBrowserDecorator', 'config.phantomjsLauncher', 'args', 'logger'] 105 | 106 | // PUBLISH DI MODULE 107 | module.exports = { 108 | 'launcher:PhantomJS2': ['type', PhantomJSBrowser] 109 | } 110 | --------------------------------------------------------------------------------