-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(huston)!: use node test runners
Signed-off-by: mateonunez <mateonunez95@gmail.com>
- Loading branch information
1 parent
7877ec7
commit 06760cc
Showing
7 changed files
with
134 additions
and
62 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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const test = require('node:test') | ||
const assert = require('node:assert') | ||
const { removeNulls, removeReservedWords } = require('./../lib/normalizers.js') | ||
|
||
test.describe('normalizers', () => { | ||
test('should remove nulls', () => { | ||
const object = { a: null, b: 1 } | ||
const normalized = removeNulls(object) | ||
assert.deepStrictEqual(normalized, { a: '', b: 1 }) | ||
}) | ||
|
||
test('should remove reserved words', () => { | ||
const object = { id: 1, a: 2 } | ||
const normalized = removeReservedWords(object) | ||
assert.deepStrictEqual(normalized, { a: 2 }) | ||
}) | ||
|
||
test('should remove nulls in arrays', () => { | ||
const array = [null, 1, { a: null, b: 2 }, [null, 3]] | ||
const normalized = removeNulls(array) | ||
assert.deepStrictEqual(normalized, ['', 1, { a: '', b: 2 }, ['', 3]]) | ||
}) | ||
|
||
test('should remove reserved words in arrays', () => { | ||
const arr = [{ id: 1, a: 2 }, [{ id: 3, b: 4 }]] | ||
const normalized = removeReservedWords(arr) | ||
assert.deepStrictEqual(normalized, [{ a: 2 }, [{ b: 4 }]]) | ||
}) | ||
|
||
test('should remove nulls in nested objects', () => { | ||
const object = { a: { c: null, d: 2 }, b: [null, 3] } | ||
const normalized = removeNulls(object) | ||
assert.deepStrictEqual(normalized, { a: { c: '', d: 2 }, b: ['', 3] }) | ||
}) | ||
|
||
test('should remove reserved words in nested objects', () => { | ||
const object = { a: { id: 1, c: 2 }, b: [{ id: 3, d: 4 }] } | ||
const normalized = removeReservedWords(object) | ||
assert.deepStrictEqual(normalized, { a: { c: 2 }, b: [{ d: 4 }] }) | ||
}) | ||
}) |
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,71 @@ | ||
const test = require('node:test') | ||
const assert = require('node:assert') | ||
const { getNanoTime, formatTime, sleep } = require('./../lib/time.js') | ||
|
||
test.describe('time', () => { | ||
test.it('should get nano time', async () => { | ||
const time = getNanoTime() | ||
assert.equal(typeof time, 'bigint') | ||
}) | ||
|
||
test.it('should format time in nanoseconds', async () => { | ||
const time = BigInt(123) | ||
const formattedTime = formatTime(time) | ||
assert.equal(formattedTime, '123ns') | ||
}) | ||
|
||
test.it('should format time in microseconds', async () => { | ||
const time = BigInt(123456) | ||
const formattedTime = formatTime(time) | ||
assert.equal(formattedTime, '123μs') | ||
}) | ||
|
||
test.it('should format time in milliseconds', async () => { | ||
const time = BigInt(123456789) | ||
const formattedTime = formatTime(time) | ||
assert.equal(formattedTime, '123ms') | ||
}) | ||
|
||
test.it('should format time in seconds', async () => { | ||
const time = BigInt(1234567890) | ||
const formattedTime = formatTime(time) | ||
assert.equal(formattedTime, '1s') | ||
}) | ||
|
||
test.it('should convert number to bigint and format time', async () => { | ||
const time = 123456789 | ||
const formattedTime = formatTime(time) | ||
assert.equal(formattedTime, '123ms') | ||
}) | ||
|
||
test.it('should throw error for negative time', async () => { | ||
const time = BigInt(-123) | ||
assert.throws(() => formatTime(time), /microtime must be positive/) | ||
}) | ||
|
||
test.it('should sleep for 100ms', async () => { | ||
const start = getNanoTime() | ||
await sleep(100) | ||
const end = getNanoTime() | ||
const elapsed = end - start | ||
assert.equal(elapsed >= BigInt(1e8), true) | ||
}) | ||
|
||
test.it('should return BigInt(0) if process or process.hrtime is undefined', () => { | ||
const originalHrtime = process.hrtime | ||
|
||
Object.defineProperty(process, 'hrtime', { | ||
value: undefined, | ||
writable: true | ||
}) | ||
|
||
let time = getNanoTime() | ||
assert.equal(time, BigInt(0)) | ||
|
||
process.hrtime = originalHrtime | ||
|
||
time = getNanoTime() | ||
assert.ok(typeof time === 'bigint') | ||
assert.ok(time > BigInt(0)) | ||
}) | ||
}) |