Skip to content

Commit be83839

Browse files
authored
Merge pull request #57 from lgeiger/electron-tests
Add Electron tests
2 parents a51e740 + aa46c7f commit be83839

File tree

6 files changed

+84
-64
lines changed

6 files changed

+84
-64
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
*.dll filter=lfs diff=lfs merge=lfs -text
21
*.lib filter=lfs diff=lfs merge=lfs -text

.travis.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ addons:
66
sources:
77
- ubuntu-toolchain-r-test
88
packages:
9+
- xvfb
910
- gcc-4.9
1011
- g++-4.9
1112
- uuid-dev
@@ -17,29 +18,35 @@ os:
1718

1819
env:
1920
matrix:
20-
- NODE_VERSION="6"
21+
- NODE_VERSION="6" DEPLOY="true"
22+
- NODE_VERSION="5" ELECTRON="0.37.8"
23+
- NODE_VERSION="6" ELECTRON="1.1.3"
24+
- NODE_VERSION="6" ELECTRON="1.4.3" REBUILD="true"
2125
global:
2226
secure: AMY9chDNyNawxPhxAksCREhbQoOmphQKo2hDuYIPXBCUNF6Zik969QlB07TVjo+Bo0KVEbG4ANTdI0FkFIhg4MuJIWUkW30ZDyCSovUx8zyWB/7IN23A4Cx4p4ZnKjezTHUQpZ9InRIZzy9kOR+215IIBP6GfxbUY89eDA6ARElcv1rwDjZqSnLAxfie6v80vIbhWxNK4kQjiEyIez5eWBjRg4//dmb63TvJjc78GFTaqmh6lRIApAyA0uKka14XR/PJw5IpDR+0Q2omHl4t4zbu9MdVNYMSD+c6iNxOq3fqZJwnyJ1ELErbtR8oeKgZX1SOew5QTCUZWQsa+ySYTCzUnhWjhCgN6W0ciVtT2PslS/ZcvnrGGIxJAOmTZwINw8sAp8yYdY9QCJOGdB5ah2oUBLGKElcFGqSblohXUEM1tXeRchmpXiiAxnPNtxc6lkZzz6NxDl2OFXSmjMS4Cr8cA//Bn6gM04xRJyETy86/8KDoL+ENc7gkeiuYUOFqkAn5X8PrqPdsPmF7yA61IF1ru/OgtiuCh+eqnzZKBPImJo2KfUIqVuRi/6eUaDfWLT7d/J84Vbe3p2nPxoFd2pSw60f/lIkzFSRZx3vBjQiW2MVUN7ZTdawMOzE4TpIV7rDOkKe7qJJobquJEjd2X9Z+8JiTYXK2pPN2GceiqAM=
2327

2428
before_install:
25-
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
26-
- source ~/.nvm/nvm.sh
27-
- nvm install $NODE_VERSION
28-
- nvm use $NODE_VERSION
29-
- node --version
30-
- npm --version
31-
- test "$(uname)" = "Darwin" || export CXX=g++-4.9 CC=gcc-4.9
32-
- gcc --version
29+
- export DISPLAY=':99.0'
30+
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
31+
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
32+
- source ~/.nvm/nvm.sh
33+
- nvm install $NODE_VERSION
34+
- nvm use $NODE_VERSION
35+
- test "$(uname)" = "Darwin" || export CXX=g++-4.9 CC=gcc-4.9
3336

34-
install: npm install
37+
install:
38+
- npm install
39+
- '[ -z "$ELECTRON" ] || npm install electron-prebuilt@${ELECTRON}'
40+
- '[ -z "$REBUILD" ] || npm install -g node-gyp'
41+
- '[ -z "$REBUILD" ] || node-gyp rebuild --runtime=electron --target=${ELECTRON} --disturl=https://atom.io/download/atom-shell --build-from-source'
3542

36-
script: travis_retry npm test
43+
script: if [[ -z "$ELECTRON" ]]; then travis_retry npm test; else travis_retry npm run test:electron; fi
3744

3845
deploy:
3946
provider: script
4047
skip_cleanup: true
4148
# Linking to prebuild directly since it doesn't work inside a npm script.
4249
script: node_modules/prebuild/bin.js --all -u $GH_TOKEN
4350
on:
44-
condition: "$NODE_VERSION = 6"
51+
condition: "$DEPLOY = true"
4552
tags: true

appveyor.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ environment:
33
secure: 8CQgwBRBHNwfTcYdno2yTyyHOhRoSyElm2TzWOCpVh4jPA71l8bXQTxjyoSTJQaf
44
matrix:
55
- nodejs_version: "4"
6+
deploy: "true"
7+
- nodejs_version: "5"
8+
electron: "0.37.8"
9+
- nodejs_version: "6"
10+
electron: "1.1.3"
11+
- nodejs_version: "6"
12+
electron: "1.4.3"
613

