Skip to content

Commit cad9fd3

Browse files
committed
test_runner: update test + update docs
1 parent ec06553 commit cad9fd3

File tree

3 files changed

+32
-47
lines changed

3 files changed

+32
-47
lines changed

doc/api/test.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,11 @@ changes:
333333
properties are supported:
334334
* `concurrency` {number|boolean} If a number is provided,
335335
then that many tests would run in parallel.
336-
If truthy, on top level, it would run (number of cpu cores - 1)
337-
tests in parallel.
336+
If truthy, when running in `--test` mode, it would run
337+
(number of cpu cores - 1) tests in parallel.
338338
For subtests, it will be infinity tests in parallel.
339-
If falsy, on top level & subtest level it would only run one test at a time.
339+
If falsy, when running in `--test` mode & subtest level
340+
it would only run one test at a time.
340341
If unspecified, subtests inherit this value from their parent.
341342
**Default:** `1`.
342343
* `only` {boolean} If truthy, and the test context is configured to run

test/message/test_runner_describe_it.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -339,47 +339,3 @@ describe('timeouts', () => {
339339
setTimeout(done, 10);
340340
});
341341
});
342-
343-
describe('Concurrency option (boolean) = true ', { concurrency: true }, () => {
344-
const suiteStartDateTime = new Date().getTime();
345-
const extraBufferTime = 10;
346-
it('should be over by 3 seconds from suite start', async () => {
347-
const duration = 3000;
348-
const expectedEndDateTime = suiteStartDateTime + duration + extraBufferTime;
349-
await new Promise((resolve, reject) => {
350-
setTimeout(resolve, duration);
351-
});
352-
assert.strictEqual(expectedEndDateTime > new Date().getTime(), true);
353-
});
354-
it('should be over by 1 second from suite start', async () => {
355-
const duration = 1000;
356-
const expectedEndDateTime = suiteStartDateTime + duration + extraBufferTime;
357-
await new Promise((resolve, reject) => {
358-
setTimeout(resolve, duration);
359-
});
360-
assert.strictEqual(expectedEndDateTime > new Date().getTime(), true);
361-
});
362-
});
363-
364-
describe('Concurrency option (boolean) = false ', { concurrency: false }, () => {
365-
const suiteStartDateTime = new Date().getTime();
366-
const extraBufferTime = 10;
367-
it('should be over by 3 seconds from suite start', async () => {
368-
const duration = 3000;
369-
const expectedEndDateTime = suiteStartDateTime + duration + extraBufferTime;
370-
await new Promise((resolve, reject) => {
371-
setTimeout(resolve, duration);
372-
});
373-
assert.strictEqual(expectedEndDateTime > new Date().getTime(), true);
374-
});
375-
it('should be over by 4 seconds from suite start', async () => {
376-
const duration = 1000;
377-
const prevTestDuration = 3000;
378-
const expectedEndDateTime =
379-
suiteStartDateTime + duration + extraBufferTime + prevTestDuration;
380-
await new Promise((resolve, reject) => {
381-
setTimeout(resolve, duration);
382-
});
383-
assert.strictEqual(expectedEndDateTime > new Date().getTime(), true);
384-
});
385-
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
require('../common');
3+
const { describe, it } = require('node:test');
4+
const assert = require('assert');
5+
6+
describe('Concurrency option (boolean) = true ', { concurrency: true }, () => {
7+
let isFirstTestOver = false;
8+
it('should end after 1000ms', () => new Promise((resolve) => {
9+
setTimeout(() => { resolve(); isFirstTestOver = true; }, 1000);
10+
}));
11+
it('should start before the previous test ends', () => {
12+
assert.strictEqual(isFirstTestOver, false);
13+
});
14+
});
15+
16+
describe(
17+
'Concurrency option (boolean) = false ',
18+
{ concurrency: false },
19+
() => {
20+
let isFirstTestOver = false;
21+
it('should end after 1000ms', () => new Promise((resolve) => {
22+
setTimeout(() => { resolve(); isFirstTestOver = true; }, 1000);
23+
}));
24+
it('should start after the previous test ends', () => {
25+
assert.strictEqual(isFirstTestOver, true);
26+
});
27+
}
28+
);

0 commit comments

Comments
 (0)