Skip to content

Commit

Permalink
test refactors, test multi-os on travis
Browse files Browse the repository at this point in the history
Also includes various workarounds to make tests work on windows
travis.
  • Loading branch information
silverwind committed Feb 15, 2019
1 parent f7903f5 commit 4e66672
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
root: true
extends: eslint-config-silverwind

# workaround for window travis
rules:
linebreak-style: [0]
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
language: node_js
node_js:
- node
- lts/*
- 8
- 10
os:
- linux
- osx
- windows
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "silverwind/default-gateway",
"license": "BSD-2-Clause",
"scripts": {
"test": "make test"
"test": "eslint *.js && node --pending-deprecation --trace-deprecation --throw-deprecation --trace-warnings test.js"
},
"engines": {
"node": ">=6"
Expand Down
37 changes: 16 additions & 21 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
"use strict";

// travis VMs don't have IPs on their interfaces
// https://docs.travis-ci.com/user/ci-environment/#Networking
if (process.env.CI) return;
// IPv6 tests are skipped because Travis VMs do not support IPv6

const assert = require("assert");
const net = require("net");
const defaultGateway = require(".");

Promise.all([
defaultGateway.v4(),
defaultGateway.v6(),
]).then(results => {
assert(net.isIPv4(results[0].gateway));
assert(net.isIPv6(results[1].gateway));
}).catch(err => {
console.error(err.stack);
process.exit(1);
});
(async () => {
const async4 = await defaultGateway.v4();
assert(net.isIPv4((async4).gateway));

if (defaultGateway.v4.sync) {
const result = defaultGateway.v4.sync();
assert(net.isIPv4(result.gateway));
}
if (!process.env.CI) {
const async6 = await defaultGateway.v6();
assert(net.isIPv6(async6.gateway));
}

if (defaultGateway.v6.sync) {
const result = defaultGateway.v6.sync();
assert(net.isIPv6(result.gateway));
}
const sync4 = defaultGateway.v4.sync();
assert(net.isIPv4(sync4.gateway));

if (!process.env.CI) {
const sync6 = defaultGateway.v6.sync();
assert(net.isIPv6(sync6.gateway));
}
})();

0 comments on commit 4e66672

Please sign in to comment.