Skip to content

Commit

Permalink
Travis + SauceLabs + Karma setup (first pass)
Browse files Browse the repository at this point in the history
- add sauce connect
- prepare to use karma on saucelabs; fix potential windows problems
- rewrite `scripts/ensure-compatible-npm.sh` in JS
- detect travis node 0.8 env; just upgrade if found
- symlink `mocha` to itself for `karma-mocha`
- if explicit `--production` flag is present, skip this
- don't know how to skip this part if `mocha` is a devDep of some other package
- use phantomjs@1.9.19; don't try to install npm@3
- browser tests with karma & phantom
- move `support/browser-entry.js` to `browser-entry.js` to keep paths sane
- `karma.conf.js` loads data out of `.karma.conf.js`
  - we have a "main" browser suite
    - then we have suites for each interface
    - each suite is a single run of Karma
    - each suite is executed by the `Makefile`
  - build `./mocha.js` upon test execution for `karma-mocha` to use
  - bonus: 3rd-party browserification should theoretically now be possible as per the `./index.js` entry in `package.json`'s `browser` field
  - add dev deps for karma
  - test changes:
    - split `lookupFiles` test into its own file so we can ignore it in Karma
    - fix broken `test/acceptance/throw.js` for browser
    - fix `test/acceptance/utils.js`'s `type` tests for PhantomJS
- try to reduce build matrix
- fix missing targets
- fix infinite loop in Makefile
- downgrade phantomjs to 1.9.8
- remove some cruft from karma config; try to add sauce labs
- try again w/ the saucelabs
- typo
- remove karma-source-map-support as it's a no-go on IE8
- Require up-to-date mocha.js for any browser tests
- Make CI rebuild mocha.js.  Make won't rebuild when just checked out by CI because timestamps on source and mocha.js are the same.  We could use a script to set the timestamps to the commit time, but it still wouldn't work if mocha.js were committed along with other changes that hadn't been built into it. Which shouldn't happen anyway -- but then again, the point of CI is to see what commits change, it's usually going to need to rebuild mocha.js if it's working right, so it's not going to hurt much to rebuild it every time even on the few times it doesn't need to.
  • Loading branch information
boneskull committed May 21, 2016
1 parent 3ad9c4e commit a03ae0e
Show file tree
Hide file tree
Showing 17 changed files with 321 additions and 91 deletions.
4 changes: 4 additions & 0 deletions .karma-config/fixture-bdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-env browser */

window.mocha.timeout(200)
.ui('bdd');
4 changes: 4 additions & 0 deletions .karma-config/fixture-exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-env browser */

window.mocha.timeout(200)
.ui('exports');
4 changes: 4 additions & 0 deletions .karma-config/fixture-qunit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-env browser */

window.mocha.timeout(200)
.ui('qunit');
4 changes: 4 additions & 0 deletions .karma-config/fixture-tdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-env browser */

window.mocha.timeout(200)
.ui('tdd');
4 changes: 4 additions & 0 deletions .karma-config/fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-env browser */

window.mocha.timeout(200)
.ui('bdd');
74 changes: 74 additions & 0 deletions .karma-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
function getConfig() {
var cfg = {
frameworks: [
'browserify',
'should',
'mocha'
],
files: [
'./.karma-config/fixture.js',
'test/acceptance/*.js'
],
exclude: [
'test/acceptance/http.js',
'test/acceptance/fs.js',
'test/acceptance/lookup-files.js',
'test/acceptance/require/**/*.js',
'test/acceptance/misc/**/*.js'
],
preprocessors: {
'test/**/*.js': ['browserify']
},
browserify: {
debug: true,
configure: function configure(b) {
b.ignore('glob')
.ignore('jade')
.ignore('supports-color')
.exclude('./lib-cov/mocha');
}
},
reporters: ['mocha-clean'],
port: 9876,
colors: true,
autoWatch: false,
browsers: ['PhantomJS'],
singleRun: true,
concurrency: Infinity
};

if (process.env.TRAVIS) {
cfg.reporters.push('saucelabs');
cfg.browsers.push('ie8');
cfg.customLaunchers = {
ie8: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows XP',
version: '8.0'
}
};
cfg.sauceLabs = {
testName: 'Karma Tests',
build: 'TRAVIS #' + process.env.TRAVIS_BUILD_NUMBER + ' ('
+ process.env.TRAVIS_BUILD_ID + ')',
public: 'public',
tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER,
startConnect: false
};
// Debug logging into a file, that we print out at the end of the build.
cfg.logLevel = 'DEBUG';
cfg.browserNoActivityTimeout = 120000;
cfg.captureTimeout = 0;
}
return cfg;
}

