Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
feat: initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Aug 7, 2013
0 parents commit 20f10ec
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*
Gruntfile.coffee
CONTRIBUTING.md
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Please see the [Contributing to Karma] guide for information on contributing to this project.

[Contributing to Karma]: https://github.com/karma-runner/karma/blob/master/CONTRIBUTING.md
29 changes: 29 additions & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = (grunt) ->

# Project configuration.
grunt.initConfig
pkgFile: 'package.json'

'npm-contributors':
options:
commitMessage: 'chore: update contributors'

bump:
options:
commitMessage: 'chore: release v%VERSION%'
pushTo: 'upstream'

'auto-release':
options:
checkTravisBuild: false

grunt.loadNpmTasks 'grunt-npm'
grunt.loadNpmTasks 'grunt-bump'
grunt.loadNpmTasks 'grunt-auto-release'

grunt.registerTask 'release', 'Bump the version and publish to NPM.', (type) ->
grunt.task.run [
'npm-contributors',
"bump:#{type||'patch'}",
'npm-publish'
]
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License

Copyright (C) 2011-2013 Vojta Jína and contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# karma-browserstack-launcher

> Use any browser on [BrowserStack](http://www.browserstack.com/)!
**NOTE:** You have to run local tunnel first:
```bash
$ java -jar BrowserStackTunnel.jar <KEY> localhost,9876,0
```


## Installation

The easiest way is to keep `karma-browserstack-launcher` as a devDependency in your `package.json`.
```json
{
"devDependencies": {
"karma": "~0.10",
"karma-browserstack-launcher": "~0.1"
}
}
```

You can also add it by this command:
```bash
npm install karma-browserstack-launcher --save-dev
```


## Configuration

```js
// karma.conf.js
module.exports = function(config) {
config.set({
// global config of your BrowserStack account
browserStack: {
username: 'jamesbond',
accessKey: '007'
},

// define browsers
customLaunchers: {
bs_firefox_mac: {
base: 'BrowserStack',
browser: 'firefox',
os: 'mac',
version: '21.0'
}
},

browsers: ['bs_firefox_mac']
});
};
```

### Global options
- `username` your BS username (email), you can also use `BROWSER_STACK_USERNAME` env variable.
- `accessKey` your BS access key (password), you can also use `BROWSER_STACK_ACCESS_KEY` env variable.


### Per browser options
- `browser` name of the browser
- `version` version of the browser
- `os` which platform ?

For an example project of, check out Karma's [e2e test](https://github.com/karma-runner/karma/tree/master/test/e2e/browserstack).


----

For more information on Karma see the [homepage](http://karma-runner.github.io).
82 changes: 82 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var api = require('browserstack');

var createBrowserStackClient = function(/* config.browserStack */ config) {
var env = process.env;

// TODO(vojta): handle no username/pwd
return api.createClient({
username: env.BROWSER_STACK_USERNAME || config.username,
password: env.BROWSER_STACK_ACCESS_KEY || config.accessKey
});
};

var formatError = function(error) {
if (error.message === 'Validation Failed') {
return ' Validation Failed: you probably misconfigured the browser ' +
'or given browser is not available.';
}

return error.toString();
};


var BrowserStackBrowser = function(id, emitter, /* browserStackClient */ client, args, logger) {
var self = this;
var workerId = null;
var captured = false;
var log = logger.create('launcher.browserstack');
var browserName = args.browser + (args.version ? ' ' + args.version : '') +
(args.os ? ' (' + args.os + ')' : '') + ' on BrowserStack';

this.id = id;
this.name = browserName;

this.start = function(url) {
// TODO(vojta): handle non os/browser/version
var settings = {
os: args.os,
browser: args.browser,
version: args.version || 'latest',
url: url + '?id=' + id
};

client.createWorker(settings, function(error, worker) {
if (error) {
log.error('Can not start %s\n %s', browserName, formatError(error));
return emitter.emit('browser_process_failure', self);
}

log.debug('Browser %s started with id %s', browserName, worker.id);
workerId = worker.id;
});
};

this.kill = function(done) {
if (!workerId) {
done();
}

log.debug('Killing worker %s', workerId);
client.terminateWorker(workerId, done);
};


this.markCaptured = function() {
captured = true;
};

this.isCaptured = function() {
return captured;
};

this.toString = function() {
return this.name;
};
};


// PUBLISH DI MODULE
module.exports = {
'browserStackClient': ['factory', createBrowserStackClient],
'launcher:BrowserStack': ['type', BrowserStackBrowser]
};
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "karma-browserstack-launcher",
"version": "0.0.0",
"description": "A Karma plugin. Launch any browser on BrowserStack!",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/karma-runner/karma-browserstack-launcher.git"
},
"keywords": [
"karma-plugin",
"karma-launcher",
"browserstack",
"browser-stack"
],
"author": "Vojta Jina <vojta.jina@gmail.com>",
"dependencies": {
"browserstack": "~0.2.0"
},
"peerDependencies": {
"karma": ">=0.9"
},
"license": "MIT",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-bump": "~0.0.7",
"grunt-npm": "~0.0.2",
"grunt-auto-release": "~0.0.2"
},
"contributors": []
}

0 comments on commit 20f10ec

Please sign in to comment.