fix(admin): isolate CodeMirror load for chunk-failure tests

- Route CodeEditorField through codeeditor/load so vitest can mock the chunk
- Keep registry expectations for colorpicker/codeeditor without importing the editor SFC

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-13 13:57:16 +01:00
parent e81cfde7b2
commit 1df2e31dea
4 changed files with 30 additions and 15 deletions

View File

@@ -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<void>((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: '<p>x</p>', 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, {