Skip to content

Commit 934a240

Browse files
committed
test: add test
1 parent 7bc1020 commit 934a240

10 files changed

Lines changed: 141 additions & 62 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import test from '@vitejs/test-package'
2+
3+
function App() {
4+
return (
5+
<div>
6+
<h1>Node Modules Include Test</h1>
7+
<p>
8+
This playground tests that files in node_modules are processed
9+
correctly.
10+
</p>
11+
12+
<p className="result">Result: {'' + test}</p>
13+
</div>
14+
)
15+
}
16+
17+
export default App
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { expect, test } from 'vitest'
2+
import { page } from '~utils'
3+
4+
test('should render', async () => {
5+
expect(await page.textContent('h1')).toMatch('Node Modules Include Test')
6+
})
7+
8+
test('babel should run on files in node_modules', async () => {
9+
expect(await page.textContent('.result')).toMatch('Result: true')
10+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div id="app"></div>
2+
<script type="module">
3+
import React from 'react'
4+
import ReactDOM from 'react-dom/client'
5+
import App from './App.jsx'
6+
7+
ReactDOM.createRoot(document.getElementById('app')).render(
8+
React.createElement(App),
9+
)
10+
</script>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "@vitejs/test-node-modules-include",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vite build",
8+
"preview": "vite preview"
9+
},
10+
"dependencies": {
11+
"react": "^19.1.0",
12+
"react-dom": "^19.1.0"
13+
},
14+
"devDependencies": {
15+
"@types/babel__core": "^7.20.5",
16+
"@types/react": "^19.1.8",
17+
"@types/react-dom": "^19.1.6",
18+
"@vitejs/plugin-react": "workspace:*",
19+
"@vitejs/test-package": "file:./test-package"
20+
}
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default TEST_BABEL
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "test-package",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"type": "module"
6+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { defineConfig } from 'vite'
2+
import react from '@vitejs/plugin-react'
3+
import type { PluginItem as BabelPlugin } from '@babel/core'
4+
5+
export default defineConfig({
6+
plugins: [
7+
react({
8+
exclude: [/\/node_modules\/(?!(\.pnpm\/)?test-package)/],
9+
babel: {
10+
plugins: [
11+
({ types: t }): BabelPlugin => ({
12+
name: 'test-replace-test-babel',
13+
visitor: {
14+
Identifier(path) {
15+
if (path.node.name === 'TEST_BABEL') {
16+
path.replaceWith(t.booleanLiteral(true))
17+
}
18+
},
19+
},
20+
}),
21+
],
22+
},
23+
}),
24+
],
25+
optimizeDeps: {
26+
exclude: ['@vitejs/test-package'],
27+
},
28+
})

playground/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"preview": "vite preview"
1010
},
1111
"dependencies": {
12-
"jsx-entry": "file:./jsx-entry",
12+
"jsx-entry": "link:./jsx-entry",
1313
"react": "^19.1.0",
1414
"react-dom": "^19.1.0"
1515
},

pnpm-lock.yaml

Lines changed: 45 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ catalogs:
1010

1111
overrides:
1212
'@types/estree': ^1.0.8
13+
14+
dedupeInjectedDeps: false

0 commit comments

Comments
 (0)