getConfig.uiFixturePaths = {
bdd: './.karma-config/fixture-bdd.js',
tdd: './.karma-config/fixture-tdd.js',
exports: './.karma-config/fixture-exports.js',
qunit: './.karma-config/fixture-qunit.js'
};

module.exports = getConfig;
37 changes: 26 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,37 @@ dist: trusty

language: node_js

node_js:
- '6'
- '5'
- '4'
- 'iojs'
- '0.12'
- '0.11'
- '0.10'
- '0.8'
matrix:
include:
- node_js: '6'
env: TARGET="clean lint test-node test-browser"
- node_js: '5'
env: TARGET=test-node
- node_js: '4'
env: TARGET=test-node
- node_js: 'iojs'
env: TARGET=test-node
- node_js: '0.12'
env: TARGET=test-node
- node_js: '0.11'
env: TARGET=test-node
- node_js: '0.10'
env: TARGET=test-node
- node_js: '0.8'
env: TARGET=test-node

before_install:
# node 0.8 won't install our dev deps with an out-of-box npm;
# this upgrades it
- ./scripts/ensure-compatible-npm.sh
- node ./scripts/upgrade-npm.js

script: travis_retry npm test
script: travis_retry make $TARGET

addons:
sauce_connect:
username: mochajs
access_key:
secure: R0HXKtR6F2iDEnItv57BTRyL64XfyIlyyluPLK8G33O/InaQjT3KxGuxevz3nVYIqqnI1MPjYodXcQaqrBOLUVmA2vhBeMHB2OwGc9GAL+HBtB1fh+bQJelkl/XMcTTbC5LIZ6nZjmFnkmjqT3AmUhdDRISgieIFeVY4x48LfiU=

notifications:
urls:
Expand Down
50 changes: 45 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
BROWSERIFY := node_modules/.bin/browserify
ESLINT := node_modules/.bin/eslint
KARMA := node_modules/.bin/karma

