From 1463ca8bba2d6ff6bdeb82a8598d306150481990 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Sun, 17 Mar 2024 16:22:12 +0300 Subject: [PATCH] fix: apply undefined-filter to `assign` --- src/main/ts/util.ts | 3 ++- src/scripts/test.mjs | 4 +++- src/test/ts/util.test.ts | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/test/ts/util.test.ts diff --git a/src/main/ts/util.ts b/src/main/ts/util.ts index 17c3a20..9605f4c 100644 --- a/src/main/ts/util.ts +++ b/src/main/ts/util.ts @@ -26,7 +26,8 @@ export const isStringLiteral = (pieces: any) => pieces?.every?.((p: any) => type export const assign = (target: T, ...extras: E[]): T => Object.defineProperties(target, extras.reduce>((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 === '') { diff --git a/src/scripts/test.mjs b/src/scripts/test.mjs index a6767de..cf473e9 100644 --- a/src/scripts/test.mjs +++ b/src/scripts/test.mjs @@ -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)))) diff --git a/src/test/ts/util.test.ts b/src/test/ts/util.test.ts new file mode 100644 index 0000000..d71bd4e --- /dev/null +++ b/src/test/ts/util.test.ts @@ -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}) + }) +})