Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "guacamole", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "A friendly wrapper for the SauceLabs browser listing API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -190,2 +190,37 @@ # guacamole | ||
### Creating and Using a Shrinkwrap File / Allowing Synchronous Usage | ||
You can cache the results of the SauceLabs browser API: | ||
```console | ||
./node_modules/.bin/guacamole --generate-shrinkwrap | ||
Wrote guacamole shrinkwrap to /Users/example/myproject/guacamole-shrinkwrap.json | ||
``` | ||
This will cache a local copy of the SauceLabs API result, allowing you to bypass a network request and use the `guacamole` API in a synchronous fashion. To use the generated shrinkwrap, call `useShrinkwrap()`: | ||
```javascript | ||
var guacamole = require("guacamole"); | ||
// Tell guacamole to use ./guacamole-shrinkwrap.json | ||
guacamole.useShrinkwrap(); | ||
// Fetch a specific Firefox by id | ||
console.log(guacamole.get({ id: "firefox_38_OS_X_10_9_Desktop" })); | ||
// Yields: [{ browserName: 'firefox', version: '38', platform: 'OS X 10.9' }] | ||
``` | ||
If you have a shrinkwrap stored somewhere other than the default location, you can specify the location when calling `useShrinkwrap()`: | ||
```javascript | ||
// Tell guacamole to use ./settings/guacamole-shrinkwrap.json | ||
guacamole.useShrinkwrap("./settings/guacamole-shrinkwrap.json"); | ||
``` | ||
The same logic works on the command line version of `guacamole` with the `shrinkwrap` option: | ||
```console | ||
./node_modules/.bin/guacamole --shrinkwrap=./settings/guacamole-shrinkwrap.json --id=firefox_38_OS_X_10_9_Desktop | ||
{ browserName: 'firefox', version: '38', platform: 'OS X 10.9' } | ||
``` | ||
## Licenses | ||
@@ -192,0 +227,0 @@ |
@@ -5,2 +5,4 @@ var Q = require("q"); | ||
var browsers = []; | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
@@ -254,2 +256,16 @@ var SauceBrowsers = { | ||
// Signal that we want to load a shrinkwrap file (i.e. cached sauce labs API result) and bypass the Sauce API | ||
useShrinkwrap: function (shrinkwrapFilepath) { | ||
shrinkwrapFilepath = path.resolve(shrinkwrapFilepath || "./guacamole-shrinkwrap.json"); | ||
try { | ||
var data = JSON.parse(fs.readFileSync(shrinkwrapFilepath, "utf8")); | ||
if (data) { | ||
this._haveCachedSauceBrowsers = true; | ||
browsers = this._normalize(data); | ||
} | ||
} catch (e) { | ||
throw new Error("Could not read guacamole shrinkwrap file at : " + shrinkwrapFilepath); | ||
} | ||
}, | ||
// Return a promise that we'll build a list of supported browsers | ||
@@ -256,0 +272,0 @@ initialize: function () { |
Sorry, the diff of this file is not supported yet
495060
11
355
229
3