REPORTER ?= spec
TM_BUNDLE = JavaScript\ mocha.tmbundle
SRC = $(shell find lib -name "*.js" -type f | sort)
TESTS = $(shell find test -name "*.js" -type f | sort)
SUPPORT = $(wildcard support/*.js)

all: mocha.js

mocha.js: $(SRC) $(SUPPORT)
@$(BROWSERIFY) ./support/browser-entry \
@printf "==> [Browser :: build]\n"
@$(BROWSERIFY) ./browser-entry \
--ignore 'fs' \
--ignore 'glob' \
--ignore 'jade' \
Expand All @@ -18,48 +21,75 @@ mocha.js: $(SRC) $(SUPPORT)
--exclude './lib-cov/mocha' > $@

clean:
@printf "==> [Clean]\n"
rm -f mocha.js
rm -rf test-outputs
rm -fr lib-cov
rm -rf lib-cov
rm -f coverage.html

test-cov: lib-cov
@printf "==> [Test :: Coverage]\n"
@COV=1 $(MAKE) test REPORTER=html-cov > coverage.html

lib-cov:
@printf "==> [Coverage]\n"
@rm -fr ./$@
@jscoverage lib $@

lint:
@printf "==> [Test :: Lint]\n"
@$(ESLINT) $(SRC)

test: lint test-unit
test-node: test-bdd test-tdd test-qunit test-exports test-unit test-integration test-jsapi test-compilers test-glob test-requires test-reporters test-only

test-all: lint test-bdd test-tdd test-qunit test-exports test-unit test-integration test-jsapi test-compilers test-glob test-requires test-reporters test-only
test-browser: test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-exports

test: lint test-node test-browser

test-browser-unit: mocha.js
@printf "==> [Test :: Browser]\n"
@$(KARMA) start

test-browser-bdd:
@printf "==> [Test :: Browser :: BDD]\n"
@KARMA_INTERFACE=bdd $(MAKE) test-browser-unit

test-browser-qunit:
@printf "==> [Test :: Browser :: QUnit]\n"
@KARMA_INTERFACE=qunit $(MAKE) test-browser-unit

test-browser-tdd:
@printf "==> [Test :: Browser :: TDD]\n"
@KARMA_INTERFACE=tdd $(MAKE) test-browser-unit

test-jsapi:
@printf "==> [Test :: JS API]\n"
@node test/jsapi

test-unit:
@printf "==> [Test :: Unit]\n"
@./bin/mocha \
--reporter $(REPORTER) \
test/acceptance/*.js \
--growl \
test/*.js

test-integration:
@printf "==> [Test :: Integrations]\n"
@./bin/mocha \
--reporter $(REPORTER) \
test/integration/*.js

test-compilers:
@printf "==> [Test :: Compilers]\n"
@./bin/mocha \
--reporter $(REPORTER) \
--compilers coffee:coffee-script/register,foo:./test/compiler/foo \
test/acceptance/test.coffee \
test/acceptance/test.foo

test-requires:
@printf "==> [Test :: Requires]\n"
@./bin/mocha \
--reporter $(REPORTER) \
--compilers coffee:coffee-script/register \
Expand All @@ -70,38 +100,45 @@ test-requires:
test/acceptance/require/require.js

test-bdd:
@printf "==> [Test :: BDD]\n"
@./bin/mocha \
--reporter $(REPORTER) \
--ui bdd \
test/acceptance/interfaces/bdd

test-tdd:
@printf "==> [Test :: TDD]\n"
@./bin/mocha \
--reporter $(REPORTER) \
--ui tdd \
test/acceptance/interfaces/tdd

test-qunit:
@printf "==> [Test :: QUnit]\n"
@./bin/mocha \
--reporter $(REPORTER) \
--ui qunit \
test/acceptance/interfaces/qunit

test-exports:
@printf "==> [Test :: Exports]\n"
@./bin/mocha \
--reporter $(REPORTER) \
--ui exports \
test/acceptance/interfaces/exports

test-glob:
@printf "==> [Test :: Glob]\n"
@./test/acceptance/glob/glob.sh

test-reporters:
@printf "==> [Test :: Reporters]\n"
@./bin/mocha \
--reporter $(REPORTER) \
test/reporters/*.js

test-only:
@printf "==> [Test :: Only]\n"
@./bin/mocha \
--reporter $(REPORTER) \
--ui tdd \
Expand All @@ -123,11 +160,13 @@ test-only:
test/acceptance/misc/only/qunit

test-mocha:
@printf "==> [Test :: Mocha]\n"
@./bin/mocha \
--reporter $(REPORTER) \
test/mocha

non-tty:
@printf "==> [Test :: Non-TTY]\n"
@./bin/mocha \
--reporter dot \
test/acceptance/interfaces/bdd 2>&1 > /tmp/dot.out
Expand All @@ -150,6 +189,7 @@ non-tty:
@cat /tmp/spec.out

tm:
@printf "==> [TM]\n"
@open editors/$(TM_BUNDLE)

.PHONY: test-cov test-jsapi test-compilers watch test test-all test-bdd test-tdd test-qunit test-exports test-unit test-integration non-tty tm clean
.PHONY: test-cov test-jsapi test-compilers watch test test-node test-bdd test-tdd test-qunit test-exports test-unit test-integration non-tty tm clean test-browser test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-exports lint
4 changes: 3 additions & 1 deletion support/browser-entry.js → browser-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

process.stdout = require('browser-stdout')();

var Mocha = require('../');
var Mocha = require('./lib/mocha');

/**
* Create a Mocha instance.
Expand Down Expand Up @@ -159,3 +159,5 @@ Mocha.process = process;

global.Mocha = Mocha;
global.mocha = mocha;

module.exports = global;
14 changes: 14 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var getConfig = require('./.karma-config');

module.exports = function(config) {
var cfg = getConfig();
var ui = process.env.KARMA_INTERFACE;
if (ui) {
cfg.files = [
getConfig.uiFixturePaths[ui],
'./test/acceptance/interfaces/' + ui + '.js'
];
}

config.set(cfg);
};
17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@
"node": ">= 0.8.x"
},
"scripts": {
"test": "make test-all"
"preinstall": "node scripts/fake-karma-mocha-peer-dep.js",
"test": "make test"
},
"dependencies": {
"commander": "2.3.0",
Expand All @@ -284,8 +285,17 @@
"browserify": "^13.0.0",
"coffee-script": "~1.8.0",
"eslint": "^1.2.1",
"karma": "^0.13.22",
"karma-browserify": "^5.0.5",
"karma-mocha": "^1.0.1",
"karma-mocha-clean-reporter": "0.0.1",
"karma-phantomjs-launcher": "^0.2.3",
"karma-sauce-launcher": "^1.0.0",
"karma-should": "^1.0.0",
"phantomjs": "1.9.8",
"should": "~8.0.0",
"through2": "~0.6.5"
"through2": "~0.6.5",
"watchify": "^3.7.0"
},
"files": [
"bin",
Expand All @@ -299,7 +309,8 @@
"browser": {
"debug": "./lib/browser/debug.js",
"events": "./lib/browser/events.js",
"tty": "./lib/browser/tty.js"
"tty": "./lib/browser/tty.js",
"./index.js": "./browser-entry.js"
},
"licenses": [
{
Expand Down
13 changes: 0 additions & 13 deletions scripts/ensure-compatible-npm.sh

This file was deleted.

Loading

0 comments on commit a03ae0e

Please sign in to comment.