-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vite: Don't prefix story import with
@fs
- Loading branch information
1 parent
be2e4c8
commit d8f53d5
Showing
2 changed files
with
72 additions
and
15 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
code/builders/builder-vite/src/codegen-importfn-script.test.ts
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,56 @@ | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
||
import { toImportFn } from './codegen-importfn-script'; | ||
|
||
describe('toImportFn', () => { | ||
it('should correctly map story paths to import functions for absolute paths on Linux', async () => { | ||
const root = '/absolute/path'; | ||
const stories = ['/absolute/path/to/story1.js', '/absolute/path/to/story2.js']; | ||
|
||
const result = await toImportFn(root, stories); | ||
|
||
expect(result).toMatchInlineSnapshot(` | ||
"const importers = { | ||
"./to/story1.js": () => import("/absolute/path/to/story1.js"), | ||
"./to/story2.js": () => import("/absolute/path/to/story2.js") | ||
}; | ||
export async function importFn(path) { | ||
return await importers[path](); | ||
}" | ||
`); | ||
}); | ||
|
||
it('should correctly map story paths to import functions for absolute paths on Windows', async () => { | ||
const root = 'C:\\absolute\\path'; | ||
const stories = ['C:\\absolute\\path\\to\\story1.js', 'C:\\absolute\\path\\to\\story2.js']; | ||
|
||
const result = await toImportFn(root, stories); | ||
|
||
expect(result).toMatchInlineSnapshot(` | ||
"const importers = { | ||
"./to/story1.js": () => import("C:/absolute/path/to/story1.js"), | ||
"./to/story2.js": () => import("C:/absolute/path/to/story2.js") | ||
}; | ||
export async function importFn(path) { | ||
return await importers[path](); | ||
}" | ||
`); | ||
}); | ||
|
||
it('should handle an empty array of stories', async () => { | ||
const root = '/absolute/path'; | ||
const stories: string[] = []; | ||
|
||
const result = await toImportFn(root, stories); | ||
|
||
expect(result).toMatchInlineSnapshot(` | ||
"const importers = {}; | ||
export async function importFn(path) { | ||
return await importers[path](); | ||
}" | ||
`); | ||
}); | ||
}); |
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