Skip to content

Commit

Permalink
fix: apply undefined-filter to assign
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Mar 17, 2024
1 parent 0a798c6 commit 1463ca8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export const isStringLiteral = (pieces: any) => pieces?.every?.((p: any) => type

export const assign = <T, E>(target: T, ...extras: E[]): T =>
Object.defineProperties(target, extras.reduce<Record<string, any>>((m: any, extra) =>
({...m, ...Object.getOwnPropertyDescriptors(extra)}), {}))
({...m, ...Object.fromEntries(Object.entries(Object.getOwnPropertyDescriptors(extra))
.filter(([,v]) => !Object.hasOwn(v, 'value') || v.value !== undefined))}), {}))

export const quote = (arg: string) => {
if (/^[\w./:=@-]+$/i.test(arg) || arg === '') {
Expand Down
4 changes: 3 additions & 1 deletion src/scripts/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import glob from 'fast-glob'
import { pathToFileURL } from 'node:url'
import process from 'node:process'

const suites = await glob('src/test/**/*.test.{ts,cjs,mjs}', {cwd: process.cwd(), absolute: true, onlyFiles: true})
const focused = process.argv.slice(2)
const suites = focused.length ? focused : await glob('src/test/**/*.test.{ts,cjs,mjs}', {cwd: process.cwd(), absolute: true, onlyFiles: true})

await Promise.all(suites.map(suite => import(pathToFileURL(suite))))
10 changes: 10 additions & 0 deletions src/test/ts/util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as assert from 'node:assert'
import { describe, it } from 'node:test'
import { assign } from '../../main/ts/util.js'

describe('util', () => {
it('assign()', () => {
assert.deepEqual(assign({a: 1}, {b: 2}), {a: 1, b: 2})
assert.deepEqual(assign({a: 1}, {a: undefined}), {a: 1})
})
})

0 comments on commit 1463ca8

Please sign in to comment.