Skip to content
This repository was archived by the owner on Aug 14, 2019. It is now read-only.

Commit 53a2cb0

Browse files
committed
Replace Duo with Browserify; modernize test harness
1 parent 39bef53 commit 53a2cb0

16 files changed

+404
-287
lines changed

.eslintrc

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
11
{
2-
"extends": "segment/browser",
3-
4-
"rules": {
5-
// FIXME: Refactor and remove this rule
6-
"consistent-return": 1,
7-
"global-strict": 0,
8-
"max-len": 0,
9-
// FIXME: Refactor and remove this rule
10-
"no-use-before-define": 1,
11-
"strict": 1
12-
},
13-
14-
"globals": {
15-
"exports": true,
16-
"module": true,
17-
"require": true
18-
}
2+
"extends": "@segment/eslint-config/browser/legacy"
193
}

.gitignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
*.log
2-
.DS_Store
3-
build.js
4-
components
1+
coverage
52
node_modules
File renamed without changes.

History.md renamed to HISTORY.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2.0.0 / ????-??-??
2+
==================
3+
4+
* Remove Duo compatibility
5+
* Add CI setup (coverage, linting, cross-browser compatibility, etc.)
6+
* Update eslint configuration
7+
18
1.4.3 / 2016-05-07
29
==================
310

License.md renamed to LICENSE

File renamed without changes.

Makefile

