forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9547e3
commit 14846b5
Showing
8 changed files
with
89 additions
and
16 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
packages/vite/src/node/__tests__/fixtures/inline-import/basic.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,7 @@ | ||
interface Test { | ||
field: true | ||
} | ||
|
||
export const test: Test = { | ||
field: true, | ||
} |
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 @@ | ||
module.exports = {} |
7 changes: 7 additions & 0 deletions
7
packages/vite/src/node/__tests__/fixtures/inline-import/plugin.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,7 @@ | ||
import { Plugin } from 'vite' | ||
|
||
export default function testPlugin(): Plugin { | ||
return { | ||
name: 'test', | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/vite/src/node/__tests__/fixtures/inline-import/vite.config.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,7 @@ | ||
import { defineConfig } from 'vite' | ||
import plugin from './plugin' | ||
|
||
export default defineConfig({ | ||
root: './test', | ||
plugins: [plugin()], | ||
}) |
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,40 @@ | ||
import { resolve } from 'node:path' | ||
import { describe, expect, test } from 'vitest' | ||
import { inlineImport } from '../ssr/inlineImport' | ||
|
||
describe('importing files using inlined environment', () => { | ||
const fixture = (name: string) => | ||
resolve(import.meta.dirname, './fixtures/inline-import', name) | ||
|
||
test('importing a basic file works', async () => { | ||
const { module } = await inlineImport< | ||
typeof import('./fixtures/inline-import/basic') | ||
>(fixture('basic')) | ||
expect(module.test).toEqual({ | ||
field: true, | ||
}) | ||
}) | ||
|
||
test("cannot import cjs, 'inlineImport' doesn't support CJS syntax at all", async () => { | ||
await expect(() => | ||
inlineImport<typeof import('./fixtures/inline-import/basic')>( | ||
fixture('cjs.js'), | ||
), | ||
).rejects.toThrow('module is not defined') | ||
}) | ||
|
||
test('can import vite config', async () => { | ||
const { module, dependencies } = await inlineImport< | ||
typeof import('./fixtures/inline-import/vite.config') | ||
>(fixture('vite.config')) | ||
expect(module.default).toEqual({ | ||
root: './test', | ||
plugins: [ | ||
{ | ||
name: 'test', | ||
}, | ||
], | ||
}) | ||
expect(dependencies).toEqual([fixture('plugin.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
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