714
platform:
815
- x64
@@ -13,11 +20,14 @@ build: off
1320
install:
1421
- ps: Install-Product node $env:nodejs_version $env:platform
1522
- npm install
23+
- IF DEFINED ELECTRON (npm install electron-prebuilt@%ELECTRON%)
24+
- IF DEFINED ELECTRON (npm install -g node-gyp)
25+
# We always need to rebuild for electron even for electron <= 1.1.3
26+
- IF DEFINED ELECTRON (node-gyp rebuild --runtime=electron --target=%ELECTRON% --disturl=https://atom.io/download/atom-shell --build-from-source)
27+
1628

1729
test_script:
18-
- node --version
19-
- npm --version
20-
- appveyor-retry call npm test
30+
- IF DEFINED ELECTRON (appveyor-retry call npm run test:electron) ELSE (appveyor-retry call npm test)
2131

2232
deploy_script:
23-
- IF "%nodejs_version%;%appveyor_repo_tag%"=="4;true" (npm install prebuild -g & prebuild --all -u %GITHUB_TOKEN%)
33+
- IF "%deploy%;%appveyor_repo_tag%"=="true;true" (npm install prebuild -g & prebuild --all -u %GITHUB_TOKEN%)

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"prebuild": "^4.2.2"
1515
},
1616
"devDependencies": {
17+
"electron-mocha": "^3.1.1",
1718
"mocha": "^3.1.0",
1819
"semver": "^5.3.0",
1920
"should": "^11.1.0"
@@ -23,7 +24,8 @@
2324
},
2425
"scripts": {
2526
"install": "prebuild --install",
26-
"test": "mocha --expose-gc --slow 300 --timeout 4000"
27+
"test": "mocha --expose-gc --slow 300 --timeout 4000",
28+
"test:electron": "electron-mocha --slow 300 --timeout 4000"
2729
},
2830
"keywords": [
2931
"zeromq",

test/gc.js

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
1+
if (process.versions['electron'] === undefined) {
2+
var zmq = require('..')
3+
, should = require('should');
14

2-
var zmq = require('..')
3-
, should = require('should');
5+
it('should cooperate with gc', function(done){
6+
var a = zmq.socket('dealer')
7+
, b = zmq.socket('dealer');
48

5-
it('should cooperate with gc', function(done){
6-
var a = zmq.socket('dealer')
7-
, b = zmq.socket('dealer');
9+
/**
10+
* We create 2 dealer sockets.
11+
* One of them (`a`) is not referenced explicitly after the main loop
12+
* finishes so it's a pretender for garbage collection.
13+
* This test performs gc() explicitly and then tries to send a message
14+
* to a dealer socket that could be destroyed and collected.
15+
* If a message is delivered, than everything is ok. Otherwise the guard
16+
* timeout will make the test fail.
17+
*/
18+
a.on('message', function(msg){
19+
msg.should.be.an.instanceof(Buffer);
20+
msg.toString().should.equal('hello');
21+
this.close();
22+
b.close();
23+
clearTimeout(timeout);
24+
done();
25+
});
826

9-
/**
10-
* We create 2 dealer sockets.
11-
* One of them (`a`) is not referenced explicitly after the main loop
12-
* finishes so it's a pretender for garbage collection.
13-
* This test performs gc() explicitly and then tries to send a message
14-
* to a dealer socket that could be destroyed and collected.
15-
* If a message is delivered, than everything is ok. Otherwise the guard
16-
* timeout will make the test fail.
17-
*/
18-
a.on('message', function(msg){
19-
msg.should.be.an.instanceof(Buffer);
20-
msg.toString().should.equal('hello');
21-
this.close();
22-
b.close();
23-
clearTimeout(timeout);
24-
done();
25-
});
27+
var bound = false;
2628

27-
var bound = false;
29+
a.bind('tcp://127.0.0.1:5555', function(e){
30+
if (e) {
31+
clearInterval(interval);
32+
done(e);
33+
} else {
34+
bound = true;
35+
}
36+
});
2837

29-
a.bind('tcp://127.0.0.1:5555', function(e){
30-
if (e) {
31-
clearInterval(interval);
32-
done(e);
33-
} else {
34-
bound = true;
35-
}
36-
});
38+
var interval = setInterval(function(){
39+
gc();
40+
if (bound) {
41+
clearInterval(interval);
42+
b.connect('tcp://127.0.0.1:5555');
43+
b.send('hello');
44+
}
45+
}, 100);
3746

38-
var interval = setInterval(function(){
39-
gc();
40-
if (bound) {
47+
// guard against hanging
48+
var timeout = setTimeout(function(){
4149
clearInterval(interval);
42-
b.connect('tcp://127.0.0.1:5555');
43-
b.send('hello');
44-
}
45-
}, 100);
46-
47-
// guard against hanging
48-
var timeout = setTimeout(function(){
49-
clearInterval(interval);
50-
done(new Error('timeout of 5000ms exceeded (bound: ' + bound + ')'));
51-
}, 15000);
52-
});
50+
done(new Error('timeout of 5000ms exceeded (bound: ' + bound + ')'));
51+
}, 15000);
52+
});
53+
} else {
54+
console.log('Running in electron: GC test skipped.');
55+
}

test/mocha.opts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)