+65-78
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,80 @@
1-
#
2-
# Binaries.
3-
#
4-
5-
DUO = node_modules/.bin/duo
6-
DUOT = node_modules/.bin/duo-test
7-
ESLINT = node_modules/.bin/eslint
8-
9-
#
10-
# Files.
11-
#
12-
13-
SRCS_DIR = lib
14-
SRCS = $(shell find $(SRCS_DIR) -type f -name "*.js")
15-
TESTS_DIR = test
16-
TESTS = $(shell find $(TESTS_DIR) -type f -name '*.test.js')
17-
18-
#
19-
# Task config.
20-
#
21-
22-
BROWSER ?= chrome
23-
24-
PORT ?= 0
25-
26-
DUOT_ARGS = \
27-
--reporter spec \
28-
--port $(PORT) \
29-
--commands "make build"
30-
31-
#
32-
# Chore tasks.
33-
#
34-
35-
# Install node dependencies.
1+
##
2+
# Binaries
3+
##
4+
5+
ESLINT := node_modules/.bin/eslint
6+
KARMA := node_modules/.bin/karma
7+
8+
##
9+
# Files
10+
##
11+
12+
LIBS = $(shell find lib -type f -name "*.js")
13+
TESTS = $(shell find test -type f -name "*.test.js")
14+
SUPPORT = $(wildcard karma.conf*.js)
15+
ALL_FILES = $(LIBS) $(TESTS) $(SUPPORT)
16+
17+
##
18+
# Program options/flags
19+
##
20+
21+
# A list of options to pass to Karma
22+
# Overriding this overwrites all options specified in this file (e.g. BROWSERS)
23+
KARMA_FLAGS ?=
24+
25+
# A list of Karma browser launchers to run
26+
# http://karma-runner.github.io/0.13/config/browsers.html
27+
BROWSERS ?=
28+
ifdef BROWSERS
29+
KARMA_FLAGS += --browsers $(BROWSERS)
30+
endif
31+
32+
ifdef CI
33+
KARMA_CONF ?= karma.conf.ci.js
34+
else
35+
KARMA_CONF ?= karma.conf.js
36+
endif
37+
38+
# Mocha flags.
39+
GREP ?= .
40+
41+
##
42+
# Tasks
43+
##
44+
45+
# Install node modules.
3646
node_modules: package.json $(wildcard node_modules/*/package.json)
3747
@npm install
48+
@touch $@
49+
50+
# Install dependencies.
51+
install: node_modules
3852

3953
# Remove temporary files and build artifacts.
4054
clean:
41-
rm -rf build.js
55+
rm -rf *.log coverage
4256
.PHONY: clean
4357

4458
# Remove temporary files, build artifacts, and vendor dependencies.
4559
distclean: clean
46-
rm -rf components node_modules
60+
rm -rf node_modules
4761
.PHONY: distclean
4862

49-
#
50-
# Build tasks.
51-
#
52-
53-
# Build all integrations, tests, and dependencies together for testing.
54-
build.js: node_modules component.json $(SRCS) $(TESTS)
55-
@$(DUO) --stdout --development $(TESTS) > $@
56-
57-
# Build shortcut.
58-
build: build.js
59-
.DEFAULT_GOAL = build
60-
61-
#
62-
# Test tasks.
63-
#
64-
65-
# Lint JavaScript source.
66-
lint: node_modules
67-
@$(ESLINT) $(SRCS) $(TESTS)
63+
# Lint JavaScript source files.
64+
lint: install
65+
@$(ESLINT) $(ALL_FILES)
6866
.PHONY: lint
6967

70-
# Test locally in PhantomJS.
71-
test-phantomjs: node_modules build.js
72-
@$(DUOT) phantomjs $(TESTS_DIR) args: \
73-
--path node_modules/.bin/phantomjs
74-
.PHONY: test
68+
# Attempt to fix linting errors.
69+
fmt: install
70+
@$(ESLINT) --fix $(ALL_FILES)
71+
.PHONY: fmt
72+
73+
# Run browser unit tests in a browser.
74+
test-browser: install
75+
@$(KARMA) start $(KARMA_FLAGS) $(KARMA_CONF)
7576

76-
# Test locally in the browser.
77-
test-browser: node_modules build.js
78-
@$(DUOT) browser --commands "make build" $(TESTS_DIR)
79-
.PHONY: test-browser
80-
81-
# Test in Sauce Labs. Note that you must set the SAUCE_USERNAME and
82-
# SAUCE_ACCESS_KEY environment variables using your Sauce Labs credentials.
83-
test-sauce: node_modules build.js
84-
@$(DUOT) saucelabs $(TESTS_DIR) \
85-
--name analytics.js-integrations \
86-
--browsers $(BROWSER) \
87-
--user $(SAUCE_USERNAME) \
88-
--key $(SAUCE_ACCESS_KEY)
89-
.PHONY: test-sauce
90-
91-
# Test shortcut.
92-
test: lint test-phantomjs
77+
# Default test target.
78+
test: lint test-browser
9379
.PHONY: test
80+
.DEFAULT_GOAL = test

Readme.md renamed to README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Google Analytics integration for [Analytics.js][].
44

55
## License
66

7-
Released under the [MIT license](License.md).
7+
Released under the [MIT license](LICENSE).
88

99

1010
[Analytics.js]: https://segment.com/docs/libraries/analytics.js/

circle.yml

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
machine:
22
node:
3-
version: 0.12
3+
version: 4
4+
environment:
5+
NPM_CONFIG_PROGRESS: false
6+
NPM_CONFIG_SPIN: false
7+
TEST_REPORTS_DIR: $CIRCLE_TEST_REPORTS
8+
49
dependencies:
510
pre:
6-
- echo "github.com,192.30.252.*,192.30.253.*,192.30.254.*,192.30.255.* ssh-rsa $(ssh-keyscan -t rsa github.com | cut -d ' ' -f 3-)" >> ~/.ssh/known_hosts
7-
- npm install -g npm@'>=2.7.0'
8-
- make
11+
- npm config set "//registry.npmjs.org/:_authToken" $NPM_AUTH
12+
- npm -g install codecov
13+
override:
14+
- make install
15+
916
test:
1017
override:
1118
- make test
19+
post:
20+
- cp -R coverage $CIRCLE_ARTIFACTS/
21+
- codecov
22+
23+
deployment:
24+
publish:
25+
owner: segmentio
26+
# Works on e.g. `1.0.0-alpha.1`
27+
tag: /[0-9]+(\.[0-9]+)*(-.+)?/
28+
commands:
29+
- npm publish .

component.json

-25
This file was deleted.

karma.conf.ci.js

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* eslint-env node */
2+
'use strict';
3+
4+
var baseConfig = require('./karma.conf');
5+
6+
var customLaunchers = {
7+
// FIXME(han): tests for this browser was broken pre browserification
8+
// sl_chrome_latest: {
9+
// base: 'SauceLabs',
10+
// browserName: 'chrome',
11+
// platform: 'linux',
12+
// version: 'latest'
13+
// },
14+
sl_chrome_latest_1: {
15+
base: 'SauceLabs',
16+
browserName: 'chrome',
17+
platform: 'linux',
18+
version: 'latest-1'
19+
},
20+
sl_firefox_latest: {
21+
base: 'SauceLabs',
22+
browserName: 'firefox',
23+
platform: 'linux',
24+
version: 'latest'
25+
},
26+
// FIXME(han): tests for this browser was broken pre browserification
27+
// sl_firefox_latest_1: {
28+
// base: 'SauceLabs',
29+
// browserName: 'firefox',
30+
// platform: 'linux',
31+
// version: 'latest-1'
32+
// },
33+
sl_safari_9: {
34+
base: 'SauceLabs',
35+
browserName: 'safari',
36+
version: '9.0'
37+
},
38+
// FIXME(ndhoule): Bad IE7/8 support in testing packages make these fail
39+
// sl_ie_7: {
40+
// base: 'SauceLabs',
41+
// browserName: 'internet explorer',
42+
// version: '7'
43+
// },
44+
// sl_ie_8: {
45+
// base: 'SauceLabs',
46+
// browserName: 'internet explorer',
47+
// version: '8'
48+
// },
49+
sl_ie_9: {
50+
base: 'SauceLabs',
51+
browserName: 'internet explorer',
52+
version: '9'
53+
},
54+
sl_ie_10: {
55+
base: 'SauceLabs',
56+
browserName: 'internet explorer',
57+
version: '10'
58+
},
59+
sl_ie_11: {
60+
base: 'SauceLabs',
61+
browserName: 'internet explorer',
62+
version: '11'
63+
},
64+
sl_edge_latest: {
65+
base: 'SauceLabs',
66+
browserName: 'microsoftedge'
67+
}
68+
};
69+
70+
module.exports = function(config) {
71+
baseConfig(config);
72+
73+
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
74+
throw new Error('SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are required but are missing');
75+
}
76+
77+
config.set({
78+
browserDisconnectTolerance: 1,
79+
80+
singleRun: true,
81+
82+
reporters: ['progress', 'junit', 'coverage'],
83+
84+
browsers: ['PhantomJS'].concat(Object.keys(customLaunchers)),
85+
86+
customLaunchers: customLaunchers,
87+
88+
junitReporter: {
89+
outputDir: process.env.TEST_REPORTS_DIR,
90+
suite: require('./package.json').name
91+
},
92+
93+
sauceLabs: {
94+
testName: require('./package.json').name
95+
},
96+
97+
coverageReporter: {
98+
reporters: [
99+
{ type: 'lcov' }
100+
]
101+
}
102+
});
103+
};

0 commit comments

Comments
 (0)