Skip to content

Commit

Permalink
test_runner: update test + update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
98lenvi committed Jul 19, 2022
1 parent ec06553 commit cad9fd3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 47 deletions.
7 changes: 4 additions & 3 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,11 @@ changes:
properties are supported:
* `concurrency` {number|boolean} If a number is provided,
then that many tests would run in parallel.
If truthy, on top level, it would run (number of cpu cores - 1)
tests in parallel.
If truthy, when running in `--test` mode, it would run
(number of cpu cores - 1) tests in parallel.
For subtests, it will be infinity tests in parallel.
If falsy, on top level & subtest level it would only run one test at a time.
If falsy, when running in `--test` mode & subtest level
it would only run one test at a time.
If unspecified, subtests inherit this value from their parent.
**Default:** `1`.
* `only` {boolean} If truthy, and the test context is configured to run
Expand Down
44 changes: 0 additions & 44 deletions test/message/test_runner_describe_it.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,47 +339,3 @@ describe('timeouts', () => {
setTimeout(done, 10);
});
});

describe('Concurrency option (boolean) = true ', { concurrency: true }, () => {
const suiteStartDateTime = new Date().getTime();
const extraBufferTime = 10;
it('should be over by 3 seconds from suite start', async () => {
const duration = 3000;
const expectedEndDateTime = suiteStartDateTime + duration + extraBufferTime;
await new Promise((resolve, reject) => {
setTimeout(resolve, duration);
});
assert.strictEqual(expectedEndDateTime > new Date().getTime(), true);
});
it('should be over by 1 second from suite start', async () => {
const duration = 1000;
const expectedEndDateTime = suiteStartDateTime + duration + extraBufferTime;
await new Promise((resolve, reject) => {
setTimeout(resolve, duration);
});
assert.strictEqual(expectedEndDateTime > new Date().getTime(), true);
});
});

describe('Concurrency option (boolean) = false ', { concurrency: false }, () => {
const suiteStartDateTime = new Date().getTime();
const extraBufferTime = 10;
it('should be over by 3 seconds from suite start', async () => {
const duration = 3000;
const expectedEndDateTime = suiteStartDateTime + duration + extraBufferTime;
await new Promise((resolve, reject) => {
setTimeout(resolve, duration);
});
assert.strictEqual(expectedEndDateTime > new Date().getTime(), true);
});
it('should be over by 4 seconds from suite start', async () => {
const duration = 1000;
const prevTestDuration = 3000;
const expectedEndDateTime =
suiteStartDateTime + duration + extraBufferTime + prevTestDuration;
await new Promise((resolve, reject) => {
setTimeout(resolve, duration);
});
assert.strictEqual(expectedEndDateTime > new Date().getTime(), true);
});
});
28 changes: 28 additions & 0 deletions test/parallel/test-runner-concurrency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
require('../common');
const { describe, it } = require('node:test');
const assert = require('assert');

describe('Concurrency option (boolean) = true ', { concurrency: true }, () => {
let isFirstTestOver = false;
it('should end after 1000ms', () => new Promise((resolve) => {
setTimeout(() => { resolve(); isFirstTestOver = true; }, 1000);
}));
it('should start before the previous test ends', () => {
assert.strictEqual(isFirstTestOver, false);
});
});

describe(
'Concurrency option (boolean) = false ',
{ concurrency: false },
() => {
let isFirstTestOver = false;
it('should end after 1000ms', () => new Promise((resolve) => {
setTimeout(() => { resolve(); isFirstTestOver = true; }, 1000);
}));
it('should start after the previous test ends', () => {
assert.strictEqual(isFirstTestOver, true);
});
}
);

0 comments on commit cad9fd3

Please sign in to comment.