-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a proof of concept intended to explore what it would look like to use `node:test` and `node:assert` for testing. For the most part the assertions themselves translated nicely. As part of the refactor, large fixtures were moved out of some test files and into `./test/fixtures`. The parts that are probably not ready are: - Code coverage. This flag is still experimental in Node.js. There is also no way to set a coverage level requirement, nor is there coverage mapping. This is the only repo left that the npm cli team manages which still uses coverage mapping. Whether or not we want to keep coverage mapping is a discussion that could take place. - Timeout. There is a test that assumes the timeout is not Infinity. This is Node.js's default, and can only apparently be changed from tests that are invoked from `run()`. - Test runner. This still uses `tap` for running the tests. Running the tests purely from node would require having a centralized runner, or refactoring all the tests to invoke `run()` and set a timeout. It would also require solving the coverage problem. - Snapshots. There is no built-in snapshot functionality in the Node.js test suite. There was only one test that really could arguably benefit from it: the help output. The rest really were better suited for explicit checks. Conclusion: `node:test` is not feature complete, and we can not cut over to it fully. This PR may be ok to land as-is, since `node:test` returns tap-compatible results. Whether or not we want to land it like this is a discussion to be had. At the very least this demonstrates the amount of work needed to translate tests from `tap` to `node:test`
- Loading branch information
Showing
67 changed files
with
1,665 additions
and
2,058 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,57 @@ | ||
const { test } = require('tap') | ||
const t = require('node:test') | ||
const a = require('node:assert') | ||
const Comparator = require('../../classes/comparator') | ||
const comparatorIntersection = require('../fixtures/comparator-intersection.js') | ||
|
||
test('comparator testing', t => { | ||
t.test('comparator testing', t => { | ||
const c = new Comparator('>=1.2.3') | ||
t.ok(c.test('1.2.4')) | ||
a.ok(c.test('1.2.4')) | ||
const c2 = new Comparator(c) | ||
t.ok(c2.test('1.2.4')) | ||
a.ok(c2.test('1.2.4')) | ||
const c3 = new Comparator(c, true) | ||
t.ok(c3.test('1.2.4')) | ||
a.ok(c3.test('1.2.4')) | ||
// test an invalid version, should not throw | ||
const c4 = new Comparator(c) | ||
t.notOk(c4.test('not a version string')) | ||
t.end() | ||
a.ok(!c4.test('not a version string')) | ||
}) | ||
|
||
test('tostrings', (t) => { | ||
t.equal(new Comparator('>= v1.2.3').toString(), '>=1.2.3') | ||
t.end() | ||
t.test('tostrings', (t) => { | ||
a.equal(new Comparator('>= v1.2.3').toString(), '>=1.2.3') | ||
}) | ||
|
||
test('intersect comparators', (t) => { | ||
t.plan(comparatorIntersection.length) | ||
comparatorIntersection.forEach(([c0, c1, expect, includePrerelease]) => | ||
t.test(`${c0} ${c1} ${expect}`, t => { | ||
t.test('intersect comparators', async (t) => { | ||
for (const [c0, c1, expect, includePrerelease] of comparatorIntersection) { | ||
await t.test(`${c0} ${c1} ${expect}`, t => { | ||
const comp0 = new Comparator(c0) | ||
const comp1 = new Comparator(c1) | ||
|
||
t.equal(comp0.intersects(comp1, { includePrerelease }), expect, | ||
a.equal(comp0.intersects(comp1, { includePrerelease }), expect, | ||
`${c0} intersects ${c1}`) | ||
|
||
t.equal(comp1.intersects(comp0, { includePrerelease }), expect, | ||
a.equal(comp1.intersects(comp0, { includePrerelease }), expect, | ||
`${c1} intersects ${c0}`) | ||
t.end() | ||
})) | ||
}) | ||
} | ||
}) | ||
|
||
test('intersect demands another comparator', t => { | ||
t.test('intersect demands another comparator', t => { | ||
const c = new Comparator('>=1.2.3') | ||
t.throws(() => c.intersects(), new TypeError('a Comparator is required')) | ||
t.end() | ||
a.throws(() => c.intersects(), new TypeError('a Comparator is required')) | ||
}) | ||
|
||
test('ANY matches anything', t => { | ||
t.test('ANY matches anything', t => { | ||
const c = new Comparator('') | ||
t.ok(c.test('1.2.3'), 'ANY matches anything') | ||
a.ok(c.test('1.2.3'), 'ANY matches anything') | ||
const c1 = new Comparator('>=1.2.3') | ||
const ANY = Comparator.ANY | ||
t.ok(c1.test(ANY), 'anything matches ANY') | ||
t.end() | ||
a.ok(c1.test(ANY), 'anything matches ANY') | ||
}) | ||
|
||
test('invalid comparator parse throws', t => { | ||
t.throws(() => new Comparator('foo bar baz'), | ||
t.test('invalid comparator parse throws', t => { | ||
a.throws(() => new Comparator('foo bar baz'), | ||
new TypeError('Invalid comparator: foo bar baz')) | ||
t.end() | ||
}) | ||
|
||
test('= is ignored', t => { | ||
t.match(new Comparator('=1.2.3'), new Comparator('1.2.3')) | ||
t.end() | ||
t.test('= is ignored', t => { | ||
a.deepEqual(new Comparator('=1.2.3'), new Comparator('1.2.3')) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
const t = require('tap') | ||
t.same(require('../../classes'), { | ||
SemVer: require('../../classes/semver'), | ||
Range: require('../../classes/range'), | ||
Comparator: require('../../classes/comparator'), | ||
}, 'export all classes at semver/classes') | ||
const t = require('node:test') | ||
const a = require('node:assert') | ||
t.test('classes', (t) => { | ||
a.deepEqual(require('../../classes'), { | ||
SemVer: require('../../classes/semver'), | ||
Range: require('../../classes/range'), | ||
Comparator: require('../../classes/comparator'), | ||
}, 'export all classes at semver/classes') | ||
}) |
Oops, something went wrong.