diff --git a/.eslintrc b/.eslintrc index 1026c14..45688a7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,15 +1,3 @@ { - "extends": "segment/browser", - - "rules": { - "global-strict": 0, - "max-len": 0, - "strict": 1 - }, - - "globals": { - "exports": true, - "module": true, - "require": true - } + "extends": "@segment/eslint-config/browser/legacy" } diff --git a/.gitignore b/.gitignore index 68492d8..62562b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ -*.log -.DS_Store -build.js -components +coverage node_modules diff --git a/Contributing.md b/CONTRIBUTING.md similarity index 100% rename from Contributing.md rename to CONTRIBUTING.md diff --git a/History.md b/HISTORY.md similarity index 78% rename from History.md rename to HISTORY.md index eca9cbe..517f17f 100644 --- a/History.md +++ b/HISTORY.md @@ -1,3 +1,10 @@ +2.0.0 / ????-??-?? +================== + + * Remove Duo compatibility + * Add CI setup (coverage, linting, cross-browser compatibility, etc.) + * Update eslint configuration + 1.0.9 / 2016-05-07 ================== diff --git a/License.md b/LICENSE similarity index 100% rename from License.md rename to LICENSE diff --git a/Makefile b/Makefile index f63b0c2..86eb29b 100644 --- a/Makefile +++ b/Makefile @@ -1,93 +1,80 @@ -# -# Binaries. -# - -DUO = node_modules/.bin/duo -DUOT = node_modules/.bin/duo-test -ESLINT = node_modules/.bin/eslint - -# -# Files. -# - -SRCS_DIR = lib -SRCS = $(shell find $(SRCS_DIR) -type f -name "*.js") -TESTS_DIR = test -TESTS = $(shell find $(TESTS_DIR) -type f -name '*.test.js') - -# -# Task config. -# - -BROWSER ?= chrome - -PORT ?= 0 - -DUOT_ARGS = \ - --reporter spec \ - --port $(PORT) \ - --commands "make build" - -# -# Chore tasks. -# - -# Install node dependencies. +## +# Binaries +## + +ESLINT := node_modules/.bin/eslint +KARMA := node_modules/.bin/karma + +## +# Files +## + +LIBS = $(shell find lib -type f -name "*.js") +TESTS = $(shell find test -type f -name "*.test.js") +SUPPORT = $(wildcard karma.conf*.js) +ALL_FILES = $(LIBS) $(TESTS) $(SUPPORT) + +## +# Program options/flags +## + +# A list of options to pass to Karma +# Overriding this overwrites all options specified in this file (e.g. BROWSERS) +KARMA_FLAGS ?= + +# A list of Karma browser launchers to run +# http://karma-runner.github.io/0.13/config/browsers.html +BROWSERS ?= +ifdef BROWSERS +KARMA_FLAGS += --browsers $(BROWSERS) +endif + +ifdef CI +KARMA_CONF ?= karma.conf.ci.js +else +KARMA_CONF ?= karma.conf.js +endif + +# Mocha flags. +GREP ?= . + +## +# Tasks +## + +# Install node modules. node_modules: package.json $(wildcard node_modules/*/package.json) @npm install + @touch $@ + +# Install dependencies. +install: node_modules # Remove temporary files and build artifacts. clean: - rm -rf build.js + rm -rf *.log coverage .PHONY: clean # Remove temporary files, build artifacts, and vendor dependencies. distclean: clean - rm -rf components node_modules + rm -rf node_modules .PHONY: distclean -# -# Build tasks. -# - -# Build all integrations, tests, and dependencies together for testing. -build.js: node_modules component.json $(SRCS) $(TESTS) - @$(DUO) --stdout --development $(TESTS) > $@ - -# Build shortcut. -build: build.js -.DEFAULT_GOAL = build +# Lint JavaScript source files. +lint: install + @$(ESLINT) $(ALL_FILES) +.PHONY: lint -# -# Test tasks. -# +# Attempt to fix linting errors. +fmt: install + @$(ESLINT) --fix $(ALL_FILES) +.PHONY: fmt -# Lint JavaScript source. -lint: node_modules - @$(ESLINT) $(SRCS) $(TESTS) -.PHONY: lint +# Run browser unit tests in a browser. +test-browser: install + @$(KARMA) start $(KARMA_FLAGS) $(KARMA_CONF) -# Test locally in PhantomJS. -test-phantomjs: node_modules build.js - @$(DUOT) phantomjs $(TESTS_DIR) args: \ - --ignore-ssl-errors=true --ssl-protocol=tlsv1 --path node_modules/.bin/phantomjs -.PHONY: test-phantomjs - -# Test locally in the browser. -test-browser: node_modules build.js - @$(DUOT) browser --commands "make build" $(TESTS_DIR) -.PHONY: test-browser - -# Test in Sauce Labs. Note that you must set the SAUCE_USERNAME and -# SAUCE_ACCESS_KEY environment variables using your Sauce Labs credentials. -test-sauce: node_modules build.js - @$(DUOT) saucelabs $(TESTS_DIR) \ - --name analytics.js-integrations \ - --browsers $(BROWSER) \ - --user $(SAUCE_USERNAME) \ - --key $(SAUCE_ACCESS_KEY) -.PHONY: test-sauce - -# Test shortcut. -test: lint test-phantomjs +# Default test target. +test: lint test-browser .PHONY: test +.DEFAULT_GOAL = test diff --git a/Readme.md b/README.md similarity index 88% rename from Readme.md rename to README.md index cd0361b..f3280e6 100644 --- a/Readme.md +++ b/README.md @@ -4,7 +4,7 @@ Drift integration for [Analytics.js][]. ## License -Released under the [MIT license](License.md). +Released under the [MIT license](LICENSE). [Analytics.js]: https://segment.com/docs/libraries/analytics.js/ diff --git a/circle.yml b/circle.yml index 19ba508..382a5b6 100644 --- a/circle.yml +++ b/circle.yml @@ -1,11 +1,29 @@ machine: node: - version: 0.12 + version: 4 + environment: + NPM_CONFIG_PROGRESS: false + NPM_CONFIG_SPIN: false + TEST_REPORTS_DIR: $CIRCLE_TEST_REPORTS + dependencies: pre: - - 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 - - npm install -g npm@'>=2.7.0' - - make + - npm config set "//registry.npmjs.org/:_authToken" $NPM_AUTH + - npm -g install codecov + override: + - make install + test: override: - make test + post: + - cp -R coverage $CIRCLE_ARTIFACTS/ + - codecov + +deployment: + publish: + owner: segmentio + # Works on e.g. `1.0.0-alpha.1` + tag: /[0-9]+(\.[0-9]+)*(-.+)?/ + commands: + - npm publish . diff --git a/component.json b/component.json deleted file mode 100644 index 4d8fb32..0000000 --- a/component.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "analytics.js-integration-drift", - "repo": "segment-integrations/analytics.js-integration-drift", - "description": "The Drift analytics.js integration.", - "version": "1.2.1", - "license": "MIT", - "main": "lib/index.js", - "dependencies": { - "segmentio/facade": "^2.2.2", - "segmentio/alias": "0.2.1", - "segmentio/convert-dates": "0.1.0", - "segmentio/analytics.js-integration": "^1.1.0" - }, - "development": { - "segmentio/analytics.js-core": "^2.12.0", - "segmentio/clear-env": "0.2.x", - "segmentio/analytics.js-integration-tester": "^1.5.0" - } -} diff --git a/karma.conf.ci.js b/karma.conf.ci.js new file mode 100644 index 0000000..aff0fe5 --- /dev/null +++ b/karma.conf.ci.js @@ -0,0 +1,101 @@ +/* eslint-env node */ +'use strict'; + +var baseConfig = require('./karma.conf'); + +var customLaunchers = { + sl_chrome_latest: { + base: 'SauceLabs', + browserName: 'chrome', + platform: 'linux', + version: 'latest' + }, + sl_chrome_latest_1: { + base: 'SauceLabs', + browserName: 'chrome', + platform: 'linux', + version: 'latest-1' + }, + sl_firefox_latest: { + base: 'SauceLabs', + browserName: 'firefox', + platform: 'linux', + version: 'latest' + }, + sl_firefox_latest_1: { + base: 'SauceLabs', + browserName: 'firefox', + platform: 'linux', + version: 'latest-1' + }, + sl_safari_9: { + base: 'SauceLabs', + browserName: 'safari', + version: '9.0' + }, + // FIXME(ndhoule): Bad IE7/8 support in testing packages make these fail + // sl_ie_7: { + // base: 'SauceLabs', + // browserName: 'internet explorer', + // version: '7' + // }, + // sl_ie_8: { + // base: 'SauceLabs', + // browserName: 'internet explorer', + // version: '8' + // }, + sl_ie_9: { + base: 'SauceLabs', + browserName: 'internet explorer', + version: '9' + }, + sl_ie_10: { + base: 'SauceLabs', + browserName: 'internet explorer', + version: '10' + }, + sl_ie_11: { + base: 'SauceLabs', + browserName: 'internet explorer', + version: '11' + }, + sl_edge_latest: { + base: 'SauceLabs', + browserName: 'microsoftedge' + } +}; + +module.exports = function(config) { + baseConfig(config); + + if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) { + throw new Error('SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are required but are missing'); + } + + config.set({ + browserDisconnectTolerance: 1, + + singleRun: true, + + reporters: ['progress', 'junit', 'coverage'], + + browsers: ['PhantomJS'].concat(Object.keys(customLaunchers)), + + customLaunchers: customLaunchers, + + junitReporter: { + outputDir: process.env.TEST_REPORTS_DIR, + suite: require('./package.json').name + }, + + sauceLabs: { + testName: require('./package.json').name + }, + + coverageReporter: { + reporters: [ + { type: 'lcov' } + ] + } + }); +}; diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..2724258 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,50 @@ +/* eslint-env node */ +'use strict'; + +module.exports = function(config) { + config.set({ + files: [ + 'test/**/*.test.js' + ], + + browsers: ['PhantomJS'], + + frameworks: ['browserify', 'mocha'], + + reporters: ['spec', 'coverage'], + + preprocessors: { + 'test/**/*.js': 'browserify' + }, + + client: { + mocha: { + grep: process.env.GREP, + reporter: 'html', + timeout: 10000 + } + }, + + browserify: { + debug: true, + transform: [ + [ + 'browserify-istanbul', + { + instrumenterConfig: { + embedSource: true + } + } + ] + ] + }, + + coverageReporter: { + reporters: [ + { type: 'text' }, + { type: 'html' }, + { type: 'json' } + ] + } + }); +}; diff --git a/lib/index.js b/lib/index.js index 33de3b1..a40ace3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,10 +1,12 @@ +'use strict'; /** * Module dependencies. */ -var convertDates = require('convert-dates'); -var integration = require('analytics.js-integration'); +var convertDates = require('@segment/convert-dates'); +var each = require('@ndhoule/each'); +var integration = require('@segment/analytics.js-integration'); var REFRESH_RATE = 300000; var timeHash = Math.ceil(new Date() / REFRESH_RATE) * REFRESH_RATE; @@ -25,9 +27,9 @@ var Drift = module.exports = integration('Drift') */ Drift.prototype.initialize = function() { - var drift; - - drift = window.drift = window.driftt = window.driftt || []; + var drift = window.driftt || []; + window.drift = drift; + window.driftt = drift; drift.methods = ['identify', 'track', 'reset', 'debug', 'show', 'ping', 'page', 'hide', 'off', 'on']; drift.factory = function(method) { return function() { @@ -38,9 +40,9 @@ Drift.prototype.initialize = function() { }; }; - drift.methods.forEach(function(key) { + each(function(key) { drift[key] = drift.factory(key); - }); + }, drift.methods); this.load(this.ready); }; @@ -53,7 +55,9 @@ Drift.prototype.initialize = function() { */ Drift.prototype.loaded = function() { - return window.drift !== undefined; + // FIXME: This test should be improved by Driftt folks. It works in Chrome but + // not in PhantomJS. + return window.driftt && window.driftt._oldDriftt; }; /** @@ -65,6 +69,7 @@ Drift.prototype.loaded = function() { Drift.prototype.identify = function(identify) { if (!identify.userId()) return this.debug('user id required'); + if (!identify.email()) return this.debug('user id required'); var traits = identify.traits(); var id = identify.userId(); delete traits.id; diff --git a/package.json b/package.json index f8588e3..ea3aebb 100644 --- a/package.json +++ b/package.json @@ -1,32 +1,55 @@ { - "name": "analytics.js-integration-drift", + "name": "@segment/analytics.js-integration-drift", "description": "The Drift analytics.js integration.", - "author": "Segment ", - "license": "MIT", + "version": "2.0.0", + "keywords": [ + "analytics.js", + "analytics.js-integration", + "segment", + "drift" + ], "main": "lib/index.js", "scripts": { "test": "make test" }, - "engines": { - "node": ">=0.12.0", - "npm": ">=2.7.0" - }, "repository": { - "url": "https://github.com/segment-integrations/analytics.js-integration-drift.git", - "type": "git" + "type": "git", + "url": "git+https://github.com/segment-integrations/analytics.js-integration-drift.git" }, + "author": "Segment ", + "license": "SEE LICENSE IN LICENSE", "bugs": { "url": "https://github.com/segment-integrations/analytics.js-integration-drift/issues" }, - "homepage": "https://segment.com/docs/integrations/drift/", - "dependencies": {}, + "homepage": "https://github.com/segment-integrations/analytics.js-integration-drift#readme", + "dependencies": { + "@ndhoule/each": "^2.0.1", + "@segment/analytics.js-integration": "^2.1.0", + "@segment/convert-dates": "^1.0.0" + }, "devDependencies": { - "duo": "0.12.x", - "duo-test": "0.2.x", - "eslint": "0.x", - "eslint-config-segment": "^1.0.10", + "@segment/analytics.js-core": "^3.0.0", + "@segment/analytics.js-integration-tester": "^2.0.0", + "@segment/clear-env": "^2.0.0", + "@segment/eslint-config": "^3.1.1", + "browserify": "^13.0.0", + "browserify-istanbul": "^2.0.0", + "eslint": "^2.9.0", + "eslint-plugin-mocha": "^2.2.0", + "eslint-plugin-require-path-exists": "^1.1.5", + "istanbul": "^0.4.3", + "karma": "^0.13.22", + "karma-browserify": "^5.0.4", + "karma-chrome-launcher": "^1.0.1", + "karma-coverage": "^1.0.0", + "karma-junit-reporter": "^1.0.0", + "karma-mocha": "^1.0.1", + "karma-phantomjs-launcher": "^1.0.0", + "karma-sauce-launcher": "^1.0.0", + "karma-spec-reporter": "0.0.26", "mocha": "^2.2.5", - "mocha-phantomjs": "segmentio/mocha-phantomjs#master", - "phantomjs": "^1.9.17" + "npm-check": "^5.2.1", + "phantomjs-prebuilt": "^2.1.7", + "watchify": "^3.7.0" } } diff --git a/test/.eslintrc b/test/.eslintrc index 7eeefc3..bab7e83 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,5 +1,3 @@ { - "env": { - "mocha": true - } + "extends": "@segment/eslint-config/mocha" } diff --git a/test/index.html b/test/index.html deleted file mode 100644 index 9652429..0000000 --- a/test/index.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - integrations tests - - - -
- - - - - - diff --git a/test/index.test.js b/test/index.test.js index ac39aa1..892fa2e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,8 +1,9 @@ +'use strict'; -var Analytics = require('analytics.js-core').constructor; -var integration = require('analytics.js-integration'); -var sandbox = require('clear-env'); -var tester = require('analytics.js-integration-tester'); +var Analytics = require('@segment/analytics.js-core').constructor; +var integration = require('@segment/analytics.js-integration'); +var sandbox = require('@segment/clear-env'); +var tester = require('@segment/analytics.js-integration-tester'); var Drift = require('../lib/'); describe('Drift', function() {