diff --git a/libs/core/src/components/pds-checkbox/test/pds-checkbox.spec.tsx b/libs/core/src/components/pds-checkbox/test/pds-checkbox.spec.tsx index 05c9a9482..7dab328fc 100644 --- a/libs/core/src/components/pds-checkbox/test/pds-checkbox.spec.tsx +++ b/libs/core/src/components/pds-checkbox/test/pds-checkbox.spec.tsx @@ -3,6 +3,31 @@ import { PdsCheckbox } from '../pds-checkbox'; import { danger } from '@pine-ds/icons/icons'; describe('pds-checkbox', () => { + const mockInternals = { + setFormValue: jest.fn(), + setValidity: jest.fn(), + }; + let originalAttachInternals: unknown; + + beforeAll(() => { + originalAttachInternals = (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: () => mockInternals, + }); + }); + + afterAll(() => { + if (originalAttachInternals) { + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: originalAttachInternals, + }); + } else { + delete (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + } + }); + it('renders', async () => { const page = await newSpecPage({ components: [PdsCheckbox], diff --git a/libs/core/src/components/pds-combobox/test/pds-combobox.spec.tsx b/libs/core/src/components/pds-combobox/test/pds-combobox.spec.tsx index 031da068b..36d1cc557 100644 --- a/libs/core/src/components/pds-combobox/test/pds-combobox.spec.tsx +++ b/libs/core/src/components/pds-combobox/test/pds-combobox.spec.tsx @@ -14,6 +14,31 @@ const createMockOption = (value: string, label: string, selected: boolean = fals } as unknown as HTMLOptionElement); describe('pds-combobox', () => { + const mockInternals = { + setFormValue: jest.fn(), + setValidity: jest.fn(), + }; + let originalAttachInternals: unknown; + + beforeAll(() => { + originalAttachInternals = (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: () => mockInternals, + }); + }); + + afterAll(() => { + if (originalAttachInternals) { + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: originalAttachInternals, + }); + } else { + delete (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + } + }); + it('renders default combobox with input trigger', async () => { const { root } = await newSpecPage({ components: [PdsCombobox], diff --git a/libs/core/src/components/pds-input/test/pds-input.spec.tsx b/libs/core/src/components/pds-input/test/pds-input.spec.tsx index a5a81782b..5eb0744c4 100644 --- a/libs/core/src/components/pds-input/test/pds-input.spec.tsx +++ b/libs/core/src/components/pds-input/test/pds-input.spec.tsx @@ -2,6 +2,30 @@ import { newSpecPage } from '@stencil/core/testing'; import { PdsInput } from '../pds-input'; describe('pds-input', () => { + const mockInternals = { + setFormValue: jest.fn(), + setValidity: jest.fn(), + }; + let originalAttachInternals: unknown; + + beforeAll(() => { + originalAttachInternals = (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: () => mockInternals, + }); + }); + + afterAll(() => { + if (originalAttachInternals) { + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: originalAttachInternals, + }); + } else { + delete (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + } + }); it('renders a value when prop is set', async () => { const { root } = await newSpecPage({ components: [PdsInput], diff --git a/libs/core/src/components/pds-multiselect/test/__snapshots__/pds-multiselect.spec.tsx.snap b/libs/core/src/components/pds-multiselect/test/__snapshots__/pds-multiselect.spec.tsx.snap new file mode 100644 index 000000000..1e33726ef --- /dev/null +++ b/libs/core/src/components/pds-multiselect/test/__snapshots__/pds-multiselect.spec.tsx.snap @@ -0,0 +1,24 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`pds-multiselect renders with label 1`] = ` + + + +`; diff --git a/libs/core/src/components/pds-select/test/pds-select.spec.tsx b/libs/core/src/components/pds-select/test/pds-select.spec.tsx index 36efdd3f1..547fbbd0e 100644 --- a/libs/core/src/components/pds-select/test/pds-select.spec.tsx +++ b/libs/core/src/components/pds-select/test/pds-select.spec.tsx @@ -3,6 +3,31 @@ import { PdsSelect } from '../pds-select'; import { enlarge } from '@pine-ds/icons/icons'; describe('pds-select', () => { + const mockInternals = { + setFormValue: jest.fn(), + setValidity: jest.fn(), + }; + let originalAttachInternals: unknown; + + beforeAll(() => { + originalAttachInternals = (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: () => mockInternals, + }); + }); + + afterAll(() => { + if (originalAttachInternals) { + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: originalAttachInternals, + }); + } else { + delete (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + } + }); + it('renders', async () => { const { root } = await newSpecPage({ components: [PdsSelect], diff --git a/libs/core/src/components/pds-switch/test/pds-switch.spec.tsx b/libs/core/src/components/pds-switch/test/pds-switch.spec.tsx index cc5d31ae2..d7bfc0cf3 100644 --- a/libs/core/src/components/pds-switch/test/pds-switch.spec.tsx +++ b/libs/core/src/components/pds-switch/test/pds-switch.spec.tsx @@ -3,6 +3,31 @@ import { PdsSwitch } from '../pds-switch'; import { danger } from '@pine-ds/icons/icons'; describe('pds-switch', () => { + const mockInternals = { + setFormValue: jest.fn(), + setValidity: jest.fn(), + }; + let originalAttachInternals: unknown; + + beforeAll(() => { + originalAttachInternals = (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: () => mockInternals, + }); + }); + + afterAll(() => { + if (originalAttachInternals) { + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: originalAttachInternals, + }); + } else { + delete (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + } + }); + it('renders an input as a checkbox with label', async () => { const page = await newSpecPage({ components: [PdsSwitch], diff --git a/libs/core/src/components/pds-textarea/test/pds-textarea.spec.tsx b/libs/core/src/components/pds-textarea/test/pds-textarea.spec.tsx index ae3cd93d1..e682dfd8b 100644 --- a/libs/core/src/components/pds-textarea/test/pds-textarea.spec.tsx +++ b/libs/core/src/components/pds-textarea/test/pds-textarea.spec.tsx @@ -3,6 +3,31 @@ import { PdsTextarea } from '../pds-textarea'; import { danger } from '@pine-ds/icons/icons'; describe('pds-textarea', () => { + const mockInternals = { + setFormValue: jest.fn(), + setValidity: jest.fn(), + }; + let originalAttachInternals: unknown; + + beforeAll(() => { + originalAttachInternals = (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: () => mockInternals, + }); + }); + + afterAll(() => { + if (originalAttachInternals) { + Object.defineProperty(HTMLElement.prototype, 'attachInternals', { + configurable: true, + value: originalAttachInternals, + }); + } else { + delete (HTMLElement.prototype as { attachInternals?: unknown }).attachInternals; + } + }); + it('renders default textarea', async () => { const {root} = await newSpecPage({ components: [PdsTextarea], diff --git a/libs/core/stencil.config.ts b/libs/core/stencil.config.ts index 52d528bc7..f8fe939f1 100644 --- a/libs/core/stencil.config.ts +++ b/libs/core/stencil.config.ts @@ -1,4 +1,7 @@ import { Config } from '@stencil/core'; +import { existsSync, readFileSync } from 'fs'; +import { request } from 'node:http'; +import { resolve } from 'path'; import { reactOutputTarget } from '@stencil/react-output-target'; // Plugins @@ -7,6 +10,78 @@ import { sass } from '@stencil/sass'; // Custom output targets import vscodeCustomDataOutputTarget from './scripts/vscode-custom-data-generator'; +// #region agent log +const debugRunId = process.env.DEBUG_RUN_ID || 'pre-fix'; +const debugLog = (message: string, data: Record, hypothesisId: string) => { + const payload = { + sessionId: 'debug-session', + runId: debugRunId, + hypothesisId, + location: 'libs/core/stencil.config.ts', + message, + data, + timestamp: Date.now(), + }; + + if (typeof fetch === 'function') { + fetch('http://127.0.0.1:7243/ingest/3744f2d7-8ec9-48ce-9313-5076103493e4', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload), + }).catch(() => {}); + return; + } + + try { + const url = new URL('http://127.0.0.1:7243/ingest/3744f2d7-8ec9-48ce-9313-5076103493e4'); + const req = request( + { + hostname: url.hostname, + port: url.port, + path: url.pathname, + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + }, + (res) => res.resume() + ); + req.on('error', () => {}); + req.write(JSON.stringify(payload)); + req.end(); + } catch { + // swallow logging errors + } +}; + +debugLog('stencil-config-load', { + cwd: process.cwd(), + argv: process.argv, + ci: process.env.CI, + nxTarget: process.env.NX_TASK_TARGET_TARGET, +}, 'H1'); + +const componentsPkgPath = resolve(__dirname, 'components/package.json'); +const scriptsPkgPath = resolve(__dirname, 'scripts/custom-elements/package.json'); +const componentsExists = existsSync(componentsPkgPath); +const scriptsExists = existsSync(scriptsPkgPath); +const componentsName = componentsExists ? JSON.parse(readFileSync(componentsPkgPath, 'utf8')).name : null; +const scriptsName = scriptsExists ? JSON.parse(readFileSync(scriptsPkgPath, 'utf8')).name : null; + +debugLog('stencil-package-presence', { + componentsPkgPath, + scriptsPkgPath, + componentsExists, + scriptsExists, + componentsName, + scriptsName, +}, 'H2'); + +if (componentsExists && scriptsExists && componentsName === scriptsName) { + debugLog('stencil-duplicate-package-name', { + duplicateName: componentsName, + }, 'H3'); +} +// #endregion + export const config: Config = { namespace: 'pine-core', globalStyle: 'src/global/styles/app.scss',