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

Commit

Permalink
CHANGED Browser.default.<name> = <value> deprecated, use Browser.<nam…
Browse files Browse the repository at this point in the history
…e> = <value> instead
  • Loading branch information
assaf committed Feb 25, 2015
1 parent 4abd686 commit ad12d11
Show file tree
Hide file tree
Showing 34 changed files with 162 additions and 157 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ CHANGED Browser.debug -> browser.debug (per instance)

CHANGED browser.referer -> browser.referrer

CHANGED Browser.default.<name> = <value> deprecated, use Browser.<name> = <value> instead

CHANGED timeout event -> setTimeout, interval -> setInterval

CHANGED removed onalert/onconfirm/onprompt, use browser.on('alert', fn) etc
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ shortcut for making these three changes:
to 127.0.0.1 (see [DNS Masking](#dnsmasking))
- `Browser.ports.map(hostname, port)` will redirect any HTTP request to hostname
from port 80 to the designated port (see [Port Mapping](#portmapping))
- `Browser.default.site = hostname` will add the hostname to any relative URL
- `Browser.site = hostname` will add the hostname to any relative URL
(e.g. when using `browser.visit`)


Expand Down Expand Up @@ -1046,7 +1046,7 @@ example:

```
Browser.dns.localhost('*.example.com');
Browser.default.site = 'http://example.com:3000';
Browser.site = 'http://example.com:3000';
browser = new Browser();
browser.visit('/here', function(error, browser) {
Expand Down Expand Up @@ -1116,7 +1116,7 @@ To see what your code is doing, you can use `console.log` and friends from both
client-side scripts and your test code.

If you want to disable console output from scripts, set `browser.silent = true`
or once for all browser instances with `Browser.default.silent = true`.
or once for all browser instances with `Browser.silent = true`.

For more details about what Zombie is doing (windows opened, requests made,
event loop, etc), run with the environment variable `DEBUG=zombie`. Alternatively,
Expand Down
83 changes: 44 additions & 39 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Tabs = require('./tabs');
const Console = require('./console');
const Cookies = require('./cookies');
const debug = require('debug');
const { deprecate } = require('util');
const DNSMask = require('./dns_mask');
const DOM = require('./dom');
const { EventEmitter } = require('events');
Expand Down Expand Up @@ -181,12 +182,9 @@ class Browser extends EventEmitter {
});

// Sets the browser options.
for (let name of BROWSER_OPTIONS) {
if (options && options.hasOwnProperty(name))
this[name] = options[name];
else if (Browser.default.hasOwnProperty(name))
this[name] = Browser.default[name];
}
options = options || {};
for (let name of BROWSER_OPTIONS)
this[name] = options.hasOwnProperty(name) ? options[name] : Browser[name];

// Last, run all extensions in order.
for (let extension of Browser._extensions)
Expand Down Expand Up @@ -1276,12 +1274,12 @@ class Browser extends EventEmitter {
//
// This is equivalent to DNS masking the hostname as 127.0.0.1 (see
// Browser.dns), mapping port 80 to the specified port (see Browser.ports) and
// setting Browser.default.site to the hostname.
// setting Browser.site to the hostname.
static localhost(hostname, port) {
this.dns.localhost(hostname);
this.ports.map(hostname, port);
if (!this.default.site)
this.default.site = hostname.replace(/^\*\./, '');
if (!this.site)
this.site = hostname.replace(/^\*\./, '');
}

// Register a browser extension.
Expand All @@ -1302,53 +1300,60 @@ Object.assign(Browser, {
Resources,
VERSION,

// These defaults are used in any new browser instance.
default: {
// -- These defaults are used in any new browser instance --

// Which features are enabled.
features: DEFAULT_FEATURES,
// Which features are enabled.
features: DEFAULT_FEATURES,

// Tells the browser how many redirects to follow before aborting a request. Defaults to 5
maxRedirects: 5,
// Tells the browser how many redirects to follow before aborting a request. Defaults to 5
maxRedirects: 5,

// Proxy URL.
//
// Example
// Browser.default.proxy = 'http://myproxy:8080'
proxy: null,
// Proxy URL.
//
// Example
// Browser.proxy = 'http://myproxy:8080'
proxy: null,

// If true, supress `console.log` output from scripts (ignored when DEBUG=zombie)
silent: false,
// If true, supress `console.log` output from scripts (ignored when DEBUG=zombie)
silent: false,

// You can use visit with a path, and it will make a request relative to this host/URL.
site: undefined,
// You can use visit with a path, and it will make a request relative to this host/URL.
site: undefined,

// Check SSL certificates against CA. False by default since you're likely
// testing with a self-signed certificate.
strictSSL: false,
// Check SSL certificates against CA. False by default since you're likely
// testing with a self-signed certificate.
strictSSL: false,

// Sets the outgoing IP address in case there is more than on available.
// Defaults to 0.0.0.0 which should select default interface
localAddress: '0.0.0.0',
// Sets the outgoing IP address in case there is more than on available.
// Defaults to 0.0.0.0 which should select default interface
localAddress: '0.0.0.0',

// User agent string sent to server.
userAgent: `Mozilla/5.0 Chrome/10.0.613.0 Safari/534.15 Zombie.js/${VERSION}`,
// User agent string sent to server.
userAgent: `Mozilla/5.0 Chrome/10.0.613.0 Safari/534.15 Zombie.js/${VERSION}`,

// Navigator language code
language: 'en-US',
// Navigator language code
language: 'en-US',

// Default time to wait (visit, wait, etc).
waitDuration: '5s',
// Default time to wait (visit, wait, etc).
waitDuration: '5s',

// Indicates whether or not to validate and execute JavaScript, default true.
runScripts: true
// Indicates whether or not to validate and execute JavaScript, default true.
runScripts: true,

get default() {
return Browser._getDefaults(this);
},

// -- Internal properties --

// Debug instance. Create new instance when enabling debugging with Zombie.debug
_debug: debug('zombie'),

// Browser extensions;
_extensions: []
_extensions: [],

_getDefaults: deprecate(browser => browser,
'Browser.default.<name> = <value> deprecated, please use Browser.<name> = <value> instead')

});

Expand Down
4 changes: 2 additions & 2 deletions test/angular_compat_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Browser = require('../src');
const { brains } = require('./helpers');
const brains = require('./helpers/brains');
const Browser = require('../src');


describe.skip('angularjs', function() {
Expand Down
5 changes: 2 additions & 3 deletions test/assert_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const assert = require('assert');
const Browser = require('../src');
const { brains } = require('./helpers');
const brains = require('./helpers/brains');
const Browser = require('../src');


describe('Browser assert', function() {
Expand Down
5 changes: 2 additions & 3 deletions test/authentication_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const assert = require('assert');
const Browser = require('../src');
const { brains } = require('./helpers');
const brains = require('./helpers/brains');
const Browser = require('../src');


describe('Authentication', function() {
Expand Down
14 changes: 11 additions & 3 deletions test/browser_events_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert');
const Browser = require('../src');
const { brains } = require('./helpers');
const assert = require('assert');
const brains = require('./helpers/brains');
const Browser = require('../src');


describe('Browser events', function() {
Expand All @@ -16,6 +16,10 @@ describe('Browser events', function() {
});

describe('sending output to console', function() {
before(function() {
browser.silent = true;
});

before(function() {
browser.on('console', function(level, message) {
events.console.push({ level: level, message: message });
Expand All @@ -33,6 +37,10 @@ describe('Browser events', function() {
assert.deepEqual(events.console[0].message, 'Logging message');
assert.deepEqual(events.console[1].message, 'Some [Error: error]');
});

after(function() {
browser.silent = false;
});
});


Expand Down
14 changes: 7 additions & 7 deletions test/browser_object_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const assert = require('assert');
const Browser = require('../src');
const { brains } = require('./helpers');
const JSDOM = require('jsdom');
const assert = require('assert');
const brains = require('./helpers/brains');
const Browser = require('../src');
const JSDOM = require('jsdom');


describe('Browser', function() {
Expand Down Expand Up @@ -292,8 +292,8 @@ describe('Browser', function() {
let originalFeatures;

before(function() {
originalFeatures = Browser.default.features;
Browser.default.features = 'no-scripts';
originalFeatures = Browser.features;
Browser.features = 'no-scripts';
newBrowser = Browser.create();
return newBrowser.visit('/browser/scripted');
});
Expand All @@ -304,7 +304,7 @@ describe('Browser', function() {

after(function() {
newBrowser.destroy();
Browser.default.features = originalFeatures;
Browser.features = originalFeatures;
});
});

Expand Down
6 changes: 3 additions & 3 deletions test/cookies_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert');
const Browser = require('../src');
const { brains } = require('./helpers');
const assert = require('assert');
const brains = require('./helpers/brains');
const Browser = require('../src');


// Parse string with cookies in it (like document.cookies) and return object
Expand Down
4 changes: 2 additions & 2 deletions test/css_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Browser = require('../src');
const { brains } = require('./helpers');
const brains = require('./helpers/brains');
const Browser = require('../src');


describe('CSS', function() {
Expand Down
7 changes: 4 additions & 3 deletions test/document_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const assert = require('assert');
const Browser = require('../src');
const { brains } = require('./helpers');
const assert = require('assert');
const brains = require('./helpers/brains');
const Browser = require('../src');


describe('Document', function() {
const browser = new Browser();
Expand Down
6 changes: 3 additions & 3 deletions test/event_loop_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert');
const Browser = require('../src');
const { brains } = require('./helpers');
const assert = require('assert');
const brains = require('./helpers/brains');
const Browser = require('../src');


describe('EventLoop', function() {
Expand Down
6 changes: 3 additions & 3 deletions test/event_source_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert');
const Browser = require('../src');
const { brains } = require('./helpers');
const assert = require('assert');
const brains = require('./helpers/brains');
const Browser = require('../src');


describe('EventSource', function() {
Expand Down
12 changes: 6 additions & 6 deletions test/forms_test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const assert = require('assert');
const Browser = require('../src');
const { brains } = require('./helpers');
const File = require('fs')
const Crypto = require('crypto');
const assert = require('assert');
const brains = require('./helpers/brains');
const Browser = require('../src');
const File = require('fs')
const Crypto = require('crypto');


describe('Forms', function() {
Expand Down Expand Up @@ -1100,7 +1100,6 @@ describe('Forms', function() {
// File upload
describe('file upload', function() {
before(function() {
});
brains.static('/forms/upload', `
<html>
<body>
Expand Down Expand Up @@ -1130,6 +1129,7 @@ describe('Forms', function() {
} else
res.send('<html><body>nothing</body></html>');
});
});


describe('text', function() {
Expand Down
6 changes: 3 additions & 3 deletions test/google_map_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert');
const Browser = require('../src');
const { brains } = require('./helpers');
const assert = require('assert');
const brains = require('./helpers/brains');
const Browser = require('../src');


describe('Google map', function() {
Expand Down
19 changes: 16 additions & 3 deletions test/helpers/first.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
const Bluebird = require('bluebird');
// Enable ES6/7 before loading the Browser
const babel = require('babel/register');


babel({
experimental: true,
loose: 'all'
});


const Bluebird = require('bluebird');
const Browser = require('../../src');
const Replay = require('replay');


// Tests visit example.com, server is localhost port 3003
Browser.localhost('*.example.com', 3003);
Browser.default.site = 'example.com';

// Redirect all HTTP requests to localhost
Replay.fixtures = __dirname + '/../replay';
Replay.networkAccess = true;
Replay.localhost('*.example.com');

// Long stack traces when running this test suite
Bluebird.longStackTraces();

22 changes: 0 additions & 22 deletions test/helpers/index.js

This file was deleted.

Loading

0 comments on commit ad12d11

Please sign in to comment.