Skip to content

Add prettier #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: 2
jobs:
test:
docker:
- image: circleci/node:8
steps:
- checkout
- restore_cache:
key: deps-{{ checksum "yarn.lock" }}
- run:
name: Install dependencies
command: make install
- save_cache:
key: deps-{{ checksum "yarn.lock" }}
paths:
- node_modules
- run:
name: Run tests
command: make test
- store_artifacts:
path: coverage
- run:
name: Run coverage
command: yarn codecov
publish:
docker:
- image: circleci/node:8
steps:
- checkout
- run:
name: Login to npm
command: npm config set "//registry.npmjs.org/:_authToken" $NPM_AUTH
- run:
name: Publish to npm
command: npm publish .
workflows:
version: 2
test_and_publish:
jobs:
- test:
filters:
tags:
only: /.*/
- publish:
requires:
- test
filters:
tags:
only: /[0-9]+(\.[0-9]+)*(-.+)?/
branches:
ignore: /.*/
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "@segment/eslint-config/browser/legacy"
"extends": ["prettier", "@segment/eslint-config/browser/legacy"]
}
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
13 changes: 4 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Binaries
##

ESLINT := node_modules/.bin/eslint
KARMA := node_modules/.bin/karma

##
Expand Down Expand Up @@ -42,13 +41,9 @@ GREP ?= .
# Tasks
##

