11 | You’ve successfully created a project with
12 | Vite +
13 | Vue 3.
14 |
15 |
16 |
17 |
18 |
42 |
--------------------------------------------------------------------------------
/examples/vue-app-ts/src/components/TheWelcome.vue:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | Documentation
16 |
17 | Vue’s
18 | official documentation
19 | provides you with all information you need to get started.
20 |
21 |
22 |
23 |
24 |
25 |
26 | Tooling
27 |
28 | This project is served and bundled with
29 | Vite. The recommended IDE
30 | setup is VSCode +
31 | Volar. If you need to test
32 | your components and web pages, check out
33 | Cypress and
34 | Cypress Component Testing.
37 |
38 |
39 |
40 | More instructions are available in README.md.
41 |
42 |
43 |
44 |
45 |
46 |
47 | Ecosystem
48 |
49 | Get official tools and libraries for your project:
50 | Vuex,
51 | Vue Router,
52 | Vue Test Utils, and
53 | Vue Dev Tools. If you need more
54 | resources, we suggest paying
55 | Awesome Vue
56 | a visit.
57 |
58 |
59 |
60 |
61 |
62 |
63 | Community
64 |
65 | Got stuck? Ask your question on
66 | Vue Land, our official Discord server, or
67 | StackOverflow.
68 | You should also subscribe to
69 | our mailing list and follow the official
70 | @vuejs
71 | twitter account for latest news in the Vue world.
72 |
73 |
74 |
75 |
76 |
77 |
78 | Support Vue
79 |
80 | As an independent project, Vue relies on community backing for its sustainability. You can help
81 | us by
82 | becoming a sponsor.
83 |
84 |
85 |
--------------------------------------------------------------------------------
/examples/vue-app-ts/src/components/WelcomeItem.vue:
--------------------------------------------------------------------------------
1 |
2 |
14 | You’ve successfully created a project with
15 | Vite +
16 | Vue 3.
17 |
18 |
19 |
20 |
21 |
45 |
--------------------------------------------------------------------------------
/examples/vue-app-type-commonjs/src/components/TheWelcome.vue:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | Documentation
16 |
17 | Vue’s
18 | official documentation
19 | provides you with all information you need to get started.
20 |
21 |
22 |
23 |
24 |
25 |
26 | Tooling
27 |
28 | This project is served and bundled with
29 | Vite. The recommended IDE
30 | setup is VSCode +
31 | Volar. If you need to test
32 | your components and web pages, check out
33 | Cypress and
34 | Cypress Component Testing.
37 |
38 |
39 |
40 | More instructions are available in README.md.
41 |
42 |
43 |
44 |
45 |
46 |
47 | Ecosystem
48 |
49 | Get official tools and libraries for your project:
50 | Vuex,
51 | Vue Router,
52 | Vue Test Utils, and
53 | Vue Dev Tools. If you need more
54 | resources, we suggest paying
55 | Awesome Vue
56 | a visit.
57 |
58 |
59 |
60 |
61 |
62 |
63 | Community
64 |
65 | Got stuck? Ask your question on
66 | Vue Land, our official Discord server, or
67 | StackOverflow.
68 | You should also subscribe to
69 | our mailing list and follow the official
70 | @vuejs
71 | twitter account for latest news in the Vue world.
72 |
73 |
74 |
75 |
76 |
77 |
78 | Support Vue
79 |
80 | As an independent project, Vue relies on community backing for its sustainability. You can help
81 | us by
82 | becoming a sponsor.
83 |
84 |
85 |
--------------------------------------------------------------------------------
/examples/vue-app-type-commonjs/src/components/WelcomeItem.vue:
--------------------------------------------------------------------------------
1 |
2 |
14 | You’ve successfully created a project with
15 | Vite +
16 | Vue 3.
17 |
18 |
19 |
20 |
21 |
45 |
--------------------------------------------------------------------------------
/examples/vue-app-type-module/src/components/TheWelcome.vue:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | Documentation
16 |
17 | Vue’s
18 | official documentation
19 | provides you with all information you need to get started.
20 |
21 |
22 |
23 |
24 |
25 |
26 | Tooling
27 |
28 | This project is served and bundled with
29 | Vite. The recommended IDE
30 | setup is VSCode +
31 | Volar. If you need to test
32 | your components and web pages, check out
33 | Cypress and
34 | Cypress Component Testing.
37 |
38 |
39 |
40 | More instructions are available in README.md.
41 |
42 |
43 |
44 |
45 |
46 |
47 | Ecosystem
48 |
49 | Get official tools and libraries for your project:
50 | Vuex,
51 | Vue Router,
52 | Vue Test Utils, and
53 | Vue Dev Tools. If you need more
54 | resources, we suggest paying
55 | Awesome Vue
56 | a visit.
57 |
58 |
59 |
60 |
61 |
62 |
63 | Community
64 |
65 | Got stuck? Ask your question on
66 | Vue Land, our official Discord server, or
67 | StackOverflow.
68 | You should also subscribe to
69 | our mailing list and follow the official
70 | @vuejs
71 | twitter account for latest news in the Vue world.
72 |
73 |
74 |
75 |
76 |
77 |
78 | Support Vue
79 |
80 | As an independent project, Vue relies on community backing for its sustainability. You can help
81 | us by
82 | becoming a sponsor.
83 |
84 |
85 |
--------------------------------------------------------------------------------
/examples/vue-app-type-module/src/components/WelcomeItem.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
87 |
--------------------------------------------------------------------------------
/examples/vue-app-type-module/src/components/__tests__/HelloWorld.spec.js:
--------------------------------------------------------------------------------
1 | import { mount } from "@vue/test-utils";
2 | import HelloWorld from "../HelloWorld.vue";
3 |
4 | test("hellow world", async () => {
5 | const wrapper = mount(HelloWorld, { props: { msg: 'Hello vite-jest' } })
6 | expect(wrapper.html()).toMatch("Hello vite-jest");
7 | });
8 |
--------------------------------------------------------------------------------
/examples/vue-app-type-module/src/components/icons/IconCommunity.vue:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/examples/vue-app-type-module/src/components/icons/IconDocumentation.vue:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/examples/vue-app-type-module/src/components/icons/IconEcosystem.vue:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/examples/vue-app-type-module/src/components/icons/IconSupport.vue:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/examples/vue-app-type-module/src/components/icons/IconTooling.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
--------------------------------------------------------------------------------
/examples/vue-app-type-module/src/main.js:
--------------------------------------------------------------------------------
1 | import { createApp } from 'vue'
2 | import App from './App.vue'
3 |
4 | createApp(App).mount('#app')
5 |
--------------------------------------------------------------------------------
/examples/vue-app-type-module/vite.config.js:
--------------------------------------------------------------------------------
1 | import { fileURLToPath } from 'url'
2 |
3 | import { defineConfig } from 'vite'
4 | import vue from '@vitejs/plugin-vue'
5 | import vueJsx from '@vitejs/plugin-vue-jsx'
6 |
7 | // https://vitejs.dev/config/
8 | export default defineConfig({
9 | plugins: [vue(), vueJsx()],
10 | resolve: {
11 | alias: {
12 | '@': fileURLToPath(new URL('./src', import.meta.url))
13 | }
14 | }
15 | })
16 |
--------------------------------------------------------------------------------
/packages/vite-jest/README.md:
--------------------------------------------------------------------------------
1 | # vite-jest
2 |
3 | This package comes with a Jest transformer, a Jest reporter, a Jest preset, and a simple CLI wrapper of the `jest` command.
4 |
5 | Usage:
6 |
7 | 1. Add `preset: 'vite-jest'` to your Jest config.
8 | 2. Replace the `jest` CLI with `vite-jest`.
9 |
10 | ## Limitations and Differences with CommonJS tests
11 |
12 | Most are already documented in the official Jest documentation:
13 |
14 |
15 | ### The `jest` Object
16 |
17 | It's not automatically injected into each module. To access it, you must import it from `@jest/globals`: `import { jest } from '@jest/globals'`
18 |
19 | ### Mocking ES Modules
20 |
21 | Jest currently doesn't support jest.mock in a clean way in ESM.
22 |
23 | There's now an experimental API (`jest.unstable_mockModule`) for this, but you must use it in combination with top-level await and dynamic imports:
24 |
25 | ```js
26 | // Note that jest must be explicitly imported
27 | import { jest } from '@jest/globals';
28 |
29 | const mockPlaySoundFile = jest.fn();
30 | jest.unstable_mockModule('./sound-player', () => {
31 | return {default: jest.fn().mockImplementation(() => {
32 | return { playSoundFile: mockPlaySoundFile };
33 | })};
34 | });
35 |
36 | // Note that the mocked module must be dynamically imported
37 | const {default: SoundPlayer} = await import('./sound-player');
38 | const {default: SoundPlayerConsumer} = await import('./sound-player-consumer');
39 |
40 | beforeEach(() => {
41 | SoundPlayer.mockClear();
42 | mockPlaySoundFile.mockClear();
43 | });
44 | ```
45 |
46 | Follow [this issue](https://github.com/facebook/jest/issues/10025) for updates.
47 |
48 | ### Doesn't Support Windows (yet)
49 |
50 | We are actively working on that. It may be supported in a patch release.
51 |
52 | ### Coverage Report May be broken
53 |
54 | We are not very sure how to fix this. Any help is appreciated.
55 |
56 | ---
57 |
58 | ## `vite-jest` Internals
59 |
60 | ### The Transformer
61 |
62 | The transformer pass custom file formats such as `.vue`, `.jsx` to vite for transformation.
63 |
64 | It also enables Vite-specific syntax extensions such as `import.meta.glob`, `import.meta.env`, etc. (still work-in-progress)
65 |
66 | Jest doesn't support asynchronous resolver yet ().
67 | Therefore, module paths can't be resolved via the Vite server, making a few Vite-specific paths (such as `/@vite/client` and `/@vite/env`, injected by Vite core plugins) unresolvable.
68 |
69 | So we have to workaround this issue in the transformer, with the help of [`es-module-lexer`](https://www.npmjs.com/package/es-module-lexer)
70 |
71 | Virtual files injected by Vite / Rollup plugins are writtern to the `./node_modules/.vite-jest-cache` directory.
72 |
73 | Note that React fast refresh is not supported at the moment. You need to disable this feature during testing (when `process.env.NODE_ENV === 'test'`).
74 |
75 | ### The Reporter
76 |
77 | Only a Jest reporter can get the signal that all tests are done, so a custom reporter (`'vite-jest/reporter.cjs'`) is also required to correctly shutdown the Vite server after testing.
78 |
79 | ### The Preset
80 |
81 | It helps simplify the configuration process by including most essential options.
82 |
83 | Besides from configuring the transformer and reporter:
84 |
85 | * `.jsx` and `.vue` must be treated as ES module to be processed by an async transformer (that is, the `vite-jest` transformer).
86 | * The Vite cache directory (`node_modules/.vite`) must also be processed by the transformer.
87 | * Assets and style files are stubbed.
88 |
89 | ### The `vite-jest` Command
90 |
91 | * Jest requries the `--experimental-vm-modules` flag of Node.js to be turned on to support ES module transformation. The `vite-jest` command turns it on by default.
92 | * All tests must be run serially, because both Vite and `vite-jest` use caches heavily, paralleriazation may cause race conditions. So `vite-jest` automatically passes a `--runInBand` to the underlying `jest` command.
93 | * A `--no-cache` argument is also passed to fix some edge cases. Since Vite transformation is ususally very fast, the performance penalty of not caching is negligible.
94 |
95 | ## TODOs
96 |
97 | * Better source map
98 | * Clean up the console output
99 |
--------------------------------------------------------------------------------
/packages/vite-jest/bin/vite-jest.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import execa from 'execa'
4 | import { createRequire } from 'module'
5 |
6 | const require = createRequire(import.meta.url)
7 | const jestPath = require.resolve('jest/bin/jest')
8 |
9 | const additionalArgs = process.argv.slice(2)
10 | if (!additionalArgs.includes('--runInBand') && !additionalArgs.includes('-i')) {
11 | additionalArgs.push('--runInBand')
12 | }
13 |
14 | if(!additionalArgs.includes('--no-cache')) {
15 | additionalArgs.push('--no-cache')
16 | }
17 |
18 | execa.sync('node', [
19 | '--experimental-vm-modules',
20 | jestPath,
21 | ...additionalArgs
22 | ], {
23 | stdio: 'inherit'
24 | })
25 |
--------------------------------------------------------------------------------
/packages/vite-jest/index.js:
--------------------------------------------------------------------------------
1 | import fs from 'fs'
2 | import path from 'path'
3 |
4 | import { parse } from 'es-module-lexer'
5 | import MagicString from 'magic-string'
6 |
7 | import viteServer from './vite-server.js'
8 | import {
9 | slashOnWindows,
10 |
11 | FS_PREFIX,
12 | fsPathFromId,
13 |
14 | isVirtualFileRequest,
15 | virtualPathToFsPath
16 | } from './pathUtils.js'
17 |
18 | async function processAsync(src, filepath) {
19 | // We need the timestamp because in the case `jest --watch`
20 | // the same vite server instance will be used.
21 | // So we need to make sure we don't use the previous cached result.
22 | const filepathForTransform = `${filepath}?${Date.now()}`
23 | let result = await viteServer.transformRequest(filepathForTransform)
24 |
25 | // not sure if this is reliable
26 | while (viteServer._pendingReload) {
27 | await viteServer._pendingReload
28 | result = await viteServer.transformRequest(filepathForTransform)
29 | }
30 |
31 | if (!result) {
32 | throw new Error(`Failed to load module ${filepath}`)
33 | }
34 |
35 | // The following logic is better to be placed in an async jest resolver
36 | const mStr = new MagicString(result.code)
37 | const [imports] = await parse(result.code)
38 | for (let index = 0; index < imports.length; index++) {
39 | let {
40 | s: start,
41 | e: end,
42 | ss: expStart,
43 | d: dynamicIndex,
44 | n: url
45 | } = imports[index]
46 |
47 | if (!url) {
48 | // will this really happen?
49 | continue
50 | }
51 |
52 | // when parsing dynamic imports, the starting and ending quotes are also included
53 | // note here we don't care about the case where the url is a variable
54 | // because Vite doesn't allow fully-dynamic imports.
55 | // They must be a string.
56 | if (dynamicIndex > -1) {
57 | start += 1
58 | end -= 1
59 | }
60 |
61 | // even though we use a plugin to avoid resolving this module to its actual entry
62 | // vite still adds a `/@id/` prefix
63 | // so we must use `endsWith` instead of `===`
64 | if (url.endsWith('@jest/globals')) {
65 | mStr.overwrite(start, end, '@jest/globals')
66 | continue
67 | }
68 |
69 | if (url.startsWith(FS_PREFIX)) {
70 | mStr.overwrite(
71 | start,
72 | end,
73 | `./${path.posix.relative(path.dirname(filepath), fsPathFromId(url))}`
74 | )
75 | continue
76 | }
77 |
78 | if (isVirtualFileRequest(url)) {
79 | const virtualFilePath = virtualPathToFsPath(url)
80 |
81 | if (!fs.existsSync(virtualFilePath)) {
82 | const { code } = await viteServer.transformRequest(url.replace(/^\/@id\//, ''))
83 | fs.writeFileSync(virtualFilePath, code)
84 | }
85 |
86 | mStr.overwrite(
87 | start,
88 | end,
89 | `./${path.posix.relative(path.dirname(filepath), virtualFilePath)}`
90 | )
91 | continue
92 | }
93 |
94 | if (url.startsWith('/')) {
95 | const projectFilePath = slashOnWindows(path.join(viteServer.config.root, url))
96 | const relativePath = `./${path.posix.relative(path.dirname(filepath), projectFilePath)}`
97 |
98 | mStr.overwrite(
99 | start,
100 | end,
101 | relativePath
102 | )
103 | continue
104 | }
105 | }
106 |
107 | return {
108 | code: mStr.toString(),
109 | // TODO: use `@cush/sorcery` to merge source map of the magic string
110 | map: result.map
111 | }
112 | }
113 |
114 | export default {
115 | processAsync,
116 |
117 | // It is necessary because we use vite-jest to tranform everything,
118 | // we'll inevitably encounter some CommonJS modules.
119 | process: src => src
120 | }
121 |
--------------------------------------------------------------------------------
/packages/vite-jest/jest-preset.js:
--------------------------------------------------------------------------------
1 | import os from 'os'
2 | import { createRequire } from 'module'
3 |
4 | const require = createRequire(import.meta.url)
5 |
6 | const isWindows = os.platform() === 'win32'
7 | const resolveRelative = url => (new URL(url, import.meta.url)).pathname.substr(isWindows ? 1 : 0)
8 |
9 | export default {
10 | moduleFileExtensions: ['js', 'json', 'jsx', 'mjs', 'svelte', 'ts', 'tsx', 'vue'],
11 | extensionsToTreatAsEsm: ['.jsx', '.svelte', '.ts', '.tsx', '.vue'],
12 |
13 | transform: {
14 | "^.+\\.(js|json|jsx|mjs|svelte|ts|tsx|vue)$": resolveRelative('./index.js'),
15 | },
16 | transformIgnorePatterns: [
17 | '!/node_modules/\\.vite/',
18 | ],
19 |
20 | moduleNameMapper: {
21 | '.+\\.(css|styl|less|sass|scss|jpg|jpeg|png|svg|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|avif)$':
22 | require.resolve('jest-transform-stub'),
23 | },
24 |
25 | reporters: [
26 | 'default',
27 | resolveRelative('./reporter.cjs')
28 | ],
29 | }
30 |
--------------------------------------------------------------------------------
/packages/vite-jest/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vite-jest",
3 | "version": "0.1.4",
4 | "description": "A Jest transformer that enables first-class Vite integration",
5 | "type": "module",
6 | "exports": {
7 | "./": "./index.js",
8 | "./jest-preset": "./jest-preset.cjs",
9 | "./reporter": "./reporter.cjs"
10 | },
11 | "bin": "bin/vite-jest.js",
12 | "scripts": {
13 | "test": "pnpm --filter ../../examples --filter ../../playground -r exec -- pnpm run test:unit"
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "https://github.com/sodatea/vite-jest.git",
18 | "directory": "packages/vite-jest"
19 | },
20 | "author": "Haoqun Jiang ",
21 | "license": "MIT",
22 | "peerDependencies": {
23 | "jest": "^27.0.0",
24 | "vite": "^2.4.2"
25 | },
26 | "devDependencies": {
27 | "jest": "^27.4.3",
28 | "vite": "^2.6.14"
29 | },
30 | "dependencies": {
31 | "es-module-lexer": "^0.6.0",
32 | "execa": "^5.1.1",
33 | "jest-transform-stub": "^2.0.0",
34 | "magic-string": "^0.25.7",
35 | "slash": "^4.0.0"
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/packages/vite-jest/pathUtils.js:
--------------------------------------------------------------------------------
1 | import os from 'os'
2 | import path from 'path'
3 |
4 | import slash from 'slash'
5 |
6 | import { viteJestCacheDirctory } from './vite-server.js'
7 |
8 | export function isVirtualFileRequest(requestUrl) {
9 | // Rollup plugin internals
10 | if (requestUrl.startsWith('\0')) {
11 | return true
12 | }
13 |
14 | // Vite plugin conventions
15 | if (requestUrl.startsWith('virtual:')) {
16 | return true
17 | }
18 |
19 | // Vite internal
20 | // https://github.com/vitejs/vite/blob/49f28e23cae0ad588fc89374918d3a5e942c5075/packages/vite/src/node/plugins/importAnalysis.ts#L233-L239
21 | if (requestUrl.startsWith('/@id/')) {
22 | return true
23 | }
24 |
25 | // Vite internals
26 | if (requestUrl === '/@vite/client' || requestUrl === '/@vite/env') {
27 | return true
28 | }
29 |
30 | // @vitejs/plugin-vue
31 | if (requestUrl.includes(':')) {
32 | return true
33 | }
34 |
35 | if (requestUrl.startsWith('/@react-refresh')) {
36 | return true
37 | }
38 |
39 | // SvelteKit
40 | if (requestUrl.startsWith('$app/')) {
41 | return true
42 | }
43 |
44 | return false
45 | }
46 |
47 | export function virtualPathToFsPath(virtualPath) {
48 | return path.resolve(
49 | viteJestCacheDirctory,
50 | virtualPath.replace('\0', '__x00__')
51 | .replace(/\//g, '__slash__')
52 | .replace(/\$/g, '__dollar__')
53 | .replace(/\:/g, '__colon__')
54 | + '.js'
55 | )
56 | }
57 |
58 |
59 | const isWindows = os.platform() === 'win32'
60 | const VOLUME_RE = /^[A-Z]:/i
61 |
62 | export const FS_PREFIX = `/@fs/`
63 |
64 | export const slashOnWindows = path => isWindows ? slash(path) : path
65 |
66 | function normalizePath(id) {
67 | return path.posix.normalize(slashOnWindows(id))
68 | }
69 |
70 | export function fsPathFromId(id) {
71 | const fsPath = normalizePath(id.slice(FS_PREFIX.length))
72 | return fsPath.startsWith('/') || fsPath.match(VOLUME_RE)
73 | ? fsPath
74 | : `/${fsPath}`
75 | }
76 |
--------------------------------------------------------------------------------
/packages/vite-jest/reporter.cjs:
--------------------------------------------------------------------------------
1 |
2 | module.exports = class MyCustomReporter {
3 | async onRunComplete() {
4 | const viteServer = (await import('./vite-server.js')).default
5 | await viteServer.close()
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/packages/vite-jest/vite-server.js:
--------------------------------------------------------------------------------
1 | import fs from 'fs'
2 | import path from 'path'
3 | import { createServer } from 'vite'
4 |
5 | const viteServer = await createServer({
6 | base: '/',
7 | server: {
8 | hmr: false,
9 | middlewareMode: true,
10 | },
11 | resolve: {
12 | alias: {
13 | // For similar reasons as in https://github.com/cypress-io/cypress/blob/570f91dde3a8bd54fd059e1cfe0f85bab8f1a7cb/npm/vite-dev-server/src/startServer.ts#L35-L37
14 | vue: 'vue/dist/vue.esm-bundler.js',
15 | '@vue/compiler-core': '@vue/compiler-core/dist/compiler-core.cjs.js',
16 | '@vue/test-utils': '@vue/test-utils/dist/vue-test-utils.cjs.js',
17 | }
18 | },
19 |
20 | // `@jest/globals` must be kept-as-is
21 | // https://github.com/facebook/jest/blob/3093c18c428d962eb959437b322c6a5b0ae0e7a2/packages/jest-runtime/src/index.ts#L544-L554
22 | optimizeDeps: {
23 | exclude: ['@jest/globals']
24 | },
25 | plugins: [
26 | {
27 | resolveId(id) {
28 | if (id === '@jest/globals') {
29 | return id
30 | }
31 | },
32 | enforce: 'pre'
33 | }
34 | ]
35 | })
36 |
37 | // A cache directory for virtual modules
38 | const viteJestCacheDirctory = path.resolve(viteServer.config.cacheDir, '../.vite-jest-cache')
39 | if (!fs.existsSync(viteJestCacheDirctory)) {
40 | fs.mkdirSync(viteJestCacheDirctory)
41 | }
42 | fs.writeFileSync(path.join(viteJestCacheDirctory, 'package.json'), JSON.stringify({ type: "module" }))
43 |
44 |
45 | export default viteServer
46 | export { viteJestCacheDirctory }
47 |
--------------------------------------------------------------------------------
/playground/alias/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 | dist
4 | dist-ssr
5 | *.local
--------------------------------------------------------------------------------
/playground/alias/__tests__/index.spec.js:
--------------------------------------------------------------------------------
1 | import { msg } from '@/test.js'
2 |
3 | test('should support alias config in vite.config.js', () => {
4 | expect(msg).toBe('success')
5 | })
6 |
--------------------------------------------------------------------------------
/playground/alias/dir/test.js:
--------------------------------------------------------------------------------
1 | export const msg = `success`
2 |
--------------------------------------------------------------------------------
/playground/alias/favicon.svg:
--------------------------------------------------------------------------------
1 |
16 |
--------------------------------------------------------------------------------
/playground/alias/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Vite App
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/playground/alias/jest.config.js:
--------------------------------------------------------------------------------
1 | export default {
2 | preset: 'vite-jest',
3 |
4 | testMatch: [
5 | '**/tests/unit/**/*.spec.?(m)js?(x)',
6 | '**/__tests__/*.?(m)js?(x)'
7 | ],
8 | testEnvironment: 'jest-environment-jsdom'
9 | }
10 |
--------------------------------------------------------------------------------
/playground/alias/main.js:
--------------------------------------------------------------------------------
1 | import './style.css'
2 |
3 | document.querySelector('#app').innerHTML = `
4 |