From d641b2b4bb6175b985163eb91cbb25fec6c5ab4d Mon Sep 17 00:00:00 2001 From: Lukas Geiger Date: Wed, 6 Sep 2017 00:15:58 +0200 Subject: [PATCH] Add tests for getNextTarget function --- index.js | 6 ++++-- test/index.js | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 30f45ef..7619b2e 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,8 @@ var semver = require('semver') -function getNextTarget (runtime) { - var latest = allTargets.filter(function (t) { return t.runtime === runtime }).slice(-1)[0] +function getNextTarget (runtime, targets) { + if (targets == null) targets = allTargets + var latest = targets.filter(function (t) { return t.runtime === runtime }).slice(-1)[0] var increment = runtime === 'electron' ? 'minor' : 'major' return semver.inc(latest.target, increment) } @@ -90,3 +91,4 @@ exports.deprecatedTargets = deprecatedTargets exports.supportedTargets = supportedTargets exports.futureTargets = futureTargets exports.allTargets = allTargets +exports._getNextTarget = getNextTarget diff --git a/test/index.js b/test/index.js index db5b5f3..846705f 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,19 @@ var test = require('tape') var getAbi = require('../index').getAbi var getTarget = require('../index').getTarget +var getNextTarget = require('../index')._getNextTarget + +test('getNextTarget gets the next unsopported target', function (t) { + var mockTargets = [ + {runtime: 'node', target: '7.0.0', abi: '51', lts: false}, + {runtime: 'node', target: '8.0.0', abi: '57', lts: false}, + {runtime: 'electron', target: '0.36.0', abi: '47', lts: false}, + {runtime: 'electron', target: '1.1.0', abi: '48', lts: false} + ] + t.equal(getNextTarget('node', mockTargets), '9.0.0') + t.equal(getNextTarget('electron', mockTargets), '1.2.0') + t.end() +}) test('getTarget calculates correct Node target', function (t) { t.equal(getTarget(undefined), process.versions.node) @@ -27,6 +40,7 @@ test('getAbi calculates correct Node ABI', function (t) { t.equal(getAbi(undefined), process.versions.modules) t.equal(getAbi(null), process.versions.modules) t.throws(function () { getAbi('a.b.c') }) + t.throws(function () { getAbi(getNextTarget('node')) }) t.equal(getAbi('7.2.0'), '51') t.equal(getAbi('7.0.0'), '51') t.equal(getAbi('6.9.9'), '48') @@ -61,7 +75,7 @@ test('getAbi calculates correct Node ABI', function (t) { test('getAbi calculates correct Electron ABI', function (t) { t.throws(function () { getAbi(undefined, 'electron') }) - t.throws(function () { getAbi('7.2.0', 'electron') }) + t.throws(function () { getAbi(getNextTarget('electron'), 'electron') }) t.equal(getAbi('1.4.0', 'electron'), '50') t.equal(getAbi('1.3.0', 'electron'), '49') t.equal(getAbi('1.2.0', 'electron'), '48')