Skip to content

Commit c2dbfe1

Browse files
committed
fix: test perf to avoid timeout
1 parent dd91de9 commit c2dbfe1

File tree

1 file changed

+12
-75
lines changed

1 file changed

+12
-75
lines changed

tests/sandbox-config.test.ts

Lines changed: 12 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ describe.each(SANDBOX_CASES)(
4848
const [, filePath] = matchedEntry
4949
const content = await readFile(filePath, 'utf8')
5050
const mdxLoaderValue = target.extract(content)
51-
expect(mdxLoaderValue).toMatch(/remarkPlugins: \[\n.*remarkGfm/)
51+
52+
// Check that remarkPlugins is configured with remarkGfm
53+
const lines = mdxLoaderValue.split('\n')
54+
const remarkPluginsLineIndex = lines.findIndex((line) =>
55+
line.includes('remarkPlugins'),
56+
)
57+
expect(remarkPluginsLineIndex).toBeGreaterThanOrEqual(0)
58+
expect(lines[remarkPluginsLineIndex + 1]).toContain('remarkGfm')
5259
})
5360
}
5461
},
@@ -61,78 +68,8 @@ function extractMdxLoaderRule(configText: string): string {
6168
throw new Error('Unable to locate mdx loader rule in config output')
6269
}
6370

64-
const start = findOpeningBrace(configText, markerIndex)
65-
const end = findClosingBrace(configText, start)
66-
return configText.slice(start, end + 1).trim()
67-
}
68-
69-
function findOpeningBrace(text: string, fromIndex: number): number {
70-
for (let i = fromIndex; i >= 0; i -= 1) {
71-
if (text[i] === '{') {
72-
return i
73-
}
74-
}
75-
throw new Error('Unable to locate opening brace for MDX rule')
76-
}
77-
78-
function findClosingBrace(text: string, startIndex: number): number {
79-
let depth = 0
80-
let inSingle = false
81-
let inDouble = false
82-
let inTemplate = false
83-
84-
for (let i = startIndex; i < text.length; i += 1) {
85-
const char = text[i]
86-
const prevChar = text[i - 1]
87-
88-
if (inSingle) {
89-
if (char === "'" && prevChar !== '\\') {
90-
inSingle = false
91-
}
92-
continue
93-
}
94-
95-
if (inDouble) {
96-
if (char === '"' && prevChar !== '\\') {
97-
inDouble = false
98-
}
99-
continue
100-
}
101-
102-
if (inTemplate) {
103-
if (char === '`' && prevChar !== '\\') {
104-
inTemplate = false
105-
}
106-
continue
107-
}
108-
109-
if (char === "'") {
110-
inSingle = true
111-
continue
112-
}
113-
114-
if (char === '"') {
115-
inDouble = true
116-
continue
117-
}
118-
119-
if (char === '`') {
120-
inTemplate = true
121-
continue
122-
}
123-
124-
if (char === '{') {
125-
depth += 1
126-
continue
127-
}
128-
129-
if (char === '}') {
130-
depth -= 1
131-
if (depth === 0) {
132-
return i
133-
}
134-
}
135-
}
136-
137-
throw new Error('Unable to locate closing brace for MDX rule')
71+
// Extract a small window around the marker - just need a few hundred chars for the options
72+
const windowStart = Math.max(0, markerIndex - 200)
73+
const windowEnd = Math.min(configText.length, markerIndex + 800)
74+
return configText.slice(windowStart, windowEnd)
13875
}

0 commit comments

Comments
 (0)