Skip to content
This repository has been archived by the owner on Jan 20, 2020. It is now read-only.

CircleCI Build Matrix #316

Merged
merged 5 commits into from
May 14, 2018
Merged
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
36 changes: 36 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 2.0

shared: &shared
steps:
- run:
name: "Show Node Environment"
command: 'echo "node: $(node -v)" && echo "npm: v$(npm -v)"'
- checkout
- run: npm install
- run: npm run lint
- run: npm run prettier
- run: npm test

jobs:
"node-6":
<<: *shared
docker:
- image: circleci/node:6

"node-8":
<<: *shared
docker:
- image: circleci/node:8

"node-10":
<<: *shared
docker:
- image: circleci/node:10

workflows:
version: 2
build:
jobs:
- "node-6"
- "node-8"
- "node-10"
3 changes: 0 additions & 3 deletions circle.yml

This file was deleted.

14 changes: 8 additions & 6 deletions lib/orderbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ class Orderbook {

state(book) {
if (book) {
book.bids
.forEach(order => this.add({
book.bids.forEach(order =>
this.add({
id: order[2],
side: 'buy',
price: BigNumber(order[0]),
size: BigNumber(order[1]),
}));
})
);

book.asks
.forEach(order => this.add({
book.asks.forEach(order =>
this.add({
id: order[2],
side: 'sell',
price: BigNumber(order[0]),
size: BigNumber(order[1]),
}));
})
);
} else {
book = { asks: [], bids: [] };

Expand Down
7 changes: 4 additions & 3 deletions lib/orderbook_sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ class OrderbookSync extends WebsocketClient {
// subscriptions changed -- possible new products
_newSubscription(data) {
const channel = data.channels.find(c => c.name === 'full');
channel && channel.product_ids
.filter(productID => !(productID in this.books))
.forEach(this._newProduct, this);
channel &&
channel.product_ids
.filter(productID => !(productID in this.books))
.forEach(this._newProduct, this);
}

processMessage(data) {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"url": "git://github.com/coinbase/gdax-node.git"
},
"scripts": {
"lint": "eslint --ext .js ./",
"prettier": "prettier -l README.md *.js **/*.js",
"prettier-write": "npm run prettier -- --write",
"test": "mocha --full-trace --ui tdd --bail --reporter spec tests/*.js",
"precommit": "lint-staged"
},
Expand Down
13 changes: 7 additions & 6 deletions tests/authenticated.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ suite('AuthenticatedClient', () => {
.then(() => done())
.catch(err => assert.ifError(err) || assert.fail());
});

test('.getAccountTransfers()', done => {
const expectedResponse = [
{
Expand Down Expand Up @@ -741,7 +741,7 @@ suite('AuthenticatedClient', () => {

test('.depositCrypto()', done => {
const params = {
currency: 'BTC'
currency: 'BTC',
};
const expectedAccountsRespons = [
{
Expand All @@ -751,8 +751,8 @@ suite('AuthenticatedClient', () => {
currency: 'BTC',
type: 'wallet',
primary: true,
active: true
}
active: true,
},
];
const expectedAddressResponse = {
id: 'test-id',
Expand All @@ -765,9 +765,10 @@ suite('AuthenticatedClient', () => {
resource: 'address',
resource_path: '/v2/accounts/test-account-id/addresses/test-id',
warning_title: 'Only send Bitcoin (BTC) to this address',
warning_details: 'Sending any other digital asset, including Bitcoin Cash (BCH), will result in permanent loss.',
warning_details:
'Sending any other digital asset, including Bitcoin Cash (BCH), will result in permanent loss.',
callback_url: null,
exchange_deposit_address: true
exchange_deposit_address: true,
};

nock(EXCHANGE_API_URL)
Expand Down
51 changes: 30 additions & 21 deletions tests/orderbook_sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ suite('OrderbookSync', () => {
test: true,
product_id: 'BTC-USD',
});
server.close();
done();
});
});

server.on('connection', socket => {
socket.send(JSON.stringify({ test: true, product_id: 'BTC-USD' }));
socket.on('message', () => {
server.close();
done();
});
});
});

Expand All @@ -128,13 +130,15 @@ suite('OrderbookSync', () => {
test: true,
product_id: 'BTC-USD',
});
server.close();
done();
});
});

server.on('connection', socket => {
socket.send(JSON.stringify({ test: true, product_id: 'BTC-USD' }));
socket.on('message', () => {
server.close();
done();
});
});
});

Expand All @@ -152,13 +156,15 @@ suite('OrderbookSync', () => {

orderbookSync.on('error', err => {
assert.equal(err.message, 'Failed to load orderbook: whoops');
server.close();
done();
});
});

server.on('connection', socket => {
socket.send(JSON.stringify({ product_id: 'BTC-USD' }));
socket.on('message', () => {
server.close();
done();
});
});
});

Expand All @@ -177,13 +183,15 @@ suite('OrderbookSync', () => {

orderbookSync.on('error', err => {
assert.equal(err.message, 'Failed to load orderbook: whoops');
server.close();
done();
});
});

server.on('connection', socket => {
socket.send(JSON.stringify({ product_id: 'BTC-USD' }));
socket.on('message', () => {
server.close();
done();
});
});
});

Expand All @@ -202,7 +210,6 @@ suite('OrderbookSync', () => {
bids: [],
});

let count = 0;
const server = testserver(port, () => {
const orderbookSync = new Gdax.OrderbookSync(
['BTC-USD', 'ETH-USD'],
Expand All @@ -212,20 +219,18 @@ suite('OrderbookSync', () => {

orderbookSync.on('message', data => {
const state = orderbookSync.books[data.product_id].state();

assert.deepEqual(state, { asks: [], bids: [] });
assert.equal(orderbookSync.books['ETH-BTC'], undefined);

if (++count >= 2) {
server.close();
done();
}
});
});

server.on('connection', socket => {
socket.send(JSON.stringify({ product_id: 'BTC-USD' }));
socket.send(JSON.stringify({ product_id: 'ETH-USD' }));
socket.on('message', () => {
server.close();
done();
});
});
});

Expand All @@ -245,14 +250,16 @@ suite('OrderbookSync', () => {
);

orderbookSync.on('sync', productID => {
assert.equal(productID, 'BTC-USD');
server.close();
done();
assert.equal(productID, 'BTC-USD');
});
});

server.on('connection', socket => {
socket.send(JSON.stringify({ product_id: 'BTC-USD' }));
socket.on('message', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find :)

server.close();
done();
});
});
});

Expand All @@ -272,14 +279,16 @@ suite('OrderbookSync', () => {
);

orderbookSync.on('synced', productID => {
assert.equal(productID, 'BTC-USD');
server.close();
done();
assert.equal(productID, 'BTC-USD');
});
});

server.on('connection', socket => {
socket.send(JSON.stringify({ product_id: 'BTC-USD' }));
socket.on('message', () => {
server.close();
done();
});
});
});
});
7 changes: 4 additions & 3 deletions tests/websocket.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,6 @@ suite('WebsocketClient', () => {
client.once('error', err => {
assert.equal(err.message, 'test error');
assert.equal(err.reason, 'because error');

server.close();
done();
});
});

Expand All @@ -283,6 +280,10 @@ suite('WebsocketClient', () => {
reason: 'because error',
})
);
socket.on('message', () => {
server.close();
done();
});
});
});
});