From d2459a59107beea912bf6d76ec8beb3cb1a8a65e Mon Sep 17 00:00:00 2001 From: Eric Rabinowitz Date: Tue, 10 Sep 2024 14:43:24 -0400 Subject: [PATCH 1/3] Update jest.config.ts --- jest.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/jest.config.ts b/jest.config.ts index 1b5a597..9a09615 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -3,6 +3,7 @@ import type { JestConfigWithTsJest } from 'ts-jest' const jestConfig: JestConfigWithTsJest = { preset: 'ts-jest', testEnvironment: 'jsdom', + testMatch: ['/src/**/*.test.ts?(x)'], }; export default jestConfig; From dfb0eddabf829900808807d243f86d507fda7976 Mon Sep 17 00:00:00 2001 From: Eric Rabinowitz Date: Tue, 10 Sep 2024 14:43:45 -0400 Subject: [PATCH 2/3] don't make theme array values a proxy --- src/__tests__/ThemeParty.test.ts | 27 +++++++++++++++++++++++++++ src/makeThemeProxy.ts | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/__tests__/ThemeParty.test.ts b/src/__tests__/ThemeParty.test.ts index 6237221..bcb6795 100644 --- a/src/__tests__/ThemeParty.test.ts +++ b/src/__tests__/ThemeParty.test.ts @@ -1,4 +1,5 @@ import { assert, Equals } from 'tsafe'; +import util from 'util'; import { ThemeParty } from '../ThemeParty'; @@ -161,3 +162,29 @@ test('getTheme with selector', () => { lg: 16, }); }); + +test('proxy values', () => { + const themeParty = new ThemeParty({ + string: 'string', + number: 1, + boolean: true, + object: { key: 'value' }, + array: [1, 2, 3], + function: () => ({ function: true }), + }); + + const theme = themeParty.getTheme(); + expect(util.types.isProxy(theme)).toBe(true); + expect(theme.string).toBe('string'); + expect(util.types.isProxy(theme.string)).toBe(false); + expect(theme.number).toBe(1); + expect(util.types.isProxy(theme.number)).toBe(false); + expect(theme.boolean).toBe(true); + expect(util.types.isProxy(theme.boolean)).toBe(false); + expect(theme.object).toEqual({ key: 'value' }); + expect(util.types.isProxy(theme.object)).toBe(true); + expect(theme.array).toEqual([1, 2, 3]); + expect(util.types.isProxy(theme.array)).toBe(false); + expect(theme.function).toEqual({ function: true }); + expect(util.types.isProxy(theme.function)).toBe(false); +}) diff --git a/src/makeThemeProxy.ts b/src/makeThemeProxy.ts index 4e9a999..bb34736 100644 --- a/src/makeThemeProxy.ts +++ b/src/makeThemeProxy.ts @@ -9,7 +9,7 @@ export function makeThemeProxy(theme: ThemeConfig): ThemeExtrac return value(new Proxy(theme, handler)); } - if (typeof value === "object" && value !== null) { + if (typeof value === "object" && value !== null && !Array.isArray(value)) { return new Proxy(value, handler); } From 260c971b5a934ebc0390ca86e68469874c4501f7 Mon Sep 17 00:00:00 2001 From: Eric Rabinowitz Date: Tue, 10 Sep 2024 14:44:10 -0400 Subject: [PATCH 3/3] Create 071e6ed7.yml --- .yarn/versions/071e6ed7.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .yarn/versions/071e6ed7.yml diff --git a/.yarn/versions/071e6ed7.yml b/.yarn/versions/071e6ed7.yml new file mode 100644 index 0000000..3fafb72 --- /dev/null +++ b/.yarn/versions/071e6ed7.yml @@ -0,0 +1,2 @@ +releases: + theme-party: patch