-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
4,177 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
version: 2.1 | ||
|
||
workflows: | ||
build-test: | ||
jobs: | ||
- prep-deps | ||
- test-build: | ||
requires: | ||
- prep-deps | ||
- test-lint: | ||
requires: | ||
- prep-deps | ||
- test-unit: | ||
requires: | ||
- prep-deps | ||
- all-tests-pass: | ||
requires: | ||
- test-build | ||
- test-lint | ||
- test-unit | ||
|
||
jobs: | ||
prep-deps: | ||
docker: | ||
- image: circleci/node:10 | ||
steps: | ||
- checkout | ||
- run: | ||
name: Install deps | ||
command: | | ||
.circleci/scripts/deps-install.sh | ||
- run: | ||
name: Collect yarn install HAR logs | ||
command: | | ||
.circleci/scripts/collect-har-artifact.sh | ||
- persist_to_workspace: | ||
root: . | ||
paths: | ||
- node_modules | ||
- build-artifacts | ||
|
||
test-build: | ||
docker: | ||
- image: circleci/node:10 | ||
steps: | ||
- checkout | ||
- attach_workspace: | ||
at: . | ||
- run: | ||
name: Build project | ||
command: yarn build | ||
|
||
test-lint: | ||
docker: | ||
- image: circleci/node:10 | ||
steps: | ||
- checkout | ||
- attach_workspace: | ||
at: . | ||
- run: | ||
name: Lint | ||
command: yarn lint | ||
|
||
test-unit: | ||
docker: | ||
- image: circleci/node:10 | ||
steps: | ||
- checkout | ||
- attach_workspace: | ||
at: . | ||
- run: | ||
name: Unit tests | ||
command: yarn test | ||
|
||
all-tests-pass: | ||
docker: | ||
- image: circleci/node:10 | ||
steps: | ||
- run: | ||
name: All tests passed | ||
command: echo 'Great success' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -x | ||
set -e | ||
set -u | ||
set -o pipefail | ||
|
||
mkdir -p build-artifacts/yarn-install-har | ||
mv ./*.har build-artifacts/yarn-install-har/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -x | ||
set -e | ||
set -u | ||
set -o pipefail | ||
|
||
yarn --frozen-lockfile --ignore-scripts --har |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
indent_size = 4 | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.js | ||
!.eslintrc.js | ||
!jest.config.js | ||
node_modules | ||
dist | ||
coverage | ||
*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
root: true, | ||
extends: [ | ||
'@metamask/eslint-config', | ||
'@metamask/eslint-config/config/jest', | ||
'@metamask/eslint-config/config/nodejs', | ||
'@metamask/eslint-config/config/typescript', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
* text=auto | ||
*.d.ts linguist-generated=true | ||
|
||
# Reviewing the lockfile contents is an important step in verifying that | ||
# we're using the dependencies we expect to be using | ||
package-lock.json linguist-generated=false | ||
yarn.lock linguist-generated=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import SafeEventEmitter from './index'; | ||
|
||
describe('safeEventEmitter', () => { | ||
it('can be constructed without error', () => { | ||
expect(new SafeEventEmitter()).toBeDefined(); | ||
}); | ||
|
||
it('can emit a value with no listeners', () => { | ||
const see = new SafeEventEmitter(); | ||
expect(see.emit('foo', 42)).toBe(false); | ||
}); | ||
|
||
it('can emit a value with 1 listeners', () => { | ||
expect.assertions(2); | ||
|
||
const see = new SafeEventEmitter(); | ||
see.on('foo', (x) => expect(x).toBe(42)); | ||
expect(see.emit('foo', 42)).toBe(true); | ||
}); | ||
|
||
it('can emit a value with 2 listeners', () => { | ||
expect.assertions(3); | ||
|
||
const see = new SafeEventEmitter(); | ||
see.on('foo', (x) => expect(x).toBe(42)); | ||
see.on('foo', (x) => expect(x).toBe(42)); | ||
expect(see.emit('foo', 42)).toBe(true); | ||
}); | ||
|
||
it('returns false when _events is somehow undefined', () => { | ||
const see = new SafeEventEmitter(); | ||
see.on('foo', () => { /* */ }); | ||
delete (see as any)._events; | ||
expect(see.emit('foo', 42)).toBe(false); | ||
}); | ||
|
||
it('throws error from handler after setTimeout', () => { | ||
jest.useFakeTimers(); | ||
const see = new SafeEventEmitter(); | ||
see.on('boom', () => { | ||
throw new Error('foo'); | ||
}); | ||
expect(() => { | ||
see.emit('boom'); | ||
}).not.toThrow(); | ||
expect(() => { | ||
jest.runAllTimers(); | ||
}).toThrow('foo'); | ||
}); | ||
|
||
it('throws error emitted when there is no error handler', () => { | ||
const see = new SafeEventEmitter(); | ||
expect(() => { | ||
see.emit('error', new Error('foo')); | ||
}).toThrow('foo'); | ||
}); | ||
|
||
it('throws error emitted when there is no error handler AND _events is somehow undefined', () => { | ||
const see = new SafeEventEmitter(); | ||
delete (see as any)._events; | ||
expect(() => { | ||
see.emit('error', new Error('foo')); | ||
}).toThrow('foo'); | ||
}); | ||
|
||
it('throws default error when there is no error handler and error event emitted', () => { | ||
const see = new SafeEventEmitter(); | ||
expect(() => { | ||
see.emit('error'); | ||
}).toThrow('Unhandled error.'); | ||
}); | ||
|
||
it('throws error when there is no error handler and error event emitted', () => { | ||
const see = new SafeEventEmitter(); | ||
expect(() => { | ||
see.emit('error', { message: 'foo' }); | ||
}).toThrow('Unhandled error. (foo)'); | ||
}); | ||
}); |
Oops, something went wrong.