|
| 1 | +/** |
| 2 | + * @author Toru Nagashima |
| 3 | + * @copyright 2016 Toru Nagashima. All rights reserved. |
| 4 | + * See LICENSE file in root directory for full license. |
| 5 | + */ |
| 6 | +"use strict" |
| 7 | + |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | +// Requirements |
| 10 | +//------------------------------------------------------------------------------ |
| 11 | + |
| 12 | +var assert = require("assert") |
| 13 | +var semver = require("semver") |
| 14 | +var api = require("./lib/api") |
| 15 | + |
| 16 | +//------------------------------------------------------------------------------ |
| 17 | +// Helpers |
| 18 | +//------------------------------------------------------------------------------ |
| 19 | + |
| 20 | +var version = process.versions.node |
| 21 | +var run = api.run |
| 22 | +var runSync = api.runSync |
| 23 | + |
| 24 | +//------------------------------------------------------------------------------ |
| 25 | +// Test |
| 26 | +//------------------------------------------------------------------------------ |
| 27 | + |
| 28 | +describe("Under Node.js v" + version + ",", function() { |
| 29 | + var ranges = [ |
| 30 | + ">=0.10", |
| 31 | + ">=0.12", |
| 32 | + ">=4", |
| 33 | + ">=6", |
| 34 | + "<0.10", |
| 35 | + "<0.12", |
| 36 | + "<4", |
| 37 | + "<6", |
| 38 | + "^0.10", |
| 39 | + "^0.12", |
| 40 | + "^4", |
| 41 | + "^6", |
| 42 | + "^0.10 || ^0.12 || ^4 || ^6", |
| 43 | + ] |
| 44 | + |
| 45 | + ranges.forEach(function(range) { |
| 46 | + describe("if '" + range + "' is given", function() { |
| 47 | + describe("with good command,", function() { |
| 48 | + describe("async version", function() { |
| 49 | + var result = null |
| 50 | + |
| 51 | + before(function() { |
| 52 | + return run(range).then(function(ret) { |
| 53 | + result = ret |
| 54 | + }) |
| 55 | + }) |
| 56 | + |
| 57 | + if (semver.satisfies(version, range)) { |
| 58 | + it("should exit with zero", function() { |
| 59 | + assert(result.exitCode === 0) |
| 60 | + }) |
| 61 | + it("should run the specified command", function() { |
| 62 | + assert(result.stdout === "OK") |
| 63 | + }) |
| 64 | + } |
| 65 | + else { |
| 66 | + it("should NOT run the specified command", function() { |
| 67 | + assert(result == null) |
| 68 | + }) |
| 69 | + } |
| 70 | + }) |
| 71 | + |
| 72 | + describe("sync version", function() { |
| 73 | + var result = null |
| 74 | + |
| 75 | + before(function() { |
| 76 | + result = runSync(range) |
| 77 | + }) |
| 78 | + |
| 79 | + if (semver.satisfies(version, range)) { |
| 80 | + it("should exit with zero", function() { |
| 81 | + assert(result.exitCode === 0) |
| 82 | + }) |
| 83 | + it("should run the specified command", function() { |
| 84 | + assert(result.stdout === "OK") |
| 85 | + }) |
| 86 | + } |
| 87 | + else { |
| 88 | + it("should NOT run the specified command", function() { |
| 89 | + assert(result == null) |
| 90 | + }) |
| 91 | + } |
| 92 | + }) |
| 93 | + }) |
| 94 | + |
| 95 | + describe("with bad command,", function() { |
| 96 | + describe("async version", function() { |
| 97 | + var result = null |
| 98 | + |
| 99 | + before(function() { |
| 100 | + return run(range, {fail: true}).then(function(ret) { |
| 101 | + result = ret |
| 102 | + }) |
| 103 | + }) |
| 104 | + |
| 105 | + if (semver.satisfies(version, range)) { |
| 106 | + it("should exit with a non-zero code", function() { |
| 107 | + assert(result.exitCode === 1) |
| 108 | + }) |
| 109 | + it("should run the specified command", function() { |
| 110 | + assert(result.stdout === "NG") |
| 111 | + }) |
| 112 | + } |
| 113 | + else { |
| 114 | + it("should NOT run the specified command", function() { |
| 115 | + assert(result == null) |
| 116 | + }) |
| 117 | + } |
| 118 | + }) |
| 119 | + |
| 120 | + describe("sync version", function() { |
| 121 | + var result = null |
| 122 | + |
| 123 | + before(function() { |
| 124 | + result = runSync(range, {fail: true}) |
| 125 | + }) |
| 126 | + |
| 127 | + if (semver.satisfies(version, range)) { |
| 128 | + it("should exit with a non-zero code", function() { |
| 129 | + assert(result.exitCode === 1) |
| 130 | + }) |
| 131 | + it("should run the specified command", function() { |
| 132 | + assert(result.stdout === "NG") |
| 133 | + }) |
| 134 | + } |
| 135 | + else { |
| 136 | + it("should NOT run the specified command", function() { |
| 137 | + assert(result == null) |
| 138 | + }) |
| 139 | + } |
| 140 | + }) |
| 141 | + }) |
| 142 | + }) |
| 143 | + }) |
| 144 | +}) |
0 commit comments