Skip to content

Commit 3fe9356

Browse files
authored
Merge pull request #8 from psxcode/actions
add actions
2 parents 0236d2c + 3d32cd7 commit 3fe9356

23 files changed

+1698
-1308
lines changed

.babelrc

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/coverage.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
jobs:
8+
coverage:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: Get Yarn cache directory
16+
id: yarn-cache
17+
run: echo "::set-output name=dir::$(yarn cache dir)"
18+
19+
- name: Restore Yarn cache
20+
uses: actions/cache@v1
21+
with:
22+
path: ${{ steps.yarn-cache.outputs.dir }}
23+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
24+
restore-keys: |
25+
${{ runner.os }}-yarn-
26+
27+
- name: Use Node v12
28+
uses: actions/setup-node@v1
29+
with:
30+
node-version: 12.x
31+
32+
- name: Install dependencies
33+
run: yarn install --frozen-lockfile
34+
35+
- name: Test
36+
run: yarn cover
37+
continue-on-error: false
38+
39+
- name: Generate report
40+
run: yarn nyc report --reporter=json
41+
42+
- name: Codecov upload
43+
uses: codecov/codecov-action@v1
44+
with:
45+
file: "coverage/*.json"
46+
47+
48+

.github/workflows/test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
11+
12+
strategy:
13+
matrix:
14+
node-version:
15+
- 10.x
16+
- 12.x
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
22+
- name: Get Yarn cache directory
23+
id: yarn-cache
24+
run: echo "::set-output name=dir::$(yarn cache dir)"
25+
26+
- name: Restore Yarn cache
27+
uses: actions/cache@v1
28+
with:
29+
path: ${{ steps.yarn-cache.outputs.dir }}
30+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
31+
restore-keys: |
32+
${{ runner.os }}-yarn-
33+
34+
- name: Use Node v${{ matrix.node-version }}
35+
uses: actions/setup-node@v1
36+
with:
37+
node-version: ${{ matrix.node-version }}
38+
39+
- name: Install dependencies
40+
run: yarn install --frozen-lockfile
41+
42+
- name: Test
43+
run: yarn test

babel.config.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module.exports = function (api) {
2+
switch (api.env()) {
3+
case 'production':
4+
return {
5+
presets: [
6+
[
7+
'@babel/preset-env',
8+
{
9+
targets: {
10+
node: '8',
11+
},
12+
},
13+
],
14+
'@babel/preset-typescript',
15+
],
16+
plugins: [
17+
'@babel/plugin-transform-runtime',
18+
],
19+
sourceMaps: 'inline',
20+
}
21+
case 'test': {
22+
return {
23+
presets: [
24+
[
25+
'@babel/preset-env',
26+
{
27+
targets: {
28+
node: '8',
29+
},
30+
},
31+
],
32+
'@babel/preset-typescript',
33+
],
34+
plugins: [
35+
'istanbul',
36+
],
37+
sourceMaps: true,
38+
retainLines: true,
39+
}
40+
}
41+
}
42+
}

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"author": "psxcode <[email protected]> (https://github.com/psxcode)",
99
"homepage": "https://github.com/psxcode/node-on",
1010
"scripts": {
11-
"test": "NODE_ENV=test nyc mocha 'test/*.spec.ts'",
11+
"cover": "NODE_ENV=test nyc mocha 'test/*.spec.ts'",
12+
"test": "NODE_ENV=test mocha -r ./require.js 'test/*.spec.ts'",
1213
"build": "NODE_ENV=production rimraf build && tsc -p tsconfig.build.json",
13-
"copy": "cp ./{package.json,LICENSE,readme.md} ./build/",
14-
"release": "yarn build && yarn copy && npm publish build"
14+
"copy": "cp ./{package.json,LICENSE,readme.md} ./build/"
1515
},
1616
"devDependencies": {
1717
"@babel/core": "^7.2.2",
@@ -27,11 +27,10 @@
2727
"eslint": "^5.11.1",
2828
"eslint-plugin-import": "^2.14.0",
2929
"eslint-plugin-typescript": "^1.0.0-0",
30-
"esm": "^3.1.4",
3130
"mocha": "^5.2.0",
3231
"nyc": "^13.1.0",
3332
"rimraf": "^2.6.3",
34-
"spyfn": "^0.1.1",
33+
"test-fn": "^0.1.3",
3534
"typescript": "^3.2.4"
3635
},
3736
"nyc": {
@@ -42,8 +41,7 @@
4241
"**/*.spec.ts"
4342
],
4443
"require": [
45-
"./tshook.js",
46-
"esm"
44+
"./require.js"
4745
],
4846
"reporter": [
4947
"lcov",

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# node-on
2+
[![Release](https://img.shields.io/github/release/psxcode/node-on.svg)](https://github.com/psxcode/node-on/releases/latest)
3+
[![GitHub Actions](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fpsxcode%2Fnode-on%2Fbadge)](https://actions-badge.atrox.dev/psxcode/node-on/goto)
4+
[![codecov](https://codecov.io/gh/psxcode/node-on/branch/master/graph/badge.svg)](https://codecov.io/gh/psxcode/node-on)
25

36
Node-js EventEmitter helpers
47

require.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require('@babel/register')({
2+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
3+
})

test/on-ex.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { EventEmitter } from 'events'
22
import { expect } from 'chai'
3-
import { createSpy, getSpyCalls } from 'spyfn'
3+
import fn from 'test-fn'
44
import { waitTimePromise as wait } from '@psxcode/wait'
55
import onEx from '../src/on-ex'
66
import listenerCount from './listener-count'
77

88
describe('[ onEx ]', () => {
99
it('single ee', async () => {
1010
const ee = new EventEmitter()
11-
const spy = createSpy(() => {})
11+
const spy = fn()
1212

1313
/* subscribe */
1414
const unsub = onEx('event1', 'event2')(spy)(ee)
@@ -27,7 +27,7 @@ describe('[ onEx ]', () => {
2727
/* wait for ee */
2828
await wait(0)
2929

30-
expect(getSpyCalls(spy)).deep.eq([
30+
expect(spy.calls).deep.eq([
3131
[{ value: 'e1', event: 'event1', index: 0, emitter: ee, emitterIndex: 0 }],
3232
[{ value: 'e1-repeat', event: 'event1', index: 1, emitter: ee, emitterIndex: 0 }],
3333
[{ value: 'e2', event: 'event2', index: 2, emitter: ee, emitterIndex: 0 }],
@@ -39,7 +39,7 @@ describe('[ onEx ]', () => {
3939
const ee0 = new EventEmitter()
4040
const ee1 = new EventEmitter()
4141
const ee2 = new EventEmitter()
42-
const spy = createSpy(() => {})
42+
const spy = fn()
4343

4444
/* subscribe */
4545
const unsub = onEx('event1', 'event2')(spy)(ee0, ee1, ee2)
@@ -58,7 +58,7 @@ describe('[ onEx ]', () => {
5858
/* wait for ee */
5959
await wait(0)
6060

61-
expect(getSpyCalls(spy)).deep.eq([
61+
expect(spy.calls).deep.eq([
6262
[{ value: 'e1', event: 'event1', index: 0, emitter: ee0, emitterIndex: 0 }],
6363
[{ value: 'e1-repeat', event: 'event1', index: 0, emitter: ee1, emitterIndex: 1 }],
6464
[{ value: 'e2', event: 'event2', index: 0, emitter: ee2, emitterIndex: 2 }],

test/on.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { EventEmitter } from 'events'
22
import { expect } from 'chai'
3-
import { createSpy, getSpyCalls } from 'spyfn'
3+
import fn from 'test-fn'
44
import { waitTimePromise as wait } from '@psxcode/wait'
55
import on from '../src/on'
66
import listenerCount from './listener-count'
77

88
describe('[ on ]', () => {
99
it('single ee', async () => {
1010
const ee = new EventEmitter()
11-
const spy = createSpy(() => {})
11+
const spy = fn()
1212

1313
/* subscribe */
1414
const unsub = on('event1', 'event2')(spy)(ee)
@@ -30,7 +30,7 @@ describe('[ on ]', () => {
3030
/* wait for ee */
3131
await wait(0)
3232

33-
expect(getSpyCalls(spy)).deep.eq([
33+
expect(spy.calls).deep.eq([
3434
['e1'],
3535
['e1-repeat'],
3636
['e2'],
@@ -42,7 +42,7 @@ describe('[ on ]', () => {
4242
const ee0 = new EventEmitter()
4343
const ee1 = new EventEmitter()
4444
const ee2 = new EventEmitter()
45-
const spy = createSpy(() => {})
45+
const spy = fn()
4646

4747
/* subscribe */
4848
const unsub = on('event1', 'event2')(spy)(ee0, ee1, ee2)
@@ -61,7 +61,7 @@ describe('[ on ]', () => {
6161
/* wait for ee */
6262
await wait(0)
6363

64-
expect(getSpyCalls(spy)).deep.eq([
64+
expect(spy.calls).deep.eq([
6565
['e1'],
6666
['e1-repeat'],
6767
['e2'],

test/once-all-ex-promise-reject.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { EventEmitter } from 'events'
22
import { expect } from 'chai'
3-
import { createSpy, getSpyCalls } from 'spyfn'
3+
import fn from 'test-fn'
44
import { waitTimePromise as wait } from '@psxcode/wait'
55
import onceAllPromiseExReject from '../src/once-all-ex-promise-reject'
66
import listenerCount from './listener-count'
77

88
describe('[ onceAllExPromiseReject ]', () => {
99
it('single ee', async () => {
1010
const ee = new EventEmitter()
11-
const resolveSpy = createSpy(() => {})
12-
const rejectSpy = createSpy(() => {})
11+
const resolveSpy = fn()
12+
const rejectSpy = fn()
1313

1414
/* subscribe */
1515
onceAllPromiseExReject(['error'], ['event1', 'event2', 'event3'])(ee)
@@ -25,21 +25,21 @@ describe('[ onceAllExPromiseReject ]', () => {
2525
/* wait for ee to fire */
2626
await wait(0)
2727

28-
expect(getSpyCalls(resolveSpy)).deep.eq([
28+
expect(resolveSpy.calls).deep.eq([
2929
[
3030
[{ value: 'e1', event: 'event1', index: 0, emitter: ee, emitterIndex: 0 }],
3131
],
3232
])
33-
expect(getSpyCalls(rejectSpy)).deep.eq([])
33+
expect(rejectSpy.calls).deep.eq([])
3434
expect(listenerCount(ee)).eq(0)
3535
})
3636

3737
it('multiple ees', async () => {
3838
const ee0 = new EventEmitter()
3939
const ee1 = new EventEmitter()
4040
const ee2 = new EventEmitter()
41-
const resolveSpy = createSpy(() => {})
42-
const rejectSpy = createSpy(() => {})
41+
const resolveSpy = fn()
42+
const rejectSpy = fn()
4343

4444
/* subscribe */
4545
onceAllPromiseExReject(['error'], ['event1', 'event2', 'event3'])(ee0, ee1, ee2).then(resolveSpy, rejectSpy)
@@ -54,7 +54,7 @@ describe('[ onceAllExPromiseReject ]', () => {
5454
/* wait for ee to fire */
5555
await wait(0)
5656

57-
expect(getSpyCalls(resolveSpy)).deep.eq([
57+
expect(resolveSpy.calls).deep.eq([
5858
[
5959
[
6060
{ value: 'e3', event: 'event3', index: 0, emitter: ee0, emitterIndex: 0 },
@@ -63,14 +63,14 @@ describe('[ onceAllExPromiseReject ]', () => {
6363
],
6464
],
6565
])
66-
expect(getSpyCalls(rejectSpy)).deep.eq([])
66+
expect(rejectSpy.calls).deep.eq([])
6767
expect(listenerCount(ee0, ee1, ee2)).eq(0)
6868
})
6969

7070
it('single ee error', async () => {
7171
const ee = new EventEmitter()
72-
const resolveSpy = createSpy(() => {})
73-
const rejectSpy = createSpy(() => {})
72+
const resolveSpy = fn()
73+
const rejectSpy = fn()
7474

7575
/* subscribe */
7676
onceAllPromiseExReject(['error'], ['event1', 'event2'])(ee).then(resolveSpy, rejectSpy)
@@ -83,8 +83,8 @@ describe('[ onceAllExPromiseReject ]', () => {
8383
/* wait for ee to fire */
8484
await wait(0)
8585

86-
expect(getSpyCalls(resolveSpy)).deep.eq([])
87-
expect(getSpyCalls(rejectSpy)).deep.eq([
86+
expect(resolveSpy.calls).deep.eq([])
87+
expect(rejectSpy.calls).deep.eq([
8888
[
8989
{ value: 'err', event: 'error', index: 0, emitter: ee, emitterIndex: 0 },
9090
],

0 commit comments

Comments
 (0)