|
10 | 10 | const portfinder = require('../lib/portfinder'), |
11 | 11 | helper = require('./helper'); |
12 | 12 |
|
13 | | -portfinder.basePort = 32768; |
| 13 | +const basePort = 32768; |
| 14 | +portfinder.basePort = basePort; |
14 | 15 |
|
15 | 16 | describe('with 5 existing servers', function () { |
16 | 17 | const servers = []; |
@@ -152,32 +153,41 @@ describe('with no existing servers', function () { |
152 | 153 | }); |
153 | 154 | }); |
154 | 155 |
|
155 | | -describe.each([ |
156 | | - ['getPort()', false, portfinder.getPort], |
157 | | - ['getPort()', true, portfinder.getPort], |
158 | | - ['getPortPromise()', true, portfinder.getPortPromise], |
159 | | -])(`the %s method (promise: %p)`, function (name, isPromise, method) { |
160 | | - test('with startPort less than or equal to 80', function (done) { |
161 | | - if (isPromise) { |
162 | | - method({ startPort: 80 }) |
163 | | - .then(function (port) { |
164 | | - expect(port).toBeGreaterThanOrEqual(80); |
| 156 | + |
| 157 | +describe('with startPort provided', function () { |
| 158 | + beforeAll(function () { |
| 159 | + portfinder.basePort = 8000; |
| 160 | + }); |
| 161 | + afterAll(function () { |
| 162 | + portfinder.basePort = basePort; |
| 163 | + }); |
| 164 | + describe.each([ |
| 165 | + ['getPort()', false, portfinder.getPort], |
| 166 | + ['getPort()', true, portfinder.getPort], |
| 167 | + ['getPortPromise()', true, portfinder.getPortPromise], |
| 168 | + ])(`the %s method (promise: %p)`, function (name, isPromise, method) { |
| 169 | + test('with startPort less than or equal to 9050', function (done) { |
| 170 | + if (isPromise) { |
| 171 | + method({ startPort: 9050 }) |
| 172 | + .then(function (port) { |
| 173 | + expect(port).toBeGreaterThanOrEqual(9050); |
| 174 | + done(); |
| 175 | + }) |
| 176 | + .catch(function (err) { |
| 177 | + done(err); |
| 178 | + }); |
| 179 | + } else { |
| 180 | + method({ startPort: 9050 }, function (err, port) { |
| 181 | + if (err) { |
| 182 | + done(err); |
| 183 | + return; |
| 184 | + } |
| 185 | + expect(err).toBeNull(); |
| 186 | + expect(port).toBeGreaterThanOrEqual(9050); |
165 | 187 | done(); |
166 | | - }) |
167 | | - .catch(function (err) { |
168 | | - done(err); |
169 | 188 | }); |
170 | | - } else { |
171 | | - method({ startPort: 80 }, function (err, port) { |
172 | | - if (err) { |
173 | | - done(err); |
174 | | - return; |
175 | | - } |
176 | | - expect(err).toBeNull(); |
177 | | - expect(port).toBeGreaterThanOrEqual(80); |
178 | | - done(); |
179 | | - }); |
180 | | - } |
| 189 | + } |
| 190 | + }); |
181 | 191 | }); |
182 | 192 | }); |
183 | 193 |
|
|
0 commit comments