-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(strict): use standard
assert
for Node.js legacy versions (#761)
* feat(strict): use `assert` for Node.js legacy versions * ci: add tests * ci: improve imports * ci: bun is always strict * docs: add `strict` legacy behavior
- Loading branch information
1 parent
130dadb
commit d4b7b64
Showing
12 changed files
with
109 additions
and
81 deletions.
There are no files selected for viewing
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,4 +1,10 @@ | ||
import nodeAssert from 'node:assert/strict'; | ||
import { createAssert } from '../../builders/assert.js'; | ||
import { nodeVersion } from '../../parsers/get-runtime.js'; | ||
|
||
/* c8 ignore next 4 */ // Platform version | ||
const nodeAssert = | ||
!nodeVersion || nodeVersion >= 16 | ||
? require('node:assert/strict') | ||
: require('node:assert'); | ||
|
||
export const strict = createAssert(nodeAssert); |
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
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
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,40 +1,41 @@ | ||
import { test } from '../../src/modules/helpers/test.js'; | ||
import { getRuntime } from '../../src/parsers/get-runtime.js'; | ||
import { skip } from '../../src/modules/helpers/skip.js'; | ||
import { nodeVersion } from '../../src/parsers/get-runtime.js'; | ||
|
||
if (nodeVersion && nodeVersion < 16) { | ||
skip('Strict method is available from Node.js 16'); | ||
} | ||
if (getRuntime() === 'deno') skip(); | ||
|
||
import * as index from '../../src/modules/index.js'; | ||
test(async () => { | ||
const index = await import('../../src/modules/index.js'); | ||
|
||
index.test('Import Suite', () => { | ||
index.assert.ok(index.poku, 'Importing poku method'); | ||
index.assert.ok(index.assert, 'Importing assert method'); | ||
index.assert.ok(index.strict, 'Importing strict method'); | ||
index.test('Import Suite', () => { | ||
index.assert.ok(index.poku, 'Importing poku method'); | ||
index.assert.ok(index.assert, 'Importing assert method'); | ||
index.assert.ok(index.strict, 'Importing strict method'); | ||
|
||
index.assert.ok(index.defineConfig, 'Importing defineConfig method'); | ||
index.assert.ok(index.envFile, 'Importing envFile method'); | ||
index.assert.ok(index.startService, 'Importing startService method'); | ||
index.assert.ok(index.startScript, 'Importing startScript method'); | ||
index.assert.ok(index.docker, 'Importing docker method'); | ||
index.assert.ok(index.getPIDs, 'Importing getPIDs helper'); | ||
index.assert.ok(index.kill, 'Importing kill helper'); | ||
index.assert.ok(index.describe, 'Importing describe helper'); | ||
index.assert.ok(index.beforeEach, 'Importing beforeEach helper'); | ||
index.assert.ok(index.afterEach, 'Importing afterEach helper'); | ||
index.assert.ok(index.log, 'Importing log helper'); | ||
index.assert.ok(index.test, 'Importing test helper'); | ||
index.assert.ok(index.skip, 'Importing skip helper'); | ||
index.assert.ok(index.sleep, 'Importing sleep helper'); | ||
index.assert.ok( | ||
index.waitForExpectedResult, | ||
'Importing waitForExpectedResult helper' | ||
); | ||
index.assert.ok(index.waitForPort, 'Importing waitForPort helper'); | ||
index.assert.ok(index.exit, 'Importing exit helper'); | ||
index.assert.ok(index.listFiles, 'Importing listFiles helper'); | ||
index.assert.ok( | ||
typeof index.version === 'string', | ||
'Importing listFiles helper' | ||
); | ||
index.assert.ok(index.defineConfig, 'Importing defineConfig method'); | ||
index.assert.ok(index.envFile, 'Importing envFile method'); | ||
index.assert.ok(index.startService, 'Importing startService method'); | ||
index.assert.ok(index.startScript, 'Importing startScript method'); | ||
index.assert.ok(index.docker, 'Importing docker method'); | ||
index.assert.ok(index.getPIDs, 'Importing getPIDs helper'); | ||
index.assert.ok(index.kill, 'Importing kill helper'); | ||
index.assert.ok(index.describe, 'Importing describe helper'); | ||
index.assert.ok(index.beforeEach, 'Importing beforeEach helper'); | ||
index.assert.ok(index.afterEach, 'Importing afterEach helper'); | ||
index.assert.ok(index.log, 'Importing log helper'); | ||
index.assert.ok(index.test, 'Importing test helper'); | ||
index.assert.ok(index.skip, 'Importing skip helper'); | ||
index.assert.ok(index.sleep, 'Importing sleep helper'); | ||
index.assert.ok( | ||
index.waitForExpectedResult, | ||
'Importing waitForExpectedResult helper' | ||
); | ||
index.assert.ok(index.waitForPort, 'Importing waitForPort helper'); | ||
index.assert.ok(index.exit, 'Importing exit helper'); | ||
index.assert.ok(index.listFiles, 'Importing listFiles helper'); | ||
index.assert.ok( | ||
typeof index.version === 'string', | ||
'Importing listFiles helper' | ||
); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { skip } from '../../../src/modules/helpers/skip.js'; | ||
import { getRuntime, nodeVersion } from '../../../src/parsers/get-runtime.js'; | ||
import { describe } from '../../../src/modules/helpers/describe.js'; | ||
import { assert } from '../../../src/modules/essentials/assert.js'; | ||
|
||
if ((nodeVersion && nodeVersion < 16) || getRuntime() !== 'node') { | ||
skip('Strict method is available from Node.js 16'); | ||
} | ||
|
||
describe('Ensure strict', async () => { | ||
const { strict } = await import('../../../src/modules/essentials/strict.js'); | ||
|
||
const actual = Object.create(null); | ||
const expected = { name: 'John' }; | ||
|
||
actual.name = 'John'; | ||
|
||
assert.deepEqual(actual, expected); | ||
strict.notDeepEqual(actual, expected); | ||
}); |
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,15 +1,16 @@ | ||
import { nodeVersion } from '../../src/parsers/get-runtime.js'; | ||
import { test } from '../../src/modules/helpers/test.js'; | ||
import { getRuntime } from '../../src/parsers/get-runtime.js'; | ||
import { skip } from '../../src/modules/helpers/skip.js'; | ||
|
||
if (nodeVersion && nodeVersion < 16) { | ||
skip(); | ||
} | ||
if (getRuntime() === 'deno') skip(); | ||
|
||
import { assert } from '../../src/modules/essentials/assert.js'; | ||
import { defineConfig } from '../../src/modules/index.js'; | ||
test(async () => { | ||
const { assert } = await import('../../src/modules/essentials/assert.js'); | ||
const { defineConfig } = await import('../../src/modules/index.js'); | ||
|
||
assert.deepStrictEqual( | ||
defineConfig({ debug: true }), | ||
{ debug: true }, | ||
'Reflect configs' | ||
); | ||
assert.deepStrictEqual( | ||
defineConfig({ debug: true }), | ||
{ debug: true }, | ||
'Reflect configs' | ||
); | ||
}); |
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