1- import { describe , it , expect , vi , beforeEach } from 'vitest' ;
1+ import { describe , it , expect , vi , beforeEach , beforeAll } from 'vitest' ;
22import { insertContent } from './insertContent.js' ;
33import * as contentProcessor from '../helpers/contentProcessor.js' ;
44
@@ -161,11 +161,14 @@ describe('insertContent', () => {
161161
162162// Integration-style tests that use a real Editor instance to
163163// insert markdown/HTML lists and verify exported OOXML has list numbering.
164+ //
165+ // These tests need the REAL contentProcessor (not the mock from the unit tests
166+ // above). We use a separate vi.mock-free import path by dynamically importing
167+ // the real insertContent function.
164168describe ( 'insertContent (integration) list export' , ( ) => {
165- // Cache loaded DOCX data and helpers to avoid repeated file loading
166- let cachedDocxData = null ;
167169 let helpers = null ;
168170 let exportHelpers = null ;
171+ let cachedDocxData = null ;
169172
170173 const getListParagraphs = ( result ) => {
171174 const body = result . elements ?. find ( ( el ) => el . name === 'w:body' ) ;
@@ -185,22 +188,16 @@ describe('insertContent (integration) list export', () => {
185188 return { numId, ilvl } ;
186189 } ;
187190
188- const setupEditor = async ( ) => {
189- // Use real content processor for these tests
191+ // Load helpers and DOCX data once for all integration tests
192+ beforeAll ( async ( ) => {
190193 vi . resetModules ( ) ;
191194 vi . doUnmock ( '../helpers/contentProcessor.js' ) ;
195+ helpers = await import ( '../../tests/helpers/helpers.js' ) ;
196+ cachedDocxData = await helpers . loadTestDataForEditorTests ( 'blank-doc.docx' ) ;
197+ exportHelpers = await import ( '../../tests/export/export-helpers/index.js' ) ;
198+ } ) ;
192199
193- // Cache helpers and DOCX data on first call
194- if ( ! helpers ) {
195- helpers = await import ( '../../tests/helpers/helpers.js' ) ;
196- }
197- if ( ! cachedDocxData ) {
198- cachedDocxData = await helpers . loadTestDataForEditorTests ( 'blank-doc.docx' ) ;
199- }
200- if ( ! exportHelpers ) {
201- exportHelpers = await import ( '../../tests/export/export-helpers/index.js' ) ;
202- }
203-
200+ const setupEditor = ( ) => {
204201 const { docx, media, mediaFiles, fonts } = cachedDocxData ;
205202 const { editor } = helpers . initTestEditor ( { content : docx , media, mediaFiles, fonts, mode : 'docx' } ) ;
206203 return editor ;
@@ -212,7 +209,7 @@ describe('insertContent (integration) list export', () => {
212209 } ;
213210
214211 it ( 'exports ordered list from markdown with numId/ilvl' , async ( ) => {
215- const editor = await setupEditor ( ) ;
212+ const editor = setupEditor ( ) ;
216213 editor . commands . insertContent ( '1. One\n2. Two' , { contentType : 'markdown' } ) ;
217214 await Promise . resolve ( ) ;
218215
@@ -230,7 +227,7 @@ describe('insertContent (integration) list export', () => {
230227 } ) ;
231228
232229 it ( 'exports unordered list from markdown with numId/ilvl' , async ( ) => {
233- const editor = await setupEditor ( ) ;
230+ const editor = setupEditor ( ) ;
234231 editor . commands . insertContent ( '- Alpha\n- Beta' , { contentType : 'markdown' } ) ;
235232 await Promise . resolve ( ) ;
236233
@@ -248,7 +245,7 @@ describe('insertContent (integration) list export', () => {
248245 } ) ;
249246
250247 it ( 'exports ordered list from HTML with numId/ilvl' , async ( ) => {
251- const editor = await setupEditor ( ) ;
248+ const editor = setupEditor ( ) ;
252249 editor . commands . insertContent ( '<ol><li>First</li><li>Second</li></ol>' , { contentType : 'html' } ) ;
253250 await Promise . resolve ( ) ;
254251
@@ -262,7 +259,7 @@ describe('insertContent (integration) list export', () => {
262259 } ) ;
263260
264261 it ( 'inserts markdown heading + bold text without creating a table' , async ( ) => {
265- const editor = await setupEditor ( ) ;
262+ const editor = setupEditor ( ) ;
266263
267264 editor . commands . insertContent ( '# Hello\n\nSome **bold** text' , { contentType : 'markdown' } ) ;
268265 await Promise . resolve ( ) ;
@@ -280,7 +277,7 @@ describe('insertContent (integration) list export', () => {
280277 } ) ;
281278
282279 it ( 'exports unordered list from HTML with numId/ilvl' , async ( ) => {
283- const editor = await setupEditor ( ) ;
280+ const editor = setupEditor ( ) ;
284281 editor . commands . insertContent ( '<ul><li>Apple</li><li>Banana</li></ul>' , { contentType : 'html' } ) ;
285282 await Promise . resolve ( ) ;
286283
@@ -294,7 +291,7 @@ describe('insertContent (integration) list export', () => {
294291 } ) ;
295292
296293 it ( 'defaults imported HTML tables to 100% width' , async ( ) => {
297- const editor = await setupEditor ( ) ;
294+ const editor = setupEditor ( ) ;
298295 editor . commands . insertContent (
299296 '<table><tbody><tr><td>Query</td><td>Assessment</td></tr><tr><td>A</td><td>B</td></tr></tbody></table>' ,
300297 { contentType : 'html' } ,
@@ -310,7 +307,7 @@ describe('insertContent (integration) list export', () => {
310307 } ) ;
311308
312309 it ( 'defaults imported markdown tables to 100% width' , async ( ) => {
313- const editor = await setupEditor ( ) ;
310+ const editor = setupEditor ( ) ;
314311 editor . commands . insertContent ( '| Query | Assessment |\n| --- | --- |\n| A | B |' , { contentType : 'markdown' } ) ;
315312 await Promise . resolve ( ) ;
316313
@@ -323,7 +320,7 @@ describe('insertContent (integration) list export', () => {
323320 } ) ;
324321
325322 it ( 'does not inject inline cell borders on imported HTML table headers' , async ( ) => {
326- const editor = await setupEditor ( ) ;
323+ const editor = setupEditor ( ) ;
327324 editor . commands . insertContent (
328325 '<table><thead><tr><th>Search Query</th><th>Findings / Assessment</th></tr></thead><tbody><tr><td>A</td><td>B</td></tr></tbody></table>' ,
329326 { contentType : 'html' } ,
@@ -358,17 +355,14 @@ describe.skipIf(!process.env.CI)('insertContent (integration) horizontal rule',
358355 let helpers = null ;
359356 let cachedDocxData = null ;
360357
361- const setupEditor = async ( ) => {
358+ beforeAll ( async ( ) => {
362359 vi . resetModules ( ) ;
363360 vi . doUnmock ( '../helpers/contentProcessor.js' ) ;
361+ helpers = await import ( '../../tests/helpers/helpers.js' ) ;
362+ cachedDocxData = await helpers . loadTestDataForEditorTests ( 'blank-doc.docx' ) ;
363+ } ) ;
364364
365- if ( ! helpers ) {
366- helpers = await import ( '../../tests/helpers/helpers.js' ) ;
367- }
368- if ( ! cachedDocxData ) {
369- cachedDocxData = await helpers . loadTestDataForEditorTests ( 'blank-doc.docx' ) ;
370- }
371-
365+ const setupEditor = ( ) => {
372366 const { docx, media, mediaFiles, fonts } = cachedDocxData ;
373367 const { editor } = helpers . initTestEditor ( { content : docx , media, mediaFiles, fonts, mode : 'docx' } ) ;
374368 return editor ;
@@ -391,7 +385,7 @@ describe.skipIf(!process.env.CI)('insertContent (integration) horizontal rule',
391385 } ;
392386
393387 it ( 'insertContent with contentType html creates a horizontal rule' , async ( ) => {
394- const editor = await setupEditor ( ) ;
388+ const editor = setupEditor ( ) ;
395389 expect ( countHorizontalRules ( editor ) ) . toBe ( 0 ) ;
396390
397391 editor . commands . insertContent ( '<hr>' , { contentType : 'html' } ) ;
@@ -400,7 +394,7 @@ describe.skipIf(!process.env.CI)('insertContent (integration) horizontal rule',
400394 } ) ;
401395
402396 it ( 'insertContent with contentType markdown creates a horizontal rule' , async ( ) => {
403- const editor = await setupEditor ( ) ;
397+ const editor = setupEditor ( ) ;
404398 expect ( countHorizontalRules ( editor ) ) . toBe ( 0 ) ;
405399
406400 editor . commands . insertContent ( '---' , { contentType : 'markdown' } ) ;
@@ -409,7 +403,7 @@ describe.skipIf(!process.env.CI)('insertContent (integration) horizontal rule',
409403 } ) ;
410404
411405 it ( 'insertContent with bare <hr> (no contentType) creates a horizontal rule' , async ( ) => {
412- const editor = await setupEditor ( ) ;
406+ const editor = setupEditor ( ) ;
413407 expect ( countHorizontalRules ( editor ) ) . toBe ( 0 ) ;
414408
415409 editor . commands . insertContent ( '<hr>' ) ;
0 commit comments