-
Notifications
You must be signed in to change notification settings - Fork 46
test: add coverage for utility modules #718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,17 @@ | ||
| 'use strict'; | ||
|
|
||
| import assert from 'node:assert/strict'; | ||
| import { describe, it } from 'node:test'; | ||
|
|
||
| import { enforceArray } from '../array.mjs'; | ||
|
|
||
| describe('enforceArray', () => { | ||
| it('should return the same array if given an array', () => { | ||
| const input = [1, 2, 3]; | ||
| assert.strictEqual(enforceArray(input), input); | ||
| }); | ||
|
|
||
| it('should wrap a non-array value in an array', () => { | ||
| assert.deepStrictEqual(enforceArray('hello'), ['hello']); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,26 @@ | ||
| 'use strict'; | ||
|
|
||
| import assert from 'node:assert/strict'; | ||
| import { describe, it } from 'node:test'; | ||
|
|
||
| import { withExt } from '../file.mjs'; | ||
|
|
||
| describe('withExt', () => { | ||
| it('should replace an existing extension', () => { | ||
| assert.strictEqual(withExt('file.md', 'html'), 'file.html'); | ||
| assert.strictEqual(withExt('path/to/file.md', 'json'), 'path/to/file.json'); | ||
| }); | ||
|
|
||
| it('should add an extension when there is none', () => { | ||
| assert.strictEqual(withExt('file', 'html'), 'file.html'); | ||
| }); | ||
|
|
||
| it('should strip the extension when ext is empty', () => { | ||
| assert.strictEqual(withExt('file.md', ''), 'file'); | ||
| assert.strictEqual(withExt('file.md'), 'file'); | ||
| }); | ||
|
|
||
| it('should handle files with multiple dots', () => { | ||
| assert.strictEqual(withExt('file.test.mjs', 'js'), 'file.test.js'); | ||
| }); | ||
| }); |
This file contains hidden or 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,56 @@ | ||
| 'use strict'; | ||
|
|
||
| import assert from 'node:assert/strict'; | ||
| import { describe, it } from 'node:test'; | ||
|
|
||
| import { lazy, isPlainObject, deepMerge } from '../misc.mjs'; | ||
|
|
||
| describe('lazy', () => { | ||
| it('should call the function only once and cache the result', () => { | ||
| let callCount = 0; | ||
| const fn = lazy(() => { | ||
| callCount++; | ||
| return 42; | ||
| }); | ||
|
|
||
| assert.strictEqual(fn(), 42); | ||
| assert.strictEqual(fn(), 42); | ||
| assert.strictEqual(callCount, 1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isPlainObject', () => { | ||
| it('should return true for plain objects', () => { | ||
| assert.strictEqual(isPlainObject({}), true); | ||
| assert.strictEqual(isPlainObject({ a: 1 }), true); | ||
| }); | ||
|
|
||
| it('should return false for arrays', () => { | ||
| assert.strictEqual(isPlainObject([]), false); | ||
| assert.strictEqual(isPlainObject([1, 2]), false); | ||
| }); | ||
|
|
||
| it('should return false for null and primitives', () => { | ||
| assert.strictEqual(isPlainObject(null), false); | ||
| assert.strictEqual(isPlainObject(undefined), false); | ||
| assert.strictEqual(isPlainObject(42), false); | ||
| assert.strictEqual(isPlainObject('string'), false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('deepMerge', () => { | ||
| it('should merge flat objects with source taking precedence over base', () => { | ||
| const result = deepMerge({ a: 1, b: 2 }, { b: 10, c: 3 }); | ||
| assert.deepStrictEqual(result, { a: 1, b: 2, c: 3 }); | ||
| }); | ||
|
|
||
| it('should merge nested objects recursively', () => { | ||
| const result = deepMerge({ nested: { a: 1 } }, { nested: { b: 2 } }); | ||
| assert.deepStrictEqual(result, { nested: { a: 1, b: 2 } }); | ||
| }); | ||
|
|
||
| it('should use base values when source values are undefined', () => { | ||
| const result = deepMerge({ a: undefined }, { a: 'base' }); | ||
| assert.deepStrictEqual(result, { a: 'base' }); | ||
| }); | ||
| }); |
This file contains hidden or 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,26 @@ | ||
| 'use strict'; | ||
|
|
||
| import assert from 'node:assert/strict'; | ||
| import { describe, it } from 'node:test'; | ||
|
|
||
| import { populate } from '../templates.mjs'; | ||
|
|
||
| describe('populate', () => { | ||
| it('should substitute template variables from config', () => { | ||
| const result = populate('https://github.com/{repository}/blob/{ref}/', { | ||
| repository: 'nodejs/node', | ||
| ref: 'main', | ||
| }); | ||
| assert.strictEqual(result, 'https://github.com/nodejs/node/blob/main/'); | ||
| }); | ||
|
|
||
| it('should use fallback when config value is missing', () => { | ||
| const result = populate('{name|unknown}', {}); | ||
| assert.strictEqual(result, 'unknown'); | ||
| }); | ||
|
|
||
| it('should leave the placeholder as-is when no value or fallback', () => { | ||
| const result = populate('{missing}', {}); | ||
| assert.strictEqual(result, '{missing}'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.