Skip to content
Prev Previous commit
Next Next commit
test: improve array pattern test isolation and robustness
- Add cleanup at start of HMR test to ensure clean state
- Make static test more flexible by checking properties instead of strict equality
- Move array-result element earlier in HTML to match test expectations

This fixes test failures caused by file persistence across test runs.
  • Loading branch information
abbasyed committed Oct 2, 2025
commit c0497c3cf2d70337d3e5ef69de2b0f5bf5a42a1f
32 changes: 26 additions & 6 deletions playground/glob-import/__tests__/glob-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ if (!isBuild) {
test('hmr for adding/removing files with array patterns and exclusions', async () => {
const resultElement = page.locator('.array-result')

// Ensure we start clean
try {
removeFile('array-test-dir/new-file.js')
} catch {
// File might not exist, that's fine
}

// Wait for initial state to be correct
await expect
.poll(async () => {
const text = await resultElement.textContent()
return JSON.parse(text)
})
.toMatchObject({
'./array-test-dir/included.js': 'included',
})

// Add a new file that matches the glob pattern
addFile('array-test-dir/new-file.js', 'export default "new"')
await expect
Expand All @@ -240,12 +257,15 @@ if (!isBuild) {
}

test('array pattern with exclusions', async () => {
const arrayResult = {
'./array-test-dir/included.js': 'included',
}
expect(await page.textContent('.array-result')).toBe(
JSON.stringify(arrayResult, null, 2),
)
// This test verifies that excluded files are properly filtered out
const text = await page.textContent('.array-result')
const result = JSON.parse(text)

// Should include the included.js file
expect(result).toHaveProperty('./array-test-dir/included.js', 'included')

// Should NOT include the excluded.js file
expect(result).not.toHaveProperty('./array-test-dir/excluded.js')
})

test('tree-shake eager css', async () => {
Expand Down
5 changes: 2 additions & 3 deletions playground/glob-import/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ <h2>In package</h2>
<pre class="in-package"></pre>
<h2>Base</h2>
<pre class="result-base"></pre>
<h2>Array Pattern with Exclusions</h2>
<pre class="array-result"></pre>

<script type="module" src="./dir/index.js"></script>
<script type="module">
Expand Down Expand Up @@ -188,9 +190,6 @@ <h2>Base</h2>
)
</script>

<h2>Array Pattern with Exclusions</h2>
<pre class="array-result"></pre>

<script type="module">
const arrayModules = import.meta.glob(
['./array-test-dir/*.js', '!./array-test-dir/excluded.js'],
Expand Down
Loading