From 247dcac0a32f0af53254f76efb6a1da78897494a Mon Sep 17 00:00:00 2001 From: jordangarcia Date: Thu, 14 May 2015 13:57:39 -0700 Subject: [PATCH 1/2] Add configuration to run saucelabs from CI Remove the `Utils.isNumber` function, its not used in the codebase and isn't implemented correctly for IE when testing `new Number(1)` --- .travis.yml | 9 +-- grunt/aliases.js | 16 +++-- grunt/karma-configs/chrome.karma.js | 55 ----------------- grunt/karma-configs/coverage.karma.js | 71 ---------------------- grunt/karma-configs/phantom.karma.js | 55 ----------------- grunt/karma.js | 86 ++++++++++++++++++++++++++- grunt/sauce.js | 86 +++++++++++++++++++++++++++ package.json | 3 +- src/utils.js | 9 --- tests/utils-tests.js | 37 ------------ 10 files changed, 187 insertions(+), 240 deletions(-) delete mode 100644 grunt/karma-configs/chrome.karma.js delete mode 100644 grunt/karma-configs/coverage.karma.js delete mode 100644 grunt/karma-configs/phantom.karma.js create mode 100644 grunt/sauce.js diff --git a/.travis.yml b/.travis.yml index 33a4b2c..e56aba0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,12 @@ language: node_js node_js: - - '0.10' +- '0.10' branches: only: - - master + - master before_install: - - npm install -g grunt-cli +- npm install -g grunt-cli env: global: - secure: E7YHPSZtpjm4I20DB3j3uhkLIeyUGH5Hmos6dynTqoasHo5Z7LIixZaAMRGQitN03rWszrtaV6BRoYmFfjXK39H2LfJxHcCo+3eROZLad8I2tG6ClpsrOy//4xIEg82MGd3wJv81GasIr6kTwm1l4bFZMdj0O5Vb0Y7DGy63f1g= + - secure: E7YHPSZtpjm4I20DB3j3uhkLIeyUGH5Hmos6dynTqoasHo5Z7LIixZaAMRGQitN03rWszrtaV6BRoYmFfjXK39H2LfJxHcCo+3eROZLad8I2tG6ClpsrOy//4xIEg82MGd3wJv81GasIr6kTwm1l4bFZMdj0O5Vb0Y7DGy63f1g= + - secure: i+uPD/Jvg83JWDh+ohdG7oWV7f0JftH3hpVdbg4cqHdKdqjSwH0900F4CuYg6+L8wygZ3nn8hW43kyuX980AF2v1Mij2TL/LcBk434l8qGJUylPChPd0XTIKiXfmTsNphil+weAzLnSYUCGIHlJKP1rAVg6NvoKcRHciufZO+aQ= diff --git a/grunt/aliases.js b/grunt/aliases.js index c0dbad7..b803916 100644 --- a/grunt/aliases.js +++ b/grunt/aliases.js @@ -1,12 +1,18 @@ module.exports = { - 'ci': [ - 'clean:coverage', - 'karma:coverage', - 'coveralls', + 'test': [ + 'karma:phantom' + ], + + 'sauce': [ + 'karma:sauce_modern', + 'karma:sauce_ie', + 'karma:sauce_mobile', ], - 'coverage': [ + + 'ci': [ 'clean:coverage', 'karma:coverage', 'coveralls', + 'sauce', ], }; diff --git a/grunt/karma-configs/chrome.karma.js b/grunt/karma-configs/chrome.karma.js deleted file mode 100644 index c28b80a..0000000 --- a/grunt/karma-configs/chrome.karma.js +++ /dev/null @@ -1,55 +0,0 @@ -var path = require('path'); - -module.exports = function(config) { - config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: path.join(__dirname, '../../'), - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['jasmine', 'es5-shim'], - - // list of files / patterns to load in the browser - files: [ - 'tests/*-tests.js', - ], - - // list of files to exclude - exclude: [], - - reporters: ['html'], - - preprocessors: { - 'tests/*-tests.js': ['webpack'], - }, - - webpack: { - module: { - loaders: [ - { test: /\.js$/, loader: 'jstransform-loader' }, - ], - }, - }, - - // web server port - port: 9876, - - // enable / disable colors in the output (reporters and logs) - colors: true, - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_ERROR, - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: true, - - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: ['Chrome'], - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: false, - }) -} diff --git a/grunt/karma-configs/coverage.karma.js b/grunt/karma-configs/coverage.karma.js deleted file mode 100644 index 45e9d1e..0000000 --- a/grunt/karma-configs/coverage.karma.js +++ /dev/null @@ -1,71 +0,0 @@ -var path = require('path'); - -module.exports = function(config) { - config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: path.join(__dirname, '../../'), - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['jasmine', 'es5-shim'], - - // list of files / patterns to load in the browser - files: [ - 'tests/*-tests.js', - ], - - - // list of files to exclude - exclude: [], - - reporters: ['progress', 'coverage'], - - preprocessors: { - 'tests/*-tests.js': ['webpack'], - }, - - coverageReporter: { - reporters: [ - { type: "html", dir: "coverage/" }, - { type: "lcov", dir: "coverage/" }, - { type: "text-summary" }, - ] - }, - - webpack: { - module: { - loaders: [ - { test: /\.js$/, loader: 'jstransform-loader' }, - ], - postLoaders: [ - { - test: /\.js$/, - exclude: /(node_modules\/|-tests\.js$)/, - loader: 'istanbul-instrumenter' - } - ] - }, - }, - - // web server port - port: 9876, - - // enable / disable colors in the output (reporters and logs) - colors: true, - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_ERROR, - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: false, - - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: ['PhantomJS'], - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: true, - }) -} diff --git a/grunt/karma-configs/phantom.karma.js b/grunt/karma-configs/phantom.karma.js deleted file mode 100644 index eb9510f..0000000 --- a/grunt/karma-configs/phantom.karma.js +++ /dev/null @@ -1,55 +0,0 @@ -var path = require('path'); - -module.exports = function(config) { - config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: path.join(__dirname, '../../'), - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['jasmine', 'es5-shim'], - - // list of files / patterns to load in the browser - files: [ - 'tests/*-tests.js', - ], - - // list of files to exclude - exclude: [], - - reporters: ['progress'], - - preprocessors: { - 'tests/*-tests.js': ['webpack'], - }, - - webpack: { - module: { - loaders: [ - { test: /\.js$/, loader: 'jstransform-loader' }, - ], - }, - }, - - // web server port - port: 9876, - - // enable / disable colors in the output (reporters and logs) - colors: true, - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.DEBUG, - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: false, - - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: ['PhantomJS'], - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: true, - }) -} diff --git a/grunt/karma.js b/grunt/karma.js index 95d439d..e4e9f20 100644 --- a/grunt/karma.js +++ b/grunt/karma.js @@ -1,14 +1,94 @@ +var sauce = require('./sauce') +var path = require('path'); + module.exports = { - // single run + options: { + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: path.join(__dirname, '../'), + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine'], + + // list of files / patterns to load in the browser + files: [ + 'tests/*-tests.js', + ], + + reporters: ['progress'], + + preprocessors: { + 'tests/*-tests.js': ['webpack'], + }, + + webpack: { + module: { + loaders: [ + { test: /\.js$/, loader: 'jstransform-loader' }, + ], + }, + }, + + port: 9876, + + logLevel: 'error', + + colors: true, + + autoWatch: false, + + singleRun: true, + }, + phantom: { configFile: 'grunt/karma-configs/phantom.karma.js', + frameworks: ['jasmine', 'es5-shim'], + browsers: ['PhantomJS'], }, chrome: { - configFile: 'grunt/karma-configs/chrome.karma.js', + reporters: ['html'], + browsers: ['Chrome'], + autoWatch: true, + singleRun: false, }, coverage: { - configFile: 'grunt/karma-configs/coverage.karma.js', + frameworks: ['jasmine', 'es5-shim'], + reporters: ['progress', 'coverage'], + browsers: ['PhantomJS'], + coverageReporter: { + reporters: [ + { type: "html", dir: "coverage/" }, + { type: "lcov", dir: "coverage/" }, + { type: "text-summary" }, + ] + }, + + webpack: { + module: { + loaders: [ + { test: /\.js$/, loader: 'jstransform-loader' }, + ], + postLoaders: [ + { + test: /\.js$/, + exclude: /(node_modules\/|-tests\.js$)/, + loader: 'istanbul-instrumenter' + } + ] + }, + }, + }, + + sauce_modern: { + options: sauce.modern, + }, + + sauce_ie: { + options: sauce.ie, + }, + + sauce_mobile: { + options: sauce.mobile, }, }; diff --git a/grunt/sauce.js b/grunt/sauce.js new file mode 100644 index 0000000..b5a8cd4 --- /dev/null +++ b/grunt/sauce.js @@ -0,0 +1,86 @@ +var path = require('path'); +// stolen from https://github.com/yyx990803/vue/blob/master/grunt/sauce.js +var sauceConfig = { + username: 'nuclearjs', + accessKey: process.env.SAUCE_ACCESS_KEY, + testName: 'NuclearJS unit tests', + recordScreenshots: false, + build: process.env.TRAVIS_JOB_ID || Date.now(), +} + +/** + * Having too many tests running concurrently on saucelabs + * causes timeouts and errors, so we have to run them in + * smaller batches. + */ + +var batches = { + // the cool kids + modern: { + sl_chrome: { + base: 'SauceLabs', + browserName: 'chrome', + platform: 'Windows 7', + version: '39' + }, + sl_firefox: { + base: 'SauceLabs', + browserName: 'firefox', + version: '33' + }, + sl_mac_safari: { + base: 'SauceLabs', + browserName: "safari", + platform: "OS X 10.10", + version: "8" + } + }, + // ie family + ie: { + sl_ie_9: { + base: 'SauceLabs', + browserName: "internet explorer", + platform: "Windows 7", + version: "9" + }, + sl_ie_10: { + base: 'SauceLabs', + browserName: "internet explorer", + platform: "Windows 8", + version: "10" + }, + sl_ie_11: { + base: 'SauceLabs', + browserName: 'internet explorer', + platform: 'Windows 8.1', + version: '11' + } + }, + // mobile + mobile: { + sl_ios_safari: { + base: 'SauceLabs', + browserName: 'iphone', + platform: 'OS X 10.9', + version: '8.1' + }, + sl_android: { + base: 'SauceLabs', + browserName: 'android', + platform: 'Linux', + version: '4.2' + } + } +} + +for (var key in batches) { + exports[key] = { + sauceLabs: sauceConfig, + // mobile emulators are really slow + captureTimeout: 300000, + browserNoActivityTimeout: 300000, + customLaunchers: batches[key], + browsers: Object.keys(batches[key]), + reporters: ['progress', 'saucelabs'] + } +} diff --git a/package.json b/package.json index a433994..60cff0d 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "istanbul-instrumenter-loader": "^0.1.2", "grunt-karma": "^0.10.1", "load-grunt-config": "^0.17.1", - "grunt-contrib-clean": "^0.6.0" + "grunt-contrib-clean": "^0.6.0", + "karma-sauce-launcher": "^0.2.11" } } diff --git a/src/utils.js b/src/utils.js index 5eb1acf..a7522c9 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,12 +1,3 @@ -/** - * Checks if the passed in value is a number - * @param {*} val - * @return {boolean} - */ -exports.isNumber = function(val) { - return typeof val == 'number' || objectToString(val) === '[object Number]' -} - /** * Checks if the passed in value is a string * @param {*} val diff --git a/tests/utils-tests.js b/tests/utils-tests.js index 8e4f7ee..00d50a1 100644 --- a/tests/utils-tests.js +++ b/tests/utils-tests.js @@ -1,43 +1,6 @@ var Utils = require('../src/utils') describe('Utils', () => { - describe('#isNumber', () => { - it('correctly identifies number strings as not numbers', () => { - var result = Utils.isNumber('1') - expect(result).toBe(false) - }) - - it('correctly identifies integers as numbers', () => { - var result = Utils.isNumber(1) - expect(result).toBe(true) - }) - - it('correctly identifies floats as numbers', () => { - var result = Utils.isNumber(1.5) - expect(result).toBe(true) - }) - - it('correctly identifies NaN as a number', () => { - var result = Utils.isNumber(NaN) - expect(result).toBe(true) - }) - - it('correctly identifies number instances as numbers', () => { - var result = Utils.isNumber(new Number(1)) - expect(result).toBe(true) - }) - - it('correctly identifies scientific notation as a number', () => { - var result = Utils.isNumber(10e2) - expect(result).toBe(true) - }) - - it('correctly identifies hexadecimals as numbers', () => { - var result = Utils.isNumber(0xff) - expect(result).toBe(true) - }) - }) - describe('#isString', () => { it('correctly identifies a non-string as not a string', () => { var result = Utils.isString(1) From 3aebbe37810a1ed37fab9d9f46269f4234eb9377 Mon Sep 17 00:00:00 2001 From: jordangarcia Date: Thu, 14 May 2015 14:01:27 -0700 Subject: [PATCH 2/2] Add saucelabs browser matrix badge to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 74e1894..ece182e 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ [![Coverage Status](https://coveralls.io/repos/optimizely/nuclear-js/badge.svg?branch=master)](https://coveralls.io/r/optimizely/nuclear-js?branch=master) [![Join the chat at https://gitter.im/optimizely/nuclear-js](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/optimizely/nuclear-js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Sauce Test Status](https://saucelabs.com/browser-matrix/nuclearjs.svg)](https://saucelabs.com/u/nuclearjs) + Traditional Flux architecture built with ImmutableJS data structures. ## How NuclearJS differs from other Flux implementations