-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(browser): handle config.base (#4686)
Ensures that every import() is properly prefixed with either config.base or '/'.
- Loading branch information
Showing
6 changed files
with
38 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export async function importId(id: string) { | ||
const name = `/@id/${id}` | ||
export async function importId(id: string, basePath: string) { | ||
const name = `${basePath}@id/${id}` | ||
// @ts-expect-error mocking vitest apis | ||
return __vi_wrap_module__(import(name)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import assert from 'node:assert' | ||
import test from 'node:test' | ||
import runVitest from './run-vitest.mjs' | ||
|
||
const { | ||
stderr, | ||
browserResultJson, | ||
passedTests, | ||
failedTests, | ||
} = await runVitest(['--config', 'vitest.config-basepath.mts']) | ||
|
||
await test('tests run in presence of config.base', async () => { | ||
assert.ok(browserResultJson.testResults.length === 8, 'Not all the tests have been run') | ||
assert.ok(passedTests.length === 7, 'Some tests failed') | ||
assert.ok(failedTests.length === 1, 'Some tests have passed but should fail') | ||
|
||
assert.doesNotMatch(stderr, /Unhandled Error/, 'doesn\'t have any unhandled errors') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { defineConfig, mergeConfig } from 'vitest/config' | ||
import baseConfig from './vitest.config.mts' | ||
|
||
export default mergeConfig(baseConfig, defineConfig({ base: '/fix-4686' })) |