# Install node modules.
node_modules: package.json $(wildcard node_modules/*/package.json)
@npm install
@touch $@

# Install dependencies.
install: node_modules
install:
yarn install --frozen-lockfile

# Remove temporary files and build artifacts.
clean:
Expand All @@ -62,12 +57,12 @@ distclean: clean

# Lint JavaScript source files.
lint: install
@$(ESLINT) $(ALL_FILES)
yarn lint
.PHONY: lint

# Attempt to fix linting errors.
fmt: install
@$(ESLINT) --fix $(ALL_FILES)
yarn format
.PHONY: fmt

# Run browser unit tests in a browser.
Expand Down
29 changes: 0 additions & 29 deletions circle.yml

This file was deleted.

24 changes: 19 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ function plugin(analytics) {
} else {
assert(
!spy.got.apply(spy, args),
fmt('Expected "%s" not to be called with "%o", but it was called with "%o".', spy.name, args, spy.args[0])
fmt(
'Expected "%s" not to be called with "%o", but it was called with "%o".',
spy.name,
args,
spy.args[0]
)
);
}

Expand Down Expand Up @@ -251,10 +256,13 @@ function plugin(analytics) {
fmt('The integration does not have an option named "%s".', key)
);
assert.deepEqual(
aDefaults[key], bDefaults[key],
aDefaults[key],
bDefaults[key],
fmt(
'Expected option "%s" to default to "%s", but it defaults to "%s".',
key, bDefaults[key], aDefaults[key]
key,
bDefaults[key],
aDefaults[key]
)
);
}
Expand Down Expand Up @@ -295,9 +303,15 @@ function plugin(analytics) {
* @param {Function} done
*/
analytics.load = function(integration, done) {
analytics.assert(!integration.loaded(), 'Expected `integration.loaded()` to be false before loading.');
analytics.assert(
!integration.loaded(),
'Expected `integration.loaded()` to be false before loading.'
);
analytics.once('ready', function() {
analytics.assert(integration.loaded(), 'Expected `integration.loaded()` to be true after loading.');
analytics.assert(
integration.loaded(),
'Expected `integration.loaded()` to be true after loading.'
);
done();
});
analytics.initialize();
Expand Down
25 changes: 21 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@
],
"main": "lib/index.js",
"scripts": {
"test": "make test"
"test": "make test",
"lint": "eslint \"./{lib,test}/**/*.js\"",
"format": "prettier-eslint --write --list-different \"./{lib,test}/**/*.{js,json,md}\"",
"precommit": "lint-staged"
},
"lint-staged": {
"linters": {
"*.{js,json,md}": [
"prettier-eslint --write",
"git add"
]
}
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,10 +50,14 @@
"@segment/eslint-config": "^3.1.1",
"browserify": "^13.0.0",
"browserify-istanbul": "^2.0.0",
"codecov": "^3.0.2",
"component-each": "^0.2.6",
"eslint": "^2.9.0",
"eslint-plugin-mocha": "^2.2.0",
"eslint-plugin-require-path-exists": "^1.1.5",
"eslint": "^4.19.1",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-mocha": "^5.0.0",
"eslint-plugin-react": "^7.9.1",
"eslint-plugin-require-path-exists": "^1.1.8",
"husky": "^0.14.3",
"istanbul": "^0.4.3",
"karma": "1.3.0",
"karma-browserify": "^5.0.4",
Expand All @@ -53,8 +68,10 @@
"karma-phantomjs-launcher": "^1.0.0",
"karma-sauce-launcher": "^1.0.0",
"karma-spec-reporter": "0.0.26",
"lint-staged": "^7.2.0",
"mocha": "^2.2.5",
"phantomjs-prebuilt": "^2.1.7",
"prettier-eslint-cli": "^4.7.1",
"watchify": "^3.7.0"
}
}
2 changes: 1 addition & 1 deletion test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "@segment/eslint-config/mocha"
"extends": ["prettier", "@segment/eslint-config/mocha"]
}
71 changes: 51 additions & 20 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ describe('integration-tester', function() {
.readyOnLoad();

beforeEach(function() {
analytics = new Analytics;
integration = new Integration;
analytics = new Analytics();
integration = new Integration();
analytics.use(tester);
analytics.add(integration);
});

it('should compare two integrations', function() {
analytics.compare(Integration, createIntegration('Name')
.global('global')
.option('option', 'value')
.option('object', {})
.mapping('map')
.readyOnLoad());
analytics.compare(
Integration,
createIntegration('Name')
.global('global')
.option('option', 'value')
.option('object', {})
.mapping('map')
.readyOnLoad()
);
});

describe('#spy', function() {
Expand Down Expand Up @@ -151,7 +154,11 @@ describe('integration-tester', function() {
});

it('should not throw if the spy returned the value', function() {
var obj = { method: function() { return 1; } };
var obj = {
method: function() {
return 1;
}
};
analytics.spy(obj, 'method');
obj.method();
analytics.returned(obj.method, 1);
Expand All @@ -166,7 +173,11 @@ describe('integration-tester', function() {
});

it('should throw if the spy returned the value', function() {
var obj = { method: function() { return 1; } };
var obj = {
method: function() {
return 1;
}
};
analytics.spy(obj, 'method');
obj.method();
assert['throws'](function() {
Expand Down Expand Up @@ -220,9 +231,18 @@ describe('integration-tester', function() {

describe('#loaded', function() {
beforeEach(function() {
Integration.tag('example-img', '<img src="http://example.com/{{name}}.png">');
Integration.tag('example-script', '<script src="http://ajax.googleapis.com/ajax/libs/jquery/{{version}}/jquery.min.js"></script>');
Integration.tag('example-iframe', '<iframe src="http://ad.doubleclick.net/activity;src=654757884637545;type=groupTag;cat=activityTag;ord=2700503028455676400?"></iframe>');
Integration.tag(
'example-img',
'<img src="http://example.com/{{name}}.png">'
);
Integration.tag(
'example-script',
'<script src="http://ajax.googleapis.com/ajax/libs/jquery/{{version}}/jquery.min.js"></script>'
);
Integration.tag(
'example-iframe',
'<iframe src="http://ad.doubleclick.net/activity;src=654757884637545;type=groupTag;cat=activityTag;ord=2700503028455676400?"></iframe>'
);
analytics = new Analytics();
integration = new Integration();
analytics.use(tester);
Expand All @@ -246,32 +266,43 @@ describe('integration-tester', function() {
describe('script tag', function() {
it('should throw if it does not find a script tag', function() {
assert['throws'](function() {
analytics.loaded('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>');
analytics.loaded(
'<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>'
);
});
});

it('should not throw if it does find a script tag', function() {
integration.load('example-script', { version: '1.11.1' });
analytics.loaded('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>');
analytics.loaded(
'<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>'
);
});
});

describe('iframe tag', function() {
it('should throw if it does not find a iframe tag', function() {
assert['throws'](function() {
analytics.loaded('<iframe src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></iframe>');
analytics.loaded(
'<iframe src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></iframe>'
);
});
});

it('should not throw if it does find a iframe tag', function() {
integration.load('example-iframe');
analytics.loaded('<iframe src="http://ad.doubleclick.net/activity;src=654757884637545;type=groupTag;cat=activityTag;ord=2700503028455676400?"></iframe>');
analytics.loaded(
'<iframe src="http://ad.doubleclick.net/activity;src=654757884637545;type=groupTag;cat=activityTag;ord=2700503028455676400?"></iframe>'
);
});
});

it('should accept integration argument', function() {
integration.load('example-img', { name: 'example' });
analytics.loaded(integration, '<img src="http://example.com/example.png"/>');
analytics.loaded(
integration,
'<img src="http://example.com/example.png"/>'
);
});
});

Expand All @@ -291,7 +322,7 @@ describe('integration-tester', function() {

it('should not callback before all scripts have finished loading', function(done) {
var script = document.createElement('script');
script.src='/base/test/static/setGlobal.js';
script.src = '/base/test/static/setGlobal.js';
document.body.appendChild(script);
analytics.waitForScripts(function() {
document.body.removeChild(script);
Expand All @@ -303,7 +334,7 @@ describe('integration-tester', function() {

it('should call all callbacks once scripts have finished loading', function(done) {
var script = document.createElement('script');
script.src='/base/test/static/setGlobal.js';
script.src = '/base/test/static/setGlobal.js';
document.body.appendChild(script);
var called = 0;
analytics.waitForScripts(function() {
Expand Down
Loading