From d4ca6fbb6f3f7408595de0de836c416fa45f1ce0 Mon Sep 17 00:00:00 2001 From: Richard Garnier Date: Sat, 4 Jun 2016 16:22:20 +0900 Subject: [PATCH] test fixed for all versions --- test/cli.js | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/test/cli.js b/test/cli.js index 8674af2a..c5bc282b 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,22 +1,39 @@ -var test = require('tap').test -var exec = require('child_process').exec +var test = require('tap').test; +var execSync = require('child_process').execSync +var exec = require('child_process').exec; test('the command line using pipes or arguments produces the same output', function (t) { - t.plan(6); - var bin = 'node ./bin/semver '; - [[bin+'-i 1.0.0', 'echo 1.0.0 | '+bin+'-i'], - [bin+'-i major 1.0.0', 'echo 1.0.0 | '+bin+'-i major'], - [bin+'-i prerelease 1.0.0', 'echo 1.0.0 | '+bin+'-i prerelease'], - [bin+'-i preminor 1.0.0', 'echo 1.0.0 | '+bin+'-i preminor'], - [bin+'-i prepatch --preid alpha 1.0.0', 'echo 1.0.0 | '+bin+'-i prepatch --preid alpha'], - [bin+'-r \\>1.0.0 0.8.0 1.1.1', 'echo 0.8.0 1.1.1 | '+bin+'-r \\>1.0.0'] - ].forEach(function(tab) { - exec(tab[0], function(error, stdout, stderr) { - var resCli = stdout + stderr; - exec(tab[1], function(error, stdout, stderr) { - var resPipe = stdout + stderr; - t.assert(resCli === resPipe); + if (execSync === undefined) { + t.plan(6); + var bin = 'node ./bin/semver '; + [[bin+'-i 1.0.0', 'echo 1.0.0 | '+bin+'-i'], + [bin+'-i major 1.0.0', 'echo 1.0.0 | '+bin+'-i major'], + [bin+'-i prerelease 1.0.0', 'echo 1.0.0 | '+bin+'-i prerelease'], + [bin+'-i preminor 1.0.0', 'echo 1.0.0 | '+bin+'-i preminor'], + [bin+'-i prepatch --preid alpha 1.0.0', 'echo 1.0.0 | '+bin+'-i prepatch --preid alpha'], + [bin+'-r \\>1.0.0 0.8.0 1.1.1', 'echo 0.8.0 1.1.1 | '+bin+'-r \\>1.0.0'] + ].forEach(function(tab) { + exec(tab[0], function(error, stdout, stderr) { + var resCli = stdout + stderr; + exec(tab[1], function(error, stdout, stderr) { + var resPipe = stdout + stderr; + t.assert(resCli === resPipe); + }); }); }); - }); + } else { + var bin = 'node ./bin/semver '; + [[bin+'-i 1.0.0', 'echo 1.0.0 | '+bin+'-i'], + [bin+'-i major 1.0.0', 'echo 1.0.0 | '+bin+'-i major'], + [bin+'-i prerelease 1.0.0', 'echo 1.0.0 | '+bin+'-i prerelease'], + [bin+'-i preminor 1.0.0', 'echo 1.0.0 | '+bin+'-i preminor'], + [bin+'-i prepatch --preid alpha 1.0.0', 'echo 1.0.0 | '+bin+'-i prepatch --preid alpha'], + [bin+'-r \\>1.0.0 0.8.0 1.1.1', 'echo 0.8.0 1.1.1 | '+bin+'-r \\>1.0.0'] + ].forEach(function(tab) { + var resCli = execSync(tab[0]); + var resPipe = execSync(tab[1]); + t.assert(resCli.equals(resPipe)); + }); + t.end(); + } })