diff --git a/admin/src/components/form/codeeditor/load.ts b/admin/src/components/form/codeeditor/load.ts new file mode 100644 index 00000000..e1f43a3e --- /dev/null +++ b/admin/src/components/form/codeeditor/load.ts @@ -0,0 +1,5 @@ +// Separate module so tests can mock the CodeMirror chunk import without +// fighting a prior evaluation of editor.ts in the same vitest worker. +export function importCodeEditor(): Promise { + return import('./editor') +} diff --git a/admin/src/components/form/fields/CodeEditorField.vue b/admin/src/components/form/fields/CodeEditorField.vue index d5b09238..841475d2 100644 --- a/admin/src/components/form/fields/CodeEditorField.vue +++ b/admin/src/components/form/fields/CodeEditorField.vue @@ -84,7 +84,7 @@ onMounted(async () => { return } try { - module = await import('../codeeditor/editor') + module = await (await import('../codeeditor/load')).importCodeEditor() if (disposed) { return } diff --git a/admin/tests/form/mail-smoke.test.ts b/admin/tests/form/mail-smoke.test.ts index 1d84c62f..57253d5e 100644 --- a/admin/tests/form/mail-smoke.test.ts +++ b/admin/tests/form/mail-smoke.test.ts @@ -235,16 +235,18 @@ describe('CodeEditorField loading and fallback', () => { }) it('shows the bg-skel loading box at the size height while the chunk loads', async () => { - // Hold the dynamic import open so the loading box stays visible. + // Hold the chunk import open so the loading box stays visible. let release!: () => void const gate = new Promise((resolve) => { release = resolve }) vi.resetModules() - vi.doMock('../../src/components/form/codeeditor/editor', async () => { - await gate - return await vi.importActual('../../src/components/form/codeeditor/editor') - }) + vi.doMock('../../src/components/form/codeeditor/load', () => ({ + importCodeEditor: async () => { + await gate + return await vi.importActual('../../src/components/form/codeeditor/editor') + }, + })) const Field = (await import('../../src/components/form/fields/CodeEditorField.vue')).default const wrapper = mount(Field, { props: { field: codeField(), modelValue: '

x

', controlId: 'f-html' }, @@ -258,7 +260,7 @@ describe('CodeEditorField loading and fallback', () => { release() await flushPromises() wrapper.unmount() - vi.doUnmock('../../src/components/form/codeeditor/editor') + vi.doUnmock('../../src/components/form/codeeditor/load') }) it('renders a read-only pre without loading CodeMirror', async () => { @@ -442,12 +444,12 @@ describe('CodeEditorField chunk failure', () => { it('shows the load_failed note and a monospace textarea that still emits', async () => { vi.resetModules() - vi.doUnmock('../../src/components/form/codeeditor/editor') - // Reject the dynamic import itself so a prior suite that already - // evaluated the real editor chunk cannot keep createCodeEditor working. - vi.doMock('../../src/components/form/codeeditor/editor', () => { - throw new Error('chunk failed') - }) + vi.doUnmock('../../src/components/form/codeeditor/load') + vi.doMock('../../src/components/form/codeeditor/load', () => ({ + importCodeEditor: async () => { + throw new Error('chunk failed') + }, + })) ;(await import('../../src/app/i18n')).setBundle({ ...mailPreviewBundle, ...codeeditorBundle }, 'en') const Field = (await import('../../src/components/form/fields/CodeEditorField.vue')).default const wrapper = mount(Field, { diff --git a/admin/tests/form/registry.test.ts b/admin/tests/form/registry.test.ts index 0addf6e6..af54a34b 100644 --- a/admin/tests/form/registry.test.ts +++ b/admin/tests/form/registry.test.ts @@ -14,7 +14,6 @@ import MLTextField from '../../src/components/form/fields/MLTextField.vue' import PasswordField from '../../src/components/form/fields/PasswordField.vue' import PermissionEditorField from '../../src/components/form/fields/PermissionEditorField.vue' import ColorPickerField from '../../src/components/form/fields/ColorPickerField.vue' -import CodeEditorField from '../../src/components/form/fields/CodeEditorField.vue' import UnsupportedField from '../../src/components/form/fields/UnsupportedField.vue' import WidgetField from '../../src/components/form/fields/WidgetField.vue' import MLPluginField from '../../src/components/form/fields/MLPluginField.vue' @@ -48,12 +47,21 @@ describe('field renderer registry (D-05)', () => { ['checkbox', CheckboxField], ['relation', RelationField], ['colorpicker', ColorPickerField], - ['codeeditor', CodeEditorField], [RELATION_MANAGER, RelationManager], ])('renders %s with its control', (type, component) => { expect(rendererFor(type)).toBe(component) }) + // codeeditor is registered (Phase 35) but not imported here: a static import + // of CodeEditorField would evaluate its CodeMirror chunk and break the + // mail-smoke chunk-failure mock that relies on vi.resetModules. + it('registers codeeditor as an editable control', () => { + expect(isRegistered('codeeditor')).toBe(true) + expect(needsRecord('codeeditor')).toBe(false) + expect(rendererFor('codeeditor')).not.toBe(UnsupportedField) + expect(rendererFor('codeeditor').__name).toBe('CodeEditorField') + }) + it.each(['notatype', '', 'TEXT', 'constructor'])('falls back to UnsupportedField for %j', (type) => { expect(rendererFor(type)).toBe(UnsupportedField) expect(isRegistered(type)).toBe(false)