Skip to content

Commit

Permalink
Merge pull request #122 from thoov/import-changes
Browse files Browse the repository at this point in the history
Support ES2015 imports via index file
  • Loading branch information
thoov authored Oct 31, 2016
2 parents 7d12d9c + 26bfcdd commit 54485e1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ describe('Chat Unit Test', () => {
const messageLen = chatApp.messages.length;
assert.equal(messageLen, 2, '2 messages where sent from the s server');

mockServer.stop();
done();
mockServer.stop(done);
}, 100);
});
});
Expand Down Expand Up @@ -110,7 +109,7 @@ describe('Chat Unit Test', () => {
setTimeout(() => {
const messageLen = chatApp.messages.length;
assert.equal(messageLen, 2, '2 messages where sent from the server');
done();
mockServer.stop(done);
}, 100);
});
});
Expand All @@ -122,41 +121,43 @@ describe('Chat Unit Test', () => {
The easiest way to work on the project is to clone the repo down via:
```shell
git clone git@github.com:thoov/mock-socket.git; cd mock-socket; npm i
git clone git@github.com:thoov/mock-socket.git
cd mock-socket
yarn
```
Then to create a local build via:
```shell
npm run build
yarn build
```
Then create a local npm link via:
```shell
npm link
yarn link
```
At this point you can create other projects / apps locally and reference this local build via:
```shell
npm link mock-socket
yarn link mock-socket
```
from within your other projects folder. Make sure that after any changes you run `npm run build`!
from within your other projects folder. Make sure that after any changes you run `yarn build`!
### Tests
This project uses mocha as its test framework. Tests are located in /test and have 1 of 3 file name prefixes (functional-, issue-#, or unit-).
```shell
npm test
yarn test
```
### Linting
This project uses eslint and a rules set from [airbnb's javascript style guides](https://github.com/airbnb/javascript). To run linting:
```shell
npm run lint
yarn lint
```
### Code Coverage
Expand Down
2 changes: 1 addition & 1 deletion dist/main.js → dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
exports: {}
};
factory(mod.exports, global.server, global.socketIo, global.websocket);
global.main = mod.exports;
global.index = mod.exports;
}
})(this, function (exports, _server, _socketIo, _websocket) {
'use strict';
Expand Down
6 changes: 5 additions & 1 deletion dist/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
/*
* Removes the mock websocket object from the global object
*/
stop() {
stop(callback = () => {}) {
const globalObj = (0, _globalObject2.default)();

if (this.originalWebSocket) {
Expand All @@ -86,6 +86,10 @@
this.originalWebSocket = null;

_networkBridge2.default.removeServer(this.url);

if (typeof callback === 'function') {
callback();
}
}

/*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mock-socket",
"version": "5.0.1",
"description": "Javascript mocking library for websockets and socket.io",
"main": "./dist/main.js",
"main": "./dist/index.js",
"directories": {
"test": "tests"
},
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Server extends EventTarget {
/*
* Removes the mock websocket object from the global object
*/
stop() {
stop(callback = () => {}) {
const globalObj = globalObject();

if (this.originalWebSocket) {
Expand All @@ -57,6 +57,10 @@ class Server extends EventTarget {
this.originalWebSocket = null;

networkBridge.removeServer(this.url);

if (typeof callback === 'function') {
callback();
}
}

/*
Expand Down

0 comments on commit 54485e1

Please sign in to comment.