forked from berga/rx-ipc-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ddanninger/6.2
Fixes Rxjs 6 compatibility colinskow#5
- Loading branch information
Showing
4 changed files
with
124 additions
and
122 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
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 |
---|---|---|
@@ -1,109 +1,112 @@ | ||
import { expect } from 'chai'; | ||
import { ipcRenderer } from 'electron'; | ||
import { slow, suite, test, timeout } from 'mocha-typescript'; | ||
import { Observable } from 'rxjs'; | ||
import {expect} from 'chai'; | ||
import {ipcRenderer} from 'electron'; | ||
import {suite, test} from 'mocha-typescript'; | ||
import {concat, from, Observable} from 'rxjs'; | ||
import rxIpc from '../src/renderer'; | ||
|
||
@suite('Rx-Electron-IPC') | ||
class Main { | ||
|
||
@test 'It should pass an Observable from main to renderer'() { | ||
const results = []; | ||
return new Promise((resolve) => { | ||
rxIpc.runCommand('test-main', null, 1, 2, {test: 'passed'}) | ||
.subscribe( | ||
(data) => { | ||
results.push(data); | ||
}, | ||
(err) => { | ||
throw err; | ||
}, | ||
() => { | ||
expect(results).to.deep.equal([1, 2, {test: 'passed'}]); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
@test 'It should pass an Observable from main to renderer'() { | ||
const results = []; | ||
return new Promise((resolve) => { | ||
rxIpc.runCommand('test-main', null, 1, 2, {test: 'passed'}) | ||
.subscribe( | ||
(data) => { | ||
results.push(data); | ||
}, | ||
(err) => { | ||
throw err; | ||
}, | ||
() => { | ||
expect(results).to.deep.equal([1, 2, {test: 'passed'}]); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
@test 'It should correctly pass an error'() { | ||
const results = []; | ||
return new Promise((resolve) => { | ||
rxIpc.runCommand('test-error', null) | ||
.subscribe( | ||
(data) => { | ||
results.push(data); | ||
}, | ||
(err) => { | ||
expect(results).to.deep.equal([1, 2]); | ||
expect(err).to.equal('Test Error'); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
@test 'It should correctly pass an error'() { | ||
const results = []; | ||
return new Promise((resolve) => { | ||
rxIpc.runCommand('test-error', null) | ||
.subscribe( | ||
(data) => { | ||
results.push(data); | ||
}, | ||
(err) => { | ||
expect(results).to.deep.equal([1, 2]); | ||
expect(err).to.equal('Test Error'); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
@test 'It should handle two instances of the same command'() { | ||
const results = []; | ||
return new Promise((resolve) => { | ||
rxIpc.runCommand('test-main', null, 1, 2, 3) | ||
.concat(rxIpc.runCommand('test-main', null, 4, 5, 6)) | ||
.subscribe( | ||
(data) => { | ||
results.push(data); | ||
}, | ||
(err) => { | ||
throw err; | ||
}, | ||
() => { | ||
expect(results).to.deep.equal([1, 2, 3, 4, 5, 6]); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
@test 'It should handle two instances of the same command'() { | ||
const results = []; | ||
return new Promise((resolve) => { | ||
concat( | ||
rxIpc.runCommand('test-main', null, 1, 2, 3), | ||
rxIpc.runCommand('test-main', null, 4, 5, 6) | ||
).subscribe( | ||
(data) => { | ||
results.push(data); | ||
}, | ||
(err) => { | ||
throw err; | ||
}, | ||
() => { | ||
expect(results).to.deep.equal([1, 2, 3, 4, 5, 6]); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
@test 'The renderer should run a command from the main process'() { | ||
return new Promise((resolve) => { | ||
function testCommand(...args) { | ||
return from(args); | ||
} | ||
|
||
@test 'The renderer should run a command from the main process'() { | ||
return new Promise((resolve) => { | ||
function testCommand(...args) { | ||
return Observable.from(args); | ||
} | ||
ipcRenderer.on('results-from-main', (event, results) => { | ||
expect(results).to.deep.equal([3, 2, 1]); | ||
resolve(); | ||
}); | ||
rxIpc.registerListener('command-from-main', testCommand); | ||
ipcRenderer.send('main-run-command'); | ||
}); | ||
} | ||
ipcRenderer.on('results-from-main', (event, results) => { | ||
expect(results).to.deep.equal([3, 2, 1]); | ||
resolve(); | ||
}); | ||
rxIpc.registerListener('command-from-main', testCommand); | ||
ipcRenderer.send('main-run-command'); | ||
}); | ||
} | ||
|
||
@test 'It should throw an error if given an unregistered command'() { | ||
return new Promise((resolve, reject) => { | ||
rxIpc.runCommand('invalid', null) | ||
.subscribe( | ||
(data) => { | ||
reject('We should not receive data here.'); | ||
}, | ||
(err) => { | ||
expect(err).to.equal('Invalid channel: invalid'); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
@test 'It should throw an error if given an unregistered command'() { | ||
return new Promise((resolve, reject) => { | ||
rxIpc.runCommand('invalid', null) | ||
.subscribe( | ||
(data) => { | ||
reject('We should not receive data here.'); | ||
}, | ||
(err) => { | ||
expect(err).to.equal('Invalid channel: invalid'); | ||
resolve(); | ||
@test 'It should clean up listeners'() { | ||
function noop() { | ||
return new Observable(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
@test 'It should clean up listeners'() { | ||
function noop() { | ||
return new Observable(); | ||
rxIpc.registerListener('remove-test-1', noop); | ||
rxIpc.registerListener('remove-test-1', noop); | ||
expect(rxIpc._getListenerCount('remove-test-1')).to.equal(2); | ||
rxIpc.removeListeners('remove-test-1'); | ||
expect(rxIpc._getListenerCount('remove-test-1')).to.equal(0); | ||
rxIpc.registerListener('remove-test-2', noop); | ||
expect(rxIpc._getListenerCount('remove-test-2')).to.equal(1); | ||
rxIpc.cleanUp(); | ||
expect(rxIpc._getListenerCount('remove-test-2')).to.equal(0); | ||
} | ||
rxIpc.registerListener('remove-test-1', noop); | ||
rxIpc.registerListener('remove-test-1', noop); | ||
expect(rxIpc._getListenerCount('remove-test-1')).to.equal(2); | ||
rxIpc.removeListeners('remove-test-1'); | ||
expect(rxIpc._getListenerCount('remove-test-1')).to.equal(0); | ||
rxIpc.registerListener('remove-test-2', noop); | ||
expect(rxIpc._getListenerCount('remove-test-2')).to.equal(1); | ||
rxIpc.cleanUp(); | ||
expect(rxIpc._getListenerCount('remove-test-2')).to.equal(0); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -6,20 +6,18 @@ | |
version "3.5.2" | ||
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-3.5.2.tgz#c11cd2817d3a401b7ba0f5a420f35c56139b1c1e" | ||
|
||
"@types/electron@^1.4.37": | ||
version "1.4.37" | ||
resolved "https://registry.yarnpkg.com/@types/electron/-/electron-1.4.37.tgz#cfff6958f224842c1742a6e4873ed7135e5f2ff3" | ||
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/mocha@^2.2.41": | ||
version "2.2.41" | ||
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.41.tgz#e27cf0817153eb9f2713b2d3f6c68f1e1c3ca608" | ||
|
||
"@types/node@*", "@types/node@^7.0.18": | ||
"@types/node@^7.0.18": | ||
version "7.0.18" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.18.tgz#cd67f27d3dc0cfb746f0bdd5e086c4c5d55be173" | ||
|
||
"@types/node@^8.0.24": | ||
version "8.10.19" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.19.tgz#66b5b6325c048cbf4512b7a88b0e79c2ee99d3d2" | ||
|
||
ajv@^4.9.1: | ||
version "4.11.8" | ||
resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.8.tgz#82ffb02b29e662ae53bdc20af15947706739c536" | ||
|
@@ -287,10 +285,11 @@ electron-window@^0.8.0: | |
dependencies: | ||
is-electron-renderer "^2.0.0" | ||
|
||
electron@^1.6.6: | ||
version "1.6.8" | ||
resolved "https://registry.yarnpkg.com/electron/-/electron-1.6.8.tgz#41cbbe7272ccd93339c040f856c0d6372a4ddb07" | ||
electron@^2.0.2: | ||
version "2.0.2" | ||
resolved "https://registry.yarnpkg.com/electron/-/electron-2.0.2.tgz#b77e05f83419cc5ec921a2d21f35b55e4bfc3d68" | ||
dependencies: | ||
"@types/node" "^8.0.24" | ||
electron-download "^3.0.1" | ||
extract-zip "^1.0.3" | ||
|
||
|
@@ -1007,11 +1006,11 @@ rimraf@^2.2.8, rimraf@^2.6.1: | |
dependencies: | ||
glob "^7.0.5" | ||
|
||
rxjs@^5.0.0: | ||
version "5.3.1" | ||
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.3.1.tgz#9ecc9e722247e4f4490d30a878577a3740fd0cb7" | ||
rxjs@^6.2.0: | ||
version "6.2.0" | ||
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.2.0.tgz#e024d0e180b72756a83c2aaea8f25423751ba978" | ||
dependencies: | ||
symbol-observable "^1.0.1" | ||
tslib "^1.9.0" | ||
|
||
safe-buffer@^5.0.1: | ||
version "5.0.1" | ||
|
@@ -1149,10 +1148,6 @@ supports-color@^2.0.0: | |
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" | ||
|
||
symbol-observable@^1.0.1: | ||
version "1.0.4" | ||
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.4.tgz#29bf615d4aa7121bdd898b22d4b3f9bc4e2aa03d" | ||
|
||
[email protected]: | ||
version "0.0.2" | ||
resolved "https://registry.yarnpkg.com/throttleit/-/throttleit-0.0.2.tgz#cfedf88e60c00dd9697b61fdd2a8343a9b680eaf" | ||
|
@@ -1200,6 +1195,10 @@ tslib@^1.6.0, tslib@^1.7.0: | |
version "1.7.0" | ||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.0.tgz#6e8366695f72961252b35167b0dd4fbeeafba491" | ||
|
||
tslib@^1.9.0: | ||
version "1.9.2" | ||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.2.tgz#8be0cc9a1f6dc7727c38deb16c2ebd1a2892988e" | ||
|
||
tslint@^5.2.0: | ||
version "5.2.0" | ||
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.2.0.tgz#16a2addf20cb748385f544e9a0edab086bc34114" | ||
|