Permalink
Browse files

Add automated browser testing

This adds a `test-saucelabs` script to package.json that uses [zuul] to
run tests on browsers using [SauceLabs].

Zuul is setup to test the browsers in the current [browserslist] defaults
list (shown at <http://browserl.ist>), constrained to what zuul
supports, according to:

    ./node_modules/.bin/zuul --list-available-browsers

(Opera 11 fails on SauceLabs, so skip it)

---

Travis CI is configured to run these tests if the `SAUCE_USERNAME` and
`SAUCE_ACCESS_KEY` environment variables are set. These credentials can
be obtained for free by [signing up] for the SauceLabs Open Source
program. Travis offers a way to set environment variables in the [build
settings], or they can be [encrypted] and added to the .travis.yml file.

Here's what a build looks like with this change:
https://travis-ci.org/josephfrazier/xregexp/builds/220784295

---

This also includes a slight refactor that moves `beforeEach` calls from
test helpers into spec files, because having them in the helpers doesn't
work with zuul. There is a `test-browser` script that can be used to run
zuul locally.

[zuul]: https://github.com/defunctzombie/zuul
[SauceLabs]: https://saucelabs.com/open-source
[browserslist]: https://github.com/ai/browserslist
[signing up]: https://saucelabs.com/beta/signup/OSS/None
[build settings]: https://travis-ci.org/slevithan/xregexp/settings
[encrypted]: https://docs.travis-ci.com/user/environment-variables/#Defining-encrypted-variables-in-.travis.yml
  • Loading branch information...
josephfrazier committed Feb 16, 2017
1 parent a5e5f43 commit 28a77c02c543188cbf187843f5e891fb2d3bdd8a
View
@@ -1,3 +1,6 @@
language: node_js
node_js:
- node
script:
- npm test
- '[ -z "$SAUCE_USERNAME" ] || [ -z "$SAUCE_ACCESS_KEY" ] || npm run test-saucelabs'
View
@@ -0,0 +1,40 @@
ui: jasmine2
scripts:
- "tests/vendor/jasmine/jasmine.js"
- "tests/vendor/jasmine/jasmine-html.js"
- "tests/vendor/jasmine/boot.js"
- "xregexp-all.js"
- "tests/helpers/h.js"
- "tests/helpers/h-matchers.js"
- "tests/helpers/h-unicode.js"
browsers:
- name: chrome
version: [49, 55..latest]
- name: firefox
version: [45, 50..latest]
- name: safari
version: 9..latest
- name: opera
version: 12..latest
- name: ie
version: 10..latest
- name: microsoftedge
version: 13..latest
- name: android
version: '4.4..latest'
- name: iphone
version: '9.3..latest'
- name: ipad
version: '9.3..latest'
View
@@ -24,10 +24,13 @@
"scripts": {
"build": "browserify src/index.js --standalone XRegExp > xregexp-all.js",
"pretest": "npm run build",
"test": "jasmine JASMINE_CONFIG_PATH=tests/jasmine.json"
"test": "jasmine JASMINE_CONFIG_PATH=tests/jasmine.json",
"test-saucelabs": "npm run pretest && zuul tests/spec/*.js",
"test-browser": "npm run test-saucelabs -- --local --open"
},
"devDependencies": {
"browserify": "^12.0.1",
"jasmine": "^2.5.3"
"jasmine": "^2.5.3",
"zuul": "^3.11.1"
}
}
@@ -1,4 +1,8 @@
beforeEach(function() {
if (typeof global === 'undefined') {
global = window;
}
global.addToEqualMatchMatcher = function() {
jasmine.addMatchers({
// Similar to toEqual with arrays, but ignores custom properties of arrays. Useful when
// comparing regex matches with array literals.
@@ -30,4 +34,4 @@ beforeEach(function() {
};
}
});
});
}
View
@@ -5,9 +5,9 @@ if (typeof global === 'undefined') {
}
// Ensure that all opt-in features are disabled when each spec starts
beforeEach(function() {
global.disableOptInFeatures = function() {
XRegExp.uninstall('natives astral');
});
}
// Repeat a string the specified number of times
global.repeat = function (str, num) {
@@ -1,3 +1,8 @@
beforeEach(function() {
global.disableOptInFeatures();
global.addToEqualMatchMatcher();
});
describe('XRegExp.build addon:', function() {
describe('XRegExp.build()', function() {
@@ -1,3 +1,8 @@
beforeEach(function() {
global.disableOptInFeatures();
global.addToEqualMatchMatcher();
});
describe('XRegExp.matchRecursive addon:', function() {
describe('XRegExp.matchRecursive()', function() {
@@ -1,3 +1,8 @@
beforeEach(function() {
global.disableOptInFeatures();
global.addToEqualMatchMatcher();
});
describe('Unicode Base addon:', function() {
/*
@@ -1,3 +1,8 @@
beforeEach(function() {
global.disableOptInFeatures();
global.addToEqualMatchMatcher();
});
describe('XRegExp.addToken()', function() {
it('should throw an exception if provided a non-RegExp object as the regex argument', function() {
@@ -1,3 +1,8 @@
beforeEach(function() {
global.disableOptInFeatures();
global.addToEqualMatchMatcher();
});
describe('When overridden, RegExp.prototype.exec()', function() {
beforeEach(function() {
View
@@ -1,3 +1,8 @@
beforeEach(function() {
global.disableOptInFeatures();
global.addToEqualMatchMatcher();
});
describe('XRegExp()', function() {
it('should create objects that pass RegExp type checks', function() {

0 comments on commit 28a77c0

Please sign in to comment.