mirror of
https://github.com/hanzoai/vitest.git
synced 2026-09-24 17:04:25 +00:00
chore: migrate to flat eslint config (#4472)
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
dist
|
||||
html
|
||||
bench.json
|
||||
node_modules
|
||||
*.svelte
|
||||
*.snap
|
||||
*.d.ts
|
||||
coverage
|
||||
!.vitepress
|
||||
docs/**/migration.md
|
||||
docs/.vitepress/cache/deps/*.*
|
||||
test/core/src/self
|
||||
test/workspaces/results.json
|
||||
test/reporters/fixtures/with-syntax-error.test.js
|
||||
@@ -1,60 +0,0 @@
|
||||
{
|
||||
"extends": "@antfu",
|
||||
"rules": {
|
||||
"no-only-tests/no-only-tests": "off",
|
||||
// prefer global Buffer to not initialize the whole module
|
||||
"n/prefer-global/buffer": "off",
|
||||
"@typescript-eslint/no-invalid-this": "off",
|
||||
"@typescript-eslint/quotes": ["error", "single", {
|
||||
"allowTemplateLiterals": true
|
||||
}],
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
{
|
||||
"paths": ["path"]
|
||||
}
|
||||
],
|
||||
"no-empty-pattern": "off",
|
||||
"import/no-named-as-default": "off",
|
||||
"no-cond-assign": "off"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": "packages/**/*.*",
|
||||
"rules": {
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
{
|
||||
"paths": ["vitest", "path"]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
// these files define vitest as peer dependency
|
||||
"files": "packages/{coverage-*,ui,browser,web-worker}/**/*.*",
|
||||
"rules": {
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
{
|
||||
"paths": ["path"]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["docs/**", "packages/web-worker/**", "test/web-worker/**"],
|
||||
"rules": {
|
||||
"no-restricted-globals": "off",
|
||||
"import/first": "off"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["packages/vite-node/**"],
|
||||
"rules": {
|
||||
// false positive on "exports" variable
|
||||
"antfu/no-cjs-exports": "off"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -31,6 +31,8 @@
|
||||
"@types/chai",
|
||||
"@sinonjs/fake-timers",
|
||||
// TODO: update when chai is updated to 5.0
|
||||
"loupe"
|
||||
"loupe",
|
||||
// we update types for node when we bump the minimal version
|
||||
"@types/node"
|
||||
]
|
||||
}
|
||||
|
||||
Vendored
+38
-6
@@ -3,12 +3,44 @@
|
||||
"birpc",
|
||||
"unmock"
|
||||
],
|
||||
|
||||
// Enable the ESlint flat config support
|
||||
"eslint.experimental.useFlatConfig": true,
|
||||
|
||||
// Disable the default formatter, use eslint instead
|
||||
"prettier.enable": false,
|
||||
"editor.formatOnSave": false,
|
||||
"[json]": {
|
||||
"editor.formatOnSave": false
|
||||
|
||||
// Auto fix
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true,
|
||||
"source.organizeImports": false
|
||||
},
|
||||
"[markdown]": {
|
||||
"editor.formatOnSave": false
|
||||
},
|
||||
"prettier.enable": false
|
||||
|
||||
// Silent the stylistic rules in you IDE, but still auto fix them
|
||||
// "eslint.rules.customizations": [
|
||||
// { "rule": "style/*", "severity": "off" },
|
||||
// { "rule": "*-indent", "severity": "off" },
|
||||
// { "rule": "*-spacing", "severity": "off" },
|
||||
// { "rule": "*-spaces", "severity": "off" },
|
||||
// { "rule": "*-order", "severity": "off" },
|
||||
// { "rule": "*-dangle", "severity": "off" },
|
||||
// { "rule": "*-newline", "severity": "off" },
|
||||
// { "rule": "*quotes", "severity": "off" },
|
||||
// { "rule": "*semi", "severity": "off" }
|
||||
// ],
|
||||
|
||||
// Enable eslint for all supported languages
|
||||
"eslint.validate": [
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"typescript",
|
||||
"typescriptreact",
|
||||
"vue",
|
||||
"html",
|
||||
"markdown",
|
||||
"json",
|
||||
"jsonc",
|
||||
"yaml"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ import {
|
||||
ogUrl,
|
||||
releases,
|
||||
twitter,
|
||||
vitestDescription, vitestName,
|
||||
vitestDescription,
|
||||
vitestName,
|
||||
} from './meta'
|
||||
import { pwa } from './scripts/pwa'
|
||||
import { transformHead } from './scripts/transformHead'
|
||||
|
||||
+2
-1
@@ -791,7 +791,8 @@ test('Server started successfully', async () => {
|
||||
throw new Error('Server not started')
|
||||
|
||||
console.log('Server started')
|
||||
}, {
|
||||
},
|
||||
{
|
||||
timeout: 500, // default is 1000
|
||||
interval: 20, // default is 50
|
||||
}
|
||||
|
||||
@@ -966,6 +966,9 @@ Beware that the global setup is running in a different global scope, so your tes
|
||||
export default function setup({ provide }) {
|
||||
provide('wsPort', 3000)
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
// example.test.js
|
||||
import { inject } from 'vitest'
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ If you want to modify the object, you will use [replaceProperty API](https://jes
|
||||
|
||||
From Vitest v0.10.0, the callback style of declaring tests is deprecated. You can rewrite them to use `async`/`await` functions, or use Promise to mimic the callback style.
|
||||
|
||||
```ts
|
||||
```
|
||||
it('should work', (done) => { // [!code --]
|
||||
it('should work', () => new Promise(done => { // [!code ++]
|
||||
// ...
|
||||
|
||||
+12
-12
@@ -1,26 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"jsx": "preserve",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"baseUrl": ".",
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "node",
|
||||
"paths": {
|
||||
"~/*": ["src/*"]
|
||||
},
|
||||
"resolveJsonModule": true,
|
||||
"noUnusedLocals": true,
|
||||
"strictNullChecks": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"types": [
|
||||
"vite/client",
|
||||
"vite-plugin-pwa/client",
|
||||
"vitepress"
|
||||
],
|
||||
"paths": {
|
||||
"~/*": ["src/*"]
|
||||
}
|
||||
"strict": true,
|
||||
"strictNullChecks": true,
|
||||
"noUnusedLocals": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": [
|
||||
"./*.ts",
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import antfu, { GLOB_SRC } from '@antfu/eslint-config'
|
||||
|
||||
export default antfu(
|
||||
{
|
||||
// Disable tests rules because we need to test with various setup
|
||||
test: false,
|
||||
// This replaces the old `.gitignore`
|
||||
ignores: [
|
||||
'**/coverage',
|
||||
'**/*.snap',
|
||||
'**/bench.json',
|
||||
'**/fixtures',
|
||||
'test/core/src/self',
|
||||
'test/workspaces/results.json',
|
||||
'test/reporters/fixtures/with-syntax-error.test.js',
|
||||
'examples/**/mockServiceWorker.js',
|
||||
],
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
// prefer global Buffer to not initialize the whole module
|
||||
'node/prefer-global/buffer': 'off',
|
||||
'node/prefer-global/process': 'off',
|
||||
'no-empty-pattern': 'off',
|
||||
|
||||
'ts/no-invalid-this': 'off',
|
||||
|
||||
// TODO: migrate and turn it back on
|
||||
'ts/ban-types': 'off',
|
||||
|
||||
'no-restricted-imports': [
|
||||
'error',
|
||||
{
|
||||
paths: ['path'],
|
||||
},
|
||||
],
|
||||
|
||||
'import/no-named-as-default': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: [`packages/${GLOB_SRC}`],
|
||||
rules: {
|
||||
'no-restricted-imports': [
|
||||
'error',
|
||||
{
|
||||
paths: ['vitest', 'path'],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
// these files define vitest as peer dependency
|
||||
files: [`packages/{coverage-*,ui,browser,web-worker}/${GLOB_SRC}`],
|
||||
rules: {
|
||||
'no-restricted-imports': [
|
||||
'error',
|
||||
{
|
||||
paths: ['path'],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: [
|
||||
`docs/${GLOB_SRC}`,
|
||||
],
|
||||
rules: {
|
||||
'style/max-statements-per-line': 'off',
|
||||
'import/newline-after-import': 'off',
|
||||
'import/first': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: [
|
||||
`docs/${GLOB_SRC}`,
|
||||
`packages/web-worker/${GLOB_SRC}`,
|
||||
`test/web-worker/${GLOB_SRC}`,
|
||||
],
|
||||
rules: {
|
||||
'no-restricted-globals': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: [`packages/vite-node/${GLOB_SRC}`],
|
||||
rules: {
|
||||
// false positive on "exports" variable
|
||||
'antfu/no-cjs-exports': 'off',
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "node16",
|
||||
"target": "es2020",
|
||||
"module": "node16",
|
||||
"strict": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true,
|
||||
"declarationMap": true
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"include": ["src", "test"],
|
||||
"exclude": ["node_modules"]
|
||||
|
||||
@@ -2,21 +2,17 @@ const usersData = [{
|
||||
id: 1,
|
||||
name: 'John Snow',
|
||||
email: '[email protected]',
|
||||
},
|
||||
{
|
||||
}, {
|
||||
id: 2,
|
||||
name: 'Daenerys Targaryen',
|
||||
email: '[email protected]',
|
||||
},
|
||||
{
|
||||
}, {
|
||||
id: 3,
|
||||
name: 'Arya Stark',
|
||||
email: '[email protected]',
|
||||
},
|
||||
{
|
||||
}, {
|
||||
id: 4,
|
||||
name: 'Rhaenyra Targaryen',
|
||||
email: '[email protected]',
|
||||
},
|
||||
]
|
||||
}]
|
||||
export { usersData }
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "node16",
|
||||
"target": "es2020",
|
||||
"moduleResolution": "Node16",
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"experimentalDecorators": true,
|
||||
"module": "node16",
|
||||
"moduleResolution": "Node16",
|
||||
"verbatimModuleSyntax": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "NodeNext",
|
||||
"target": "esnext",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "nodenext",
|
||||
"types": ["vitest/globals"]
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
"@types/react": "latest",
|
||||
"@vitejs/plugin-react": "latest",
|
||||
"jsdom": "latest",
|
||||
"typescript": "^4.8.4",
|
||||
"typescript": "^5.2.2",
|
||||
"vitest": "latest"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { NextPage } from 'next'
|
||||
import Head from 'next/head'
|
||||
import Image from 'next/image'
|
||||
|
||||
const Home: NextPage = () =>
|
||||
const Home: NextPage = () => (
|
||||
<>
|
||||
<Head>
|
||||
<title>Create Next App</title>
|
||||
@@ -21,7 +21,8 @@ const Home: NextPage = () =>
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Powered by{' '}
|
||||
Powered by
|
||||
{' '}
|
||||
<span>
|
||||
<Image src="https://assets.vercel.com/image/upload/q_auto/front/favicon/vercel/57x57.png" alt="Vercel Logo" width={72} height={16} />
|
||||
</span>
|
||||
@@ -29,5 +30,6 @@ const Home: NextPage = () =>
|
||||
</footer>
|
||||
</main>
|
||||
</>
|
||||
)
|
||||
|
||||
export default Home
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"target": "es6",
|
||||
"jsx": "preserve",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"allowJs": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"@testing-library/preact": "^3.2.3",
|
||||
"@vitest/ui": "latest",
|
||||
"less": "^4.1.3",
|
||||
"typescript": "^4.8.4",
|
||||
"typescript": "^5.2.2",
|
||||
"vite": "latest",
|
||||
"vitest": "latest"
|
||||
}
|
||||
|
||||
@@ -13,6 +13,6 @@ describe('Preact Demo Test Suite', () => {
|
||||
it('click event', async () => {
|
||||
render(<BrowserRouter><App /></BrowserRouter>)
|
||||
fireEvent.click(screen.getByRole('button'))
|
||||
expect(await screen.findByText(/count is: 1/i)).toBeInTheDocument()
|
||||
expect(await screen.findByText(/count is:\s*1/i)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,11 +5,14 @@ export default function App() {
|
||||
const { count, inc } = useCount()
|
||||
|
||||
return (
|
||||
<div class="app">
|
||||
<div className="app">
|
||||
<header>
|
||||
<h1>Hello Vite & Preact!</h1>
|
||||
<p>
|
||||
<button onClick={inc}>Count is: {count}</button>
|
||||
<button onClick={inc}>
|
||||
Count is:
|
||||
{count}
|
||||
</button>
|
||||
</p>
|
||||
<p>
|
||||
<a
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "preserve",
|
||||
"jsxFactory": "h",
|
||||
"jsxFragmentFactory": "Fragment",
|
||||
"types": ["vitest/globals"]
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"types": ["vitest/globals"],
|
||||
"allowJs": false,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": false,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"isolatedModules": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
"references": [{ "path": "./tsconfig.node.json" }],
|
||||
"include": ["src"]
|
||||
}
|
||||
|
||||
@@ -66,8 +66,7 @@ function Providers({ children, history, route, swrCache }: ProvidersProps) {
|
||||
return Wrapper
|
||||
}
|
||||
|
||||
function renderWithProviders(ui: React.ReactElement,
|
||||
options: ProviderOptions = {}) {
|
||||
function renderWithProviders(ui: React.ReactElement, options: ProviderOptions = {}) {
|
||||
const { initialEntries = [], route, ...rest } = options
|
||||
const history = createMemoryHistory({ initialEntries })
|
||||
const swrCache = new Map(cache)
|
||||
@@ -83,12 +82,11 @@ function renderWithProviders(ui: React.ReactElement,
|
||||
|
||||
return {
|
||||
...rtl,
|
||||
rerender: (ui: React.ReactElement, rerenderOptions?: ProviderOptions) =>
|
||||
renderWithProviders(ui, {
|
||||
container: rtl.container,
|
||||
...options,
|
||||
...rerenderOptions,
|
||||
}),
|
||||
rerender: (ui: React.ReactElement, rerenderOptions?: ProviderOptions) => renderWithProviders(ui, {
|
||||
container: rtl.container,
|
||||
...options,
|
||||
...rerenderOptions,
|
||||
}),
|
||||
history,
|
||||
swrCache,
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"types": ["vitest/globals"],
|
||||
"allowJs": false,
|
||||
"strict": true,
|
||||
"useUnknownInCatchVariables": false,
|
||||
"noEmit": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": false,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"noEmit": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": false,
|
||||
"strict": true,
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"useUnknownInCatchVariables": false,
|
||||
"types": ["vitest/globals"]
|
||||
"skipLibCheck": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { DecoratorFn } from '@storybook/react'
|
||||
// Disable `react-query` error logging
|
||||
setLogger({
|
||||
error: () => {},
|
||||
// eslint-disable-next-line no-console
|
||||
log: (...params) => console.log(...params),
|
||||
warn: (...params) => console.warn(...params),
|
||||
})
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
"jsdom": "latest",
|
||||
"msw": "^0.49.2",
|
||||
"msw-storybook-addon": "^1.6.3",
|
||||
"typescript": "^4.8.4",
|
||||
"typescript": "^5.2.2",
|
||||
"vite": "latest",
|
||||
"vitest": "latest"
|
||||
},
|
||||
|
||||
@@ -16,9 +16,7 @@ export const Loading = Template.bind({})
|
||||
Loading.parameters = {
|
||||
msw: {
|
||||
handlers: [
|
||||
rest.get('https://jsonplaceholder.typicode.com/posts', (req, res, ctx) =>
|
||||
res(ctx.delay('infinite')),
|
||||
),
|
||||
rest.get('https://jsonplaceholder.typicode.com/posts', (req, res, ctx) => res(ctx.delay('infinite'))),
|
||||
],
|
||||
},
|
||||
}
|
||||
@@ -39,9 +37,7 @@ export const Error = Template.bind({})
|
||||
Error.parameters = {
|
||||
msw: {
|
||||
handlers: [
|
||||
rest.get('https://jsonplaceholder.typicode.com/posts', (req, res, ctx) =>
|
||||
res(ctx.status(500)),
|
||||
),
|
||||
rest.get('https://jsonplaceholder.typicode.com/posts', (req, res, ctx) => res(ctx.status(500))),
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"types": ["vitest/globals"],
|
||||
"allowJs": false,
|
||||
"strict": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"types": ["vitest/globals"]
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"isolatedModules": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["./src", "./.storybook"]
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ import App from './App'
|
||||
import { posts } from './mocks/handlers'
|
||||
|
||||
it('Should return posts when clicking fetch button', async () => {
|
||||
render(<ApolloProvider client={client}>
|
||||
<App />
|
||||
</ApolloProvider>)
|
||||
render(
|
||||
<ApolloProvider client={client}>
|
||||
<App />
|
||||
</ApolloProvider>,
|
||||
)
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'MSW Testing Library Example', level: 1 })).toBeDefined()
|
||||
|
||||
@@ -20,9 +22,11 @@ it('Should return posts when clicking fetch button', async () => {
|
||||
})
|
||||
|
||||
it('Should return posts when clicking fetch with graphql button', async () => {
|
||||
render(<ApolloProvider client={client}>
|
||||
<App />
|
||||
</ApolloProvider>)
|
||||
render(
|
||||
<ApolloProvider client={client}>
|
||||
<App />
|
||||
</ApolloProvider>,
|
||||
)
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'MSW Testing Library Example', level: 1 })).toBeDefined()
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable import/export */
|
||||
import { render } from '@testing-library/react'
|
||||
|
||||
function customRender(ui: React.ReactElement, options = {}) {
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": false,
|
||||
"esModuleInterop": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"types": ["vitest/globals"],
|
||||
"allowJs": false,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"types": ["vitest/globals"]
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": false,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"isolatedModules": true,
|
||||
"skipLibCheck": false
|
||||
},
|
||||
"include": ["./src"]
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"@vitest/coverage-v8": "latest",
|
||||
"@vitest/ui": "latest",
|
||||
"jsdom": "latest",
|
||||
"typescript": "^4.8.4",
|
||||
"typescript": "^5.2.2",
|
||||
"vite": "latest",
|
||||
"vitest": "latest"
|
||||
},
|
||||
|
||||
@@ -13,11 +13,17 @@ function App() {
|
||||
type="button"
|
||||
onClick={increment}
|
||||
>
|
||||
count is: {count}
|
||||
count is:
|
||||
{' '}
|
||||
{count}
|
||||
</button>
|
||||
</p>
|
||||
<p>
|
||||
Edit <code>App.tsx</code> and save to test HMR updates.
|
||||
Edit
|
||||
{' '}
|
||||
<code>App.tsx</code>
|
||||
{' '}
|
||||
and save to test HMR updates.
|
||||
</p>
|
||||
<p>
|
||||
<a
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable import/export */
|
||||
import { cleanup, render } from '@testing-library/react'
|
||||
import { afterEach } from 'vitest'
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": false,
|
||||
"esModuleInterop": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"types": ["vitest/globals"],
|
||||
"allowJs": false,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"types": ["vitest/globals"]
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": false,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"isolatedModules": true,
|
||||
"skipLibCheck": false
|
||||
},
|
||||
"include": ["./src"]
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"jsx": "react",
|
||||
"module": "node16",
|
||||
"moduleResolution": "node16",
|
||||
"esModuleInterop": true,
|
||||
"types": ["vitest/globals"]
|
||||
"types": ["vitest/globals"],
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ import { createSignal } from 'solid-js'
|
||||
|
||||
export function Hello(props) {
|
||||
const [times, setTimes] = createSignal(2)
|
||||
return <>
|
||||
<div>{`${props.count} x ${times()} = ${props.count * times()}`}</div>
|
||||
<button onClick={() => setTimes(t => t + 1)}>x1</button>
|
||||
</>
|
||||
return (
|
||||
<>
|
||||
<div>{`${props.count} x ${times()} = ${props.count * times()}`}</div>
|
||||
<button onClick={() => setTimes(t => t + 1)}>x1</button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"svelte": "^3.59.1",
|
||||
"svelte-check": "^3.4.3",
|
||||
"tslib": "^2.5.3",
|
||||
"typescript": "^5.1.3",
|
||||
"typescript": "^5.2.2",
|
||||
"vite": "^5.0.0-beta.15",
|
||||
"vitest": "latest"
|
||||
}
|
||||
|
||||
Vendored
+7
-7
@@ -1,12 +1,12 @@
|
||||
// See https://kit.svelte.dev/docs/types#app
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface Platform {}
|
||||
}
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
export {}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"strict": true,
|
||||
"sourceMap": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true
|
||||
"skipLibCheck": true
|
||||
}
|
||||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
||||
//
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"jsx": "preserve",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"types": [
|
||||
"vitest/globals"
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"jsx": "preserve",
|
||||
"lib": ["esnext", "dom"],
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"resolveJsonModule": true,
|
||||
"strict": true,
|
||||
"strictNullChecks": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipDefaultLibCheck": true,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "./dist",
|
||||
"declaration": true,
|
||||
"inlineSourceMap": true,
|
||||
"jsx": "preserve"
|
||||
"outDir": "./dist",
|
||||
"esModuleInterop": true,
|
||||
"skipDefaultLibCheck": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"jsx": "preserve",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"jsx": "preserve",
|
||||
"types": ["vitest/globals"]
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@
|
||||
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue'
|
||||
|
||||
const component: DefineComponent<{}, {}, any>
|
||||
export default component
|
||||
}
|
||||
|
||||
+5
-5
@@ -38,8 +38,8 @@
|
||||
"test:browser:playwright": "pnpm -C test/browser run test:playwright"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^0.39.6",
|
||||
"@antfu/ni": "^0.21.8",
|
||||
"@antfu/eslint-config": "^1.1.0",
|
||||
"@antfu/ni": "^0.21.9",
|
||||
"@rollup/plugin-commonjs": "^25.0.7",
|
||||
"@rollup/plugin-json": "^6.0.1",
|
||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||
@@ -51,8 +51,8 @@
|
||||
"@vitest/ui": "workspace:*",
|
||||
"bumpp": "^9.2.0",
|
||||
"esbuild": "^0.19.5",
|
||||
"eslint": "^8.44.0",
|
||||
"fast-glob": "^3.3.0",
|
||||
"eslint": "^8.53.0",
|
||||
"fast-glob": "^3.3.2",
|
||||
"lint-staged": "^15.0.2",
|
||||
"magic-string": "^0.30.5",
|
||||
"npm-run-all": "^4.1.5",
|
||||
@@ -64,7 +64,7 @@
|
||||
"rollup-plugin-license": "^3.2.0",
|
||||
"simple-git-hooks": "^2.9.0",
|
||||
"tsx": "^4.1.0",
|
||||
"typescript": "^5.1.6",
|
||||
"typescript": "^5.2.2",
|
||||
"vite": "^5.0.0-beta.15",
|
||||
"vitest": "workspace:*"
|
||||
},
|
||||
|
||||
Vendored
+3
-3
@@ -1,7 +1,7 @@
|
||||
import type { BrowserProvider } from 'vitest/nide'
|
||||
|
||||
declare var webdriverio: BrowserProvider
|
||||
declare var playwright: BrowserProvider
|
||||
declare var none: BrowserProvider
|
||||
declare const webdriverio: BrowserProvider
|
||||
declare const playwright: BrowserProvider
|
||||
declare const none: BrowserProvider
|
||||
|
||||
export { webdriverio, playwright, none }
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
"module": "./dist/index.js",
|
||||
"types": "./index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"*.d.ts"
|
||||
"*.d.ts",
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rimraf dist && rollup -c",
|
||||
|
||||
@@ -295,10 +295,7 @@ function hasIterator(object: any) {
|
||||
return !!(object != null && object[IteratorSymbol])
|
||||
}
|
||||
|
||||
export function iterableEquality(a: any,
|
||||
b: any,
|
||||
aStack: Array<any> = [],
|
||||
bStack: Array<any> = []): boolean | undefined {
|
||||
export function iterableEquality(a: any, b: any, aStack: Array<any> = [], bStack: Array<any> = []): boolean | undefined {
|
||||
if (
|
||||
typeof a !== 'object'
|
||||
|| typeof b !== 'object'
|
||||
@@ -324,8 +321,7 @@ export function iterableEquality(a: any,
|
||||
aStack.push(a)
|
||||
bStack.push(b)
|
||||
|
||||
const iterableEqualityWithStack = (a: any, b: any) =>
|
||||
iterableEquality(a, b, [...aStack], [...bStack])
|
||||
const iterableEqualityWithStack = (a: any, b: any) => iterableEquality(a, b, [...aStack], [...bStack])
|
||||
|
||||
if (a.size !== undefined) {
|
||||
if (a.size !== b.size) {
|
||||
@@ -431,8 +427,7 @@ function isObjectWithKeys(a: any) {
|
||||
&& !(a instanceof Date)
|
||||
}
|
||||
|
||||
export function subsetEquality(object: unknown,
|
||||
subset: unknown): boolean | undefined {
|
||||
export function subsetEquality(object: unknown, subset: unknown): boolean | undefined {
|
||||
// subsetEquality needs to keep track of the references
|
||||
// it has already visited to avoid infinite loops in case
|
||||
// there are circular references in the subset passed to it.
|
||||
@@ -476,8 +471,7 @@ export function typeEquality(a: any, b: any): boolean | undefined {
|
||||
return false
|
||||
}
|
||||
|
||||
export function arrayBufferEquality(a: unknown,
|
||||
b: unknown): boolean | undefined {
|
||||
export function arrayBufferEquality(a: unknown, b: unknown): boolean | undefined {
|
||||
let dataViewA = a as DataView
|
||||
let dataViewB = b as DataView
|
||||
|
||||
@@ -507,8 +501,7 @@ export function arrayBufferEquality(a: unknown,
|
||||
return true
|
||||
}
|
||||
|
||||
export function sparseArrayEquality(a: unknown,
|
||||
b: unknown): boolean | undefined {
|
||||
export function sparseArrayEquality(a: unknown, b: unknown): boolean | undefined {
|
||||
if (!Array.isArray(a) || !Array.isArray(b))
|
||||
return undefined
|
||||
|
||||
@@ -520,9 +513,7 @@ export function sparseArrayEquality(a: unknown,
|
||||
)
|
||||
}
|
||||
|
||||
export function generateToBeMessage(deepEqualityName: string,
|
||||
expected = '#{this}',
|
||||
actual = '#{exp}') {
|
||||
export function generateToBeMessage(deepEqualityName: string, expected = '#{this}', actual = '#{exp}') {
|
||||
const toBeMessage = `expected ${expected} to be ${actual} // Object.is equality`
|
||||
|
||||
if (['toStrictEqual', 'toEqual'].includes(deepEqualityName))
|
||||
|
||||
@@ -171,7 +171,7 @@ export interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>,
|
||||
|
||||
declare global {
|
||||
// support augmenting jest.Matchers by other libraries
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
// eslint-disable-next-line ts/no-namespace
|
||||
namespace jest {
|
||||
|
||||
// eslint-disable-next-line unused-imports/no-unused-vars
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"*.d.ts"
|
||||
"*.d.ts",
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rimraf dist && rollup -c",
|
||||
|
||||
@@ -308,9 +308,10 @@ function formatTitle(template: string, items: any[], idx: number) {
|
||||
const count = template.split('%').length - 1
|
||||
let formatted = format(template, ...items.slice(0, count))
|
||||
if (isObject(items[0])) {
|
||||
formatted = formatted.replace(/\$([$\w_.]+)/g,
|
||||
formatted = formatted.replace(
|
||||
/\$([$\w_.]+)/g,
|
||||
// https://github.com/chaijs/chai/pull/1490
|
||||
(_, key) => objDisplay(objectAttr(items[0], key), { truncate: runner?.config?.chaiConfig?.truncateThreshold }) as unknown as string,
|
||||
// https://github.com/chaijs/chai/pull/1490
|
||||
)
|
||||
}
|
||||
return formatted
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"*.d.ts"
|
||||
"*.d.ts",
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rimraf dist && rollup -c",
|
||||
|
||||
Vendored
+3
-1
@@ -20,7 +20,9 @@ export class NodeSnapshotEnvironment implements SnapshotEnvironment {
|
||||
async resolvePath(filepath: string): Promise<string> {
|
||||
return join(
|
||||
join(
|
||||
dirname(filepath), '__snapshots__'),
|
||||
dirname(filepath),
|
||||
'__snapshots__',
|
||||
),
|
||||
`${basename(filepath)}.snap`,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ export class SnapshotManager {
|
||||
const resolver = this.options.resolveSnapshotPath || (() => {
|
||||
return join(
|
||||
join(
|
||||
dirname(testPath), '__snapshots__'),
|
||||
dirname(testPath),
|
||||
'__snapshots__',
|
||||
),
|
||||
`${basename(testPath)}${this.extension}`,
|
||||
)
|
||||
})
|
||||
|
||||
@@ -28,11 +28,10 @@ export function keyToTestName(key: string): string {
|
||||
return key.replace(/ \d+$/, '')
|
||||
}
|
||||
|
||||
export function getSnapshotData(content: string | null,
|
||||
options: SnapshotStateOptions): {
|
||||
data: SnapshotData
|
||||
dirty: boolean
|
||||
} {
|
||||
export function getSnapshotData(content: string | null, options: SnapshotStateOptions): {
|
||||
data: SnapshotData
|
||||
dirty: boolean
|
||||
} {
|
||||
const update = options.updateSnapshot
|
||||
const data = Object.create(null)
|
||||
let snapshotContents = ''
|
||||
@@ -91,9 +90,7 @@ export function removeExtraLineBreaks(string: string): string {
|
||||
const escapeRegex = true
|
||||
const printFunctionName = false
|
||||
|
||||
export function serialize(val: unknown,
|
||||
indent = 2,
|
||||
formatOverrides: PrettyFormatOptions = {}): string {
|
||||
export function serialize(val: unknown, indent = 2, formatOverrides: PrettyFormatOptions = {}): string {
|
||||
return normalizeNewlines(
|
||||
prettyFormat(val, {
|
||||
escapeRegex,
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('DashboardEntry', () => {
|
||||
// })
|
||||
|
||||
it('renders the body and header slots', () => {
|
||||
cy.mount(<DashboardEntry v-slots={{ body, header }}/>)
|
||||
cy.mount(<DashboardEntry v-slots={{ body, header }} />)
|
||||
.get(bodySelector)
|
||||
.should('be.visible')
|
||||
.get(headerSelector)
|
||||
|
||||
@@ -20,7 +20,7 @@ function makeTextStack() {
|
||||
}
|
||||
|
||||
// 5 Stacks
|
||||
const textStacks = Array.from(new Array(5)).map(makeTextStack)
|
||||
const textStacks = Array.from(Array.from({ length: 5 })).map(makeTextStack)
|
||||
|
||||
const diff = `
|
||||
\x1B[32m- Expected\x1B[39m
|
||||
@@ -58,7 +58,7 @@ const fileWithTextStacks = {
|
||||
describe('ViewReport', () => {
|
||||
describe('File where stacks are in text', () => {
|
||||
beforeEach(() => {
|
||||
cy.mount(<ViewReport file={fileWithTextStacks as File} data-testid="view-report"/>)
|
||||
cy.mount(<ViewReport file={fileWithTextStacks as File} data-testid="view-report" />)
|
||||
})
|
||||
|
||||
it('renders all of the stacks', () => {
|
||||
|
||||
@@ -41,8 +41,8 @@ export function calcExternalLabels(labels: ModuleLabelItem[]): Map<string, strin
|
||||
label.candidate += label.candidate === '' ? head : `/${head}`
|
||||
splitMap.get(head)?.push(i)
|
||||
splits.shift()
|
||||
// eslint-disable-next-line @typescript-eslint/brace-style
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
splitMap.set(head, [i])
|
||||
// record the index of the label where the head first appears
|
||||
firsts.push(i)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
|
||||
import { mount } from 'cypress/vue'
|
||||
import type { Component } from 'vue'
|
||||
import { directives, plugins } from '../../client/global-setup'
|
||||
@@ -24,6 +22,7 @@ export function registerMount() {
|
||||
}
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line ts/no-namespace
|
||||
namespace Cypress {
|
||||
interface Chainable {
|
||||
/**
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { Reporter } from 'vitest';
|
||||
import type { Reporter } from 'vitest'
|
||||
|
||||
declare const reporter: Reporter
|
||||
export default reporter
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"jsx": "preserve",
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": [
|
||||
"./client/**/*"
|
||||
],
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"*.d.ts"
|
||||
"*.d.ts",
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rimraf dist && rollup -c",
|
||||
|
||||
@@ -208,11 +208,9 @@ const diff_cleanupSemantic = function (diffs: Array<Diff>) {
|
||||
// sides of it.
|
||||
if (lastEquality && (lastEquality.length
|
||||
<= Math.max(length_insertions1, length_deletions1))
|
||||
&& (lastEquality.length <= Math.max(length_insertions2,
|
||||
length_deletions2))) {
|
||||
&& (lastEquality.length <= Math.max(length_insertions2, length_deletions2))) {
|
||||
// Duplicate record.
|
||||
diffs.splice(equalities[equalitiesLength - 1], 0,
|
||||
new Diff(DIFF_DELETE, lastEquality))
|
||||
diffs.splice(equalities[equalitiesLength - 1], 0, new Diff(DIFF_DELETE, lastEquality))
|
||||
// Change second copy to insert.
|
||||
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT
|
||||
// Throw away the equality we just deleted.
|
||||
@@ -255,8 +253,7 @@ const diff_cleanupSemantic = function (diffs: Array<Diff>) {
|
||||
if (overlap_length1 >= deletion.length / 2
|
||||
|| overlap_length1 >= insertion.length / 2) {
|
||||
// Overlap found. Insert an equality and trim the surrounding edits.
|
||||
diffs.splice(pointer, 0, new Diff(DIFF_EQUAL,
|
||||
insertion.substring(0, overlap_length1)))
|
||||
diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1)))
|
||||
diffs[pointer - 1][1]
|
||||
= deletion.substring(0, deletion.length - overlap_length1)
|
||||
diffs[pointer + 1][1] = insertion.substring(overlap_length1)
|
||||
@@ -268,8 +265,7 @@ const diff_cleanupSemantic = function (diffs: Array<Diff>) {
|
||||
|| overlap_length2 >= insertion.length / 2) {
|
||||
// Reverse overlap found.
|
||||
// Insert an equality and swap and trim the surrounding edits.
|
||||
diffs.splice(pointer, 0, new Diff(DIFF_EQUAL,
|
||||
deletion.substring(0, overlap_length2)))
|
||||
diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2)))
|
||||
diffs[pointer - 1][0] = DIFF_INSERT
|
||||
diffs[pointer - 1][1]
|
||||
= insertion.substring(0, insertion.length - overlap_length2)
|
||||
@@ -463,8 +459,7 @@ function diff_cleanupMerge(diffs: Array<Diff>) {
|
||||
+= text_insert.substring(0, commonlength)
|
||||
}
|
||||
else {
|
||||
diffs.splice(0, 0, new Diff(DIFF_EQUAL,
|
||||
text_insert.substring(0, commonlength)))
|
||||
diffs.splice(0, 0, new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength)))
|
||||
pointer++
|
||||
}
|
||||
text_insert = text_insert.substring(commonlength)
|
||||
@@ -485,13 +480,11 @@ function diff_cleanupMerge(diffs: Array<Diff>) {
|
||||
pointer -= count_delete + count_insert
|
||||
diffs.splice(pointer, count_delete + count_insert)
|
||||
if (text_delete.length) {
|
||||
diffs.splice(pointer, 0,
|
||||
new Diff(DIFF_DELETE, text_delete))
|
||||
diffs.splice(pointer, 0, new Diff(DIFF_DELETE, text_delete))
|
||||
pointer++
|
||||
}
|
||||
if (text_insert.length) {
|
||||
diffs.splice(pointer, 0,
|
||||
new Diff(DIFF_INSERT, text_insert))
|
||||
diffs.splice(pointer, 0, new Diff(DIFF_INSERT, text_insert))
|
||||
pointer++
|
||||
}
|
||||
pointer++
|
||||
|
||||
@@ -51,8 +51,7 @@ function printAnnotation({
|
||||
bIndicator,
|
||||
includeChangeCounts,
|
||||
omitAnnotationLines,
|
||||
}: DiffOptionsNormalized,
|
||||
changeCounts: ChangeCounts): string {
|
||||
}: DiffOptionsNormalized, changeCounts: ChangeCounts): string {
|
||||
if (omitAnnotationLines)
|
||||
return ''
|
||||
|
||||
@@ -82,8 +81,7 @@ changeCounts: ChangeCounts): string {
|
||||
return `${aColor(a)}\n${bColor(b)}\n\n`
|
||||
}
|
||||
|
||||
export function printDiffLines(diffs: Array<Diff>,
|
||||
options: DiffOptionsNormalized): string {
|
||||
export function printDiffLines(diffs: Array<Diff>, options: DiffOptionsNormalized): string {
|
||||
return printAnnotation(options, countChanges(diffs))
|
||||
+ (options.expand
|
||||
? joinAlignedDiffsExpand(diffs, options)
|
||||
@@ -91,9 +89,7 @@ export function printDiffLines(diffs: Array<Diff>,
|
||||
}
|
||||
|
||||
// Compare two arrays of strings line-by-line. Format as comparison lines.
|
||||
export function diffLinesUnified(aLines: Array<string>,
|
||||
bLines: Array<string>,
|
||||
options?: DiffOptions): string {
|
||||
export function diffLinesUnified(aLines: Array<string>, bLines: Array<string>, options?: DiffOptions): string {
|
||||
return printDiffLines(
|
||||
diffLinesRaw(
|
||||
isEmptyString(aLines) ? [] : aLines,
|
||||
@@ -106,11 +102,7 @@ export function diffLinesUnified(aLines: Array<string>,
|
||||
// Given two pairs of arrays of strings:
|
||||
// Compare the pair of comparison arrays line-by-line.
|
||||
// Format the corresponding lines in the pair of displayable arrays.
|
||||
export function diffLinesUnified2(aLinesDisplay: Array<string>,
|
||||
bLinesDisplay: Array<string>,
|
||||
aLinesCompare: Array<string>,
|
||||
bLinesCompare: Array<string>,
|
||||
options?: DiffOptions): string {
|
||||
export function diffLinesUnified2(aLinesDisplay: Array<string>, bLinesDisplay: Array<string>, aLinesCompare: Array<string>, bLinesCompare: Array<string>, options?: DiffOptions): string {
|
||||
if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) {
|
||||
aLinesDisplay = []
|
||||
aLinesCompare = []
|
||||
@@ -156,13 +148,11 @@ export function diffLinesUnified2(aLinesDisplay: Array<string>,
|
||||
}
|
||||
|
||||
// Compare two arrays of strings line-by-line.
|
||||
export function diffLinesRaw(aLines: Array<string>,
|
||||
bLines: Array<string>): Array<Diff> {
|
||||
export function diffLinesRaw(aLines: Array<string>, bLines: Array<string>): Array<Diff> {
|
||||
const aLength = aLines.length
|
||||
const bLength = bLines.length
|
||||
|
||||
const isCommon = (aIndex: number, bIndex: number) =>
|
||||
aLines[aIndex] === bLines[bIndex]
|
||||
const isCommon = (aIndex: number, bIndex: number) => aLines[aIndex] === bLines[bIndex]
|
||||
|
||||
const diffs: Array<Diff> = []
|
||||
let aIndex = 0
|
||||
|
||||
@@ -12,9 +12,7 @@ import type { DiffOptionsColor } from './types'
|
||||
// * include common strings
|
||||
// * include change strings which have argument op with changeColor
|
||||
// * exclude change strings which have opposite op
|
||||
function concatenateRelevantDiffs(op: number,
|
||||
diffs: Array<Diff>,
|
||||
changeColor: DiffOptionsColor): string {
|
||||
function concatenateRelevantDiffs(op: number, diffs: Array<Diff>, changeColor: DiffOptionsColor): string {
|
||||
return diffs.reduce(
|
||||
(reduced: string, diff: Diff): string =>
|
||||
reduced
|
||||
@@ -208,8 +206,7 @@ class CommonBuffer {
|
||||
// Assume the function is not called:
|
||||
// * if either expected or received is empty string
|
||||
// * if neither expected nor received is multiline string
|
||||
function getAlignedDiffs(diffs: Array<Diff>,
|
||||
changeColor: DiffOptionsColor): Array<Diff> {
|
||||
function getAlignedDiffs(diffs: Array<Diff>, changeColor: DiffOptionsColor): Array<Diff> {
|
||||
const deleteBuffer = new ChangeBuffer(DIFF_DELETE, changeColor)
|
||||
const insertBuffer = new ChangeBuffer(DIFF_INSERT, changeColor)
|
||||
const commonBuffer = new CommonBuffer(deleteBuffer, insertBuffer)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// This is a fork of Jest's jest-diff package, but it doesn't depend on Node environment (like chalk).
|
||||
|
||||
@@ -64,7 +64,7 @@ const FALLBACK_FORMAT_OPTIONS = {
|
||||
* @param a Expected value
|
||||
* @param b Received value
|
||||
* @param options Diff options
|
||||
* @returns
|
||||
* @returns {string | null} a string diff
|
||||
*/
|
||||
export function diff(a: any, b: any, options?: DiffOptions): string | null {
|
||||
if (Object.is(a, b))
|
||||
|
||||
@@ -9,17 +9,11 @@ import type { Diff } from './cleanupSemantic'
|
||||
import { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT } from './cleanupSemantic'
|
||||
import type { DiffOptionsColor, DiffOptionsNormalized } from './types'
|
||||
|
||||
function formatTrailingSpaces(line: string,
|
||||
trailingSpaceFormatter: DiffOptionsColor): string {
|
||||
function formatTrailingSpaces(line: string, trailingSpaceFormatter: DiffOptionsColor): string {
|
||||
return line.replace(/\s+$/, match => trailingSpaceFormatter(match))
|
||||
}
|
||||
|
||||
function printDiffLine(line: string,
|
||||
isFirstOrLast: boolean,
|
||||
color: DiffOptionsColor,
|
||||
indicator: string,
|
||||
trailingSpaceFormatter: DiffOptionsColor,
|
||||
emptyFirstOrLastLinePlaceholder: string): string {
|
||||
function printDiffLine(line: string, isFirstOrLast: boolean, color: DiffOptionsColor, indicator: string, trailingSpaceFormatter: DiffOptionsColor, emptyFirstOrLastLinePlaceholder: string): string {
|
||||
return line.length !== 0
|
||||
? color(
|
||||
`${indicator} ${formatTrailingSpaces(line, trailingSpaceFormatter)}`,
|
||||
@@ -31,14 +25,12 @@ function printDiffLine(line: string,
|
||||
: ''
|
||||
}
|
||||
|
||||
function printDeleteLine(line: string,
|
||||
isFirstOrLast: boolean,
|
||||
{
|
||||
aColor,
|
||||
aIndicator,
|
||||
changeLineTrailingSpaceColor,
|
||||
emptyFirstOrLastLinePlaceholder,
|
||||
}: DiffOptionsNormalized): string {
|
||||
function printDeleteLine(line: string, isFirstOrLast: boolean, {
|
||||
aColor,
|
||||
aIndicator,
|
||||
changeLineTrailingSpaceColor,
|
||||
emptyFirstOrLastLinePlaceholder,
|
||||
}: DiffOptionsNormalized): string {
|
||||
return printDiffLine(
|
||||
line,
|
||||
isFirstOrLast,
|
||||
@@ -49,14 +41,12 @@ function printDeleteLine(line: string,
|
||||
)
|
||||
}
|
||||
|
||||
function printInsertLine(line: string,
|
||||
isFirstOrLast: boolean,
|
||||
{
|
||||
bColor,
|
||||
bIndicator,
|
||||
changeLineTrailingSpaceColor,
|
||||
emptyFirstOrLastLinePlaceholder,
|
||||
}: DiffOptionsNormalized): string {
|
||||
function printInsertLine(line: string, isFirstOrLast: boolean, {
|
||||
bColor,
|
||||
bIndicator,
|
||||
changeLineTrailingSpaceColor,
|
||||
emptyFirstOrLastLinePlaceholder,
|
||||
}: DiffOptionsNormalized): string {
|
||||
return printDiffLine(
|
||||
line,
|
||||
isFirstOrLast,
|
||||
@@ -67,14 +57,12 @@ function printInsertLine(line: string,
|
||||
)
|
||||
}
|
||||
|
||||
function printCommonLine(line: string,
|
||||
isFirstOrLast: boolean,
|
||||
{
|
||||
commonColor,
|
||||
commonIndicator,
|
||||
commonLineTrailingSpaceColor,
|
||||
emptyFirstOrLastLinePlaceholder,
|
||||
}: DiffOptionsNormalized): string {
|
||||
function printCommonLine(line: string, isFirstOrLast: boolean, {
|
||||
commonColor,
|
||||
commonIndicator,
|
||||
commonLineTrailingSpaceColor,
|
||||
emptyFirstOrLastLinePlaceholder,
|
||||
}: DiffOptionsNormalized): string {
|
||||
return printDiffLine(
|
||||
line,
|
||||
isFirstOrLast,
|
||||
@@ -86,11 +74,7 @@ function printCommonLine(line: string,
|
||||
}
|
||||
|
||||
// In GNU diff format, indexes are one-based instead of zero-based.
|
||||
function createPatchMark(aStart: number,
|
||||
aEnd: number,
|
||||
bStart: number,
|
||||
bEnd: number,
|
||||
{ patchColor }: DiffOptionsNormalized): string {
|
||||
function createPatchMark(aStart: number, aEnd: number, bStart: number, bEnd: number, { patchColor }: DiffOptionsNormalized): string {
|
||||
return patchColor(
|
||||
`@@ -${aStart + 1},${aEnd - aStart} +${bStart + 1},${bEnd - bStart} @@`,
|
||||
)
|
||||
@@ -100,8 +84,7 @@ function createPatchMark(aStart: number,
|
||||
//
|
||||
// Given array of aligned strings with inverse highlight formatting,
|
||||
// return joined lines with diff formatting (and patch marks, if needed).
|
||||
export function joinAlignedDiffsNoExpand(diffs: Array<Diff>,
|
||||
options: DiffOptionsNormalized): string {
|
||||
export function joinAlignedDiffsNoExpand(diffs: Array<Diff>, options: DiffOptionsNormalized): string {
|
||||
const iLength = diffs.length
|
||||
const nContextLines = options.contextLines
|
||||
const nContextLines2 = nContextLines + nContextLines
|
||||
@@ -270,8 +253,7 @@ export function joinAlignedDiffsNoExpand(diffs: Array<Diff>,
|
||||
//
|
||||
// Given array of aligned strings with inverse highlight formatting,
|
||||
// return joined lines with diff formatting.
|
||||
export function joinAlignedDiffsExpand(diffs: Array<Diff>,
|
||||
options: DiffOptionsNormalized): string {
|
||||
export function joinAlignedDiffsExpand(diffs: Array<Diff>, options: DiffOptionsNormalized): string {
|
||||
return diffs
|
||||
.map((diff: Diff, i: number, diffs: Array<Diff>): string => {
|
||||
const line = diff[1]
|
||||
|
||||
@@ -27,9 +27,7 @@ function hasCommonDiff(diffs: Array<Diff>, isMultiline: boolean): boolean {
|
||||
|
||||
// Compare two strings character-by-character.
|
||||
// Format as comparison lines in which changed substrings have inverse colors.
|
||||
export function diffStringsUnified(a: string,
|
||||
b: string,
|
||||
options?: DiffOptions): string {
|
||||
export function diffStringsUnified(a: string, b: string, options?: DiffOptions): string {
|
||||
if (a !== b && a.length !== 0 && b.length !== 0) {
|
||||
const isMultiline = a.includes('\n') || b.includes('\n')
|
||||
|
||||
@@ -53,9 +51,7 @@ export function diffStringsUnified(a: string,
|
||||
|
||||
// Compare two strings character-by-character.
|
||||
// Optionally clean up small common substrings, also known as chaff.
|
||||
export function diffStringsRaw(a: string,
|
||||
b: string,
|
||||
cleanup: boolean): Array<Diff> {
|
||||
export function diffStringsRaw(a: string, b: string, cleanup: boolean): Array<Diff> {
|
||||
const diffs = diffStrings(a, b)
|
||||
|
||||
if (cleanup)
|
||||
|
||||
@@ -49,6 +49,7 @@ export function serializeError(val: any, seen = new WeakMap()): any {
|
||||
return seen.get(val)
|
||||
|
||||
if (Array.isArray(val)) {
|
||||
// eslint-disable-next-line unicorn/no-new-array -- we need to keep sparce arrays ([1,,3])
|
||||
const clone: any[] = new Array(val.length)
|
||||
seen.set(val, clone)
|
||||
val.forEach((e, i) => {
|
||||
|
||||
@@ -19,38 +19,38 @@
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"require": "./dist/index.cjs",
|
||||
"import": "./dist/index.mjs"
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"./client": {
|
||||
"types": "./dist/client.d.ts",
|
||||
"require": "./dist/client.cjs",
|
||||
"import": "./dist/client.mjs"
|
||||
"import": "./dist/client.mjs",
|
||||
"require": "./dist/client.cjs"
|
||||
},
|
||||
"./server": {
|
||||
"types": "./dist/server.d.ts",
|
||||
"require": "./dist/server.cjs",
|
||||
"import": "./dist/server.mjs"
|
||||
"import": "./dist/server.mjs",
|
||||
"require": "./dist/server.cjs"
|
||||
},
|
||||
"./utils": {
|
||||
"types": "./dist/utils.d.ts",
|
||||
"require": "./dist/utils.cjs",
|
||||
"import": "./dist/utils.mjs"
|
||||
"import": "./dist/utils.mjs",
|
||||
"require": "./dist/utils.cjs"
|
||||
},
|
||||
"./hmr": {
|
||||
"types": "./dist/hmr.d.ts",
|
||||
"require": "./dist/hmr.cjs",
|
||||
"import": "./dist/hmr.mjs"
|
||||
"import": "./dist/hmr.mjs",
|
||||
"require": "./dist/hmr.cjs"
|
||||
},
|
||||
"./source-map": {
|
||||
"types": "./dist/source-map.d.ts",
|
||||
"require": "./dist/source-map.cjs",
|
||||
"import": "./dist/source-map.mjs"
|
||||
"import": "./dist/source-map.mjs",
|
||||
"require": "./dist/source-map.cjs"
|
||||
},
|
||||
"./constants": {
|
||||
"types": "./dist/constants.d.ts",
|
||||
"require": "./dist/constants.cjs",
|
||||
"import": "./dist/constants.mjs"
|
||||
"import": "./dist/constants.mjs",
|
||||
"require": "./dist/constants.cjs"
|
||||
},
|
||||
"./*": "./*"
|
||||
},
|
||||
@@ -69,9 +69,9 @@
|
||||
"vite-node": "./vite-node.mjs"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"*.d.ts",
|
||||
"*.mjs"
|
||||
"*.mjs",
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.0.0 || >=20.0.0"
|
||||
|
||||
@@ -288,8 +288,6 @@ export function createHotContext(
|
||||
addToMap(newListeners)
|
||||
},
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
||||
// @ts-ignore added in vite 5
|
||||
off<T extends string>(
|
||||
event: T,
|
||||
cb: (payload: InferCustomEventPayload<T>) => void,
|
||||
|
||||
@@ -143,15 +143,13 @@ export class ViteNodeServer {
|
||||
const promiseMap = this.fetchPromiseMap[mode]
|
||||
// reuse transform for concurrent requests
|
||||
if (!promiseMap.has(moduleId)) {
|
||||
promiseMap.set(moduleId,
|
||||
this._fetchModule(moduleId, mode)
|
||||
.then((r) => {
|
||||
return this.options.sourcemap !== true ? { ...r, map: undefined } : r
|
||||
})
|
||||
.finally(() => {
|
||||
promiseMap.delete(moduleId)
|
||||
}),
|
||||
)
|
||||
promiseMap.set(moduleId, this._fetchModule(moduleId, mode)
|
||||
.then((r) => {
|
||||
return this.options.sourcemap !== true ? { ...r, map: undefined } : r
|
||||
})
|
||||
.finally(() => {
|
||||
promiseMap.delete(moduleId)
|
||||
}))
|
||||
}
|
||||
return promiseMap.get(moduleId)!
|
||||
}
|
||||
@@ -162,12 +160,10 @@ export class ViteNodeServer {
|
||||
const promiseMap = this.transformPromiseMap[mode]
|
||||
// reuse transform for concurrent requests
|
||||
if (!promiseMap.has(id)) {
|
||||
promiseMap.set(id,
|
||||
this._transformRequest(id, filepath, mode)
|
||||
.finally(() => {
|
||||
promiseMap.delete(id)
|
||||
}),
|
||||
)
|
||||
promiseMap.set(id, this._transformRequest(id, filepath, mode)
|
||||
.finally(() => {
|
||||
promiseMap.delete(id)
|
||||
}))
|
||||
}
|
||||
return promiseMap.get(id)!
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ function retrieveSourceMapURL(source: string) {
|
||||
// Keep executing the search to find the *last* sourceMappingURL to avoid
|
||||
// picking up sourceMappingURLs from comments, strings, etc.
|
||||
let lastMatch, match
|
||||
// eslint-disable-next-line no-cond-assign
|
||||
while (match = re.exec(fileData)) lastMatch = match
|
||||
if (!lastMatch)
|
||||
return null
|
||||
@@ -192,7 +193,9 @@ function mapSourcePosition(position: OriginalMapping) {
|
||||
// location in the original file.
|
||||
if (originalPosition.source !== null) {
|
||||
originalPosition.source = supportRelativeURL(
|
||||
sourceMap.url, originalPosition.source)
|
||||
sourceMap.url,
|
||||
originalPosition.source,
|
||||
)
|
||||
return originalPosition
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"require": {
|
||||
"types": "./index.d.cts",
|
||||
"default": "./index.cjs"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./index.d.cts",
|
||||
"default": "./index.cjs"
|
||||
}
|
||||
},
|
||||
"./*": "./*",
|
||||
@@ -71,8 +71,8 @@
|
||||
},
|
||||
"./config": {
|
||||
"types": "./config.d.ts",
|
||||
"require": "./dist/config.cjs",
|
||||
"import": "./dist/config.js"
|
||||
"import": "./dist/config.js",
|
||||
"require": "./dist/config.cjs"
|
||||
},
|
||||
"./coverage": {
|
||||
"types": "./coverage.d.ts",
|
||||
@@ -90,12 +90,12 @@
|
||||
"vitest": "./vitest.mjs"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"bin",
|
||||
"*.d.ts",
|
||||
"*.cjs",
|
||||
"*.d.cts",
|
||||
"*.d.ts",
|
||||
"*.mjs",
|
||||
"*.cjs"
|
||||
"bin",
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.0.0 || >=20.0.0"
|
||||
@@ -148,7 +148,7 @@
|
||||
"magic-string": "^0.30.5",
|
||||
"pathe": "^1.1.1",
|
||||
"picocolors": "^1.0.0",
|
||||
"std-env": "^3.3.3",
|
||||
"std-env": "^3.4.3",
|
||||
"strip-literal": "^1.3.0",
|
||||
"tinybench": "^2.5.1",
|
||||
"tinypool": "^0.8.1",
|
||||
|
||||
@@ -169,8 +169,7 @@ function licensePlugin() {
|
||||
const licenses = new Set()
|
||||
const dependencyLicenseTexts = dependencies
|
||||
.filter(({ name }) => !name?.startsWith('@vitest/'))
|
||||
.sort(({ name: nameA }, { name: nameB }) =>
|
||||
nameA > nameB ? 1 : nameB > nameA ? -1 : 0,
|
||||
.sort(({ name: nameA }, { name: nameB }) => nameA > nameB ? 1 : nameB > nameA ? -1 : 0,
|
||||
)
|
||||
.map(
|
||||
({
|
||||
|
||||
@@ -178,8 +178,6 @@ export function resolveConfig(
|
||||
// vitenode will try to import such file with native node,
|
||||
// but then our mocker will not work properly
|
||||
if (resolved.server.deps.inline !== true) {
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
||||
// @ts-ignore ssr is not typed in Vite 2, but defined in Vite 3, so we can't use expect-error
|
||||
const ssrOptions = viteConfig.ssr
|
||||
if (ssrOptions?.noExternal === true && resolved.server.deps.inline == null) {
|
||||
resolved.server.deps.inline = true
|
||||
@@ -318,7 +316,8 @@ export function resolveConfig(
|
||||
if (resolved.diff) {
|
||||
resolved.diff = normalize(
|
||||
resolveModule(resolved.diff, { paths: [resolved.root] })
|
||||
?? resolve(resolved.root, resolved.diff))
|
||||
?? resolve(resolved.root, resolved.diff),
|
||||
)
|
||||
resolved.forceRerunTriggers.push(resolved.diff)
|
||||
}
|
||||
|
||||
|
||||
@@ -189,7 +189,8 @@ function printModuleWarningForPackage(logger: Logger, path: string, name: string
|
||||
}
|
||||
}
|
||||
}
|
||||
}\n`)))
|
||||
}\n`),
|
||||
))
|
||||
}
|
||||
|
||||
function printModuleWarningForSourceCode(logger: Logger, path: string) {
|
||||
|
||||
@@ -76,9 +76,6 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
|
||||
mainFields: [],
|
||||
alias: testConfig.alias,
|
||||
conditions: ['node'],
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
||||
// @ts-ignore we support Vite ^3.0, but browserField is available in Vite ^3.2
|
||||
browserField: false,
|
||||
},
|
||||
server: {
|
||||
...testConfig.api,
|
||||
|
||||
@@ -23,6 +23,7 @@ export function NormalizeURLPlugin(): Plugin {
|
||||
|
||||
let updatedCode = code
|
||||
let match: RegExpExecArray | null
|
||||
// eslint-disable-next-line no-cond-assign
|
||||
while ((match = assetImportMetaUrlRE.exec(cleanString))) {
|
||||
const { 0: exp, index } = match
|
||||
const metaUrlIndex = index + exp.indexOf('import.meta.url')
|
||||
|
||||
@@ -49,9 +49,6 @@ export function WorkspaceVitestPlugin(project: WorkspaceProject, options: Worksp
|
||||
mainFields: [],
|
||||
alias: testConfig.alias,
|
||||
conditions: ['node'],
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
||||
// @ts-ignore we support Vite ^3.0, but browserField is available in Vite ^3.2
|
||||
browserField: false,
|
||||
},
|
||||
esbuild: {
|
||||
sourcemap: 'external',
|
||||
|
||||
@@ -41,7 +41,9 @@ function removeInvalidXMLCharacters(value: any, removeDiscouragedChars: boolean)
|
||||
+ 'uDAFF[\\uDFFE\\uDFFF])|(?:\\uDB3F[\\uDFFE\\uDFFF])|(?:\\uDB7F[\\uDFFE\\uDFFF])|(?:\\uDBBF'
|
||||
+ '[\\uDFFE\\uDFFF])|(?:\\uDBFF[\\uDFFE\\uDFFF])(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\'
|
||||
+ 'uE000-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|'
|
||||
+ '(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]))', 'g')
|
||||
+ '(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]))',
|
||||
'g',
|
||||
)
|
||||
|
||||
value = value.replace(regex, '')
|
||||
}
|
||||
@@ -57,7 +59,8 @@ function escapeXML(value: any): string {
|
||||
.replace(/'/g, ''')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>'),
|
||||
true)
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
function executionTime(durationMS: number) {
|
||||
@@ -210,8 +213,7 @@ export class JUnitReporter implements Reporter {
|
||||
failures: stats.failures + Number(task.result?.state === 'fail'),
|
||||
skipped: stats.skipped + Number(task.mode === 'skip' || task.mode === 'todo'),
|
||||
}
|
||||
},
|
||||
{
|
||||
}, {
|
||||
passed: 0,
|
||||
failures: 0,
|
||||
skipped: 0,
|
||||
|
||||
@@ -348,8 +348,7 @@ export class WorkspaceProject {
|
||||
inspect: this.ctx.config.inspect,
|
||||
inspectBrk: this.ctx.config.inspectBrk,
|
||||
alias: [],
|
||||
}, this.ctx.configOverride || {} as any,
|
||||
) as ResolvedConfig
|
||||
}, this.ctx.configOverride || {} as any) as ResolvedConfig
|
||||
}
|
||||
|
||||
close() {
|
||||
|
||||
@@ -173,7 +173,8 @@ export class VitestMocker {
|
||||
const vitestError = this.createError(
|
||||
'[vitest] There was an error when mocking a module. '
|
||||
+ 'If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. '
|
||||
+ 'Read more: https://vitest.dev/api/vi.html#vi-mock')
|
||||
+ 'Read more: https://vitest.dev/api/vi.html#vi-mock',
|
||||
)
|
||||
vitestError.cause = err
|
||||
throw vitestError
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export class CommonjsExecutor {
|
||||
Error: typeof Error
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
// eslint-disable-next-line ts/no-this-alias
|
||||
const executor = this
|
||||
|
||||
this.Module = class Module {
|
||||
@@ -139,8 +139,6 @@ export class CommonjsExecutor {
|
||||
static _resolveLookupPaths = _Module._resolveLookupPaths
|
||||
// @ts-expect-error not typed
|
||||
static globalPaths = _Module.globalPaths
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
||||
// @ts-ignore not typed in lower versions
|
||||
static isBuiltin = _Module.isBuiltin
|
||||
|
||||
static Module = Module
|
||||
@@ -216,6 +214,7 @@ export class CommonjsExecutor {
|
||||
let currentExtension: string
|
||||
let index: number
|
||||
let startIndex = 0
|
||||
// eslint-disable-next-line no-cond-assign
|
||||
while ((index = name.indexOf('.', startIndex)) !== -1) {
|
||||
startIndex = index + 1
|
||||
if (index === 0)
|
||||
|
||||
@@ -26,8 +26,7 @@ export class EsmExecutor {
|
||||
if (m.status === 'unlinked') {
|
||||
this.esmLinkMap.set(
|
||||
m,
|
||||
m.link((identifier, referencer) =>
|
||||
this.executor.resolveModule(identifier, referencer.identifier),
|
||||
m.link((identifier, referencer) => this.executor.resolveModule(identifier, referencer.identifier),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ export interface InlineConfig {
|
||||
* Benchmark options.
|
||||
*
|
||||
* @default {}
|
||||
*/
|
||||
*/
|
||||
benchmark?: BenchmarkUserOptions
|
||||
|
||||
/**
|
||||
@@ -241,10 +241,10 @@ export interface InlineConfig {
|
||||
dir?: string
|
||||
|
||||
/**
|
||||
* Register apis globally
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
* Register apis globally
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
globals?: boolean
|
||||
|
||||
/**
|
||||
@@ -452,7 +452,7 @@ export interface InlineConfig {
|
||||
|
||||
/**
|
||||
* Enable Vitest UI
|
||||
* @internal WIP
|
||||
* @internal
|
||||
*/
|
||||
ui?: boolean
|
||||
|
||||
@@ -592,7 +592,7 @@ export interface InlineConfig {
|
||||
* The number of milliseconds after which a test is considered slow and reported as such in the results.
|
||||
*
|
||||
* @default 300
|
||||
*/
|
||||
*/
|
||||
slowTestThreshold?: number
|
||||
|
||||
/**
|
||||
@@ -619,7 +619,7 @@ export interface InlineConfig {
|
||||
/**
|
||||
* Modify default Chai config. Vitest uses Chai for `expect` and `assert` matches.
|
||||
* https://github.com/chaijs/chai/blob/4.x.x/lib/chai/config.js
|
||||
*/
|
||||
*/
|
||||
chaiConfig?: ChaiConfig
|
||||
|
||||
/**
|
||||
@@ -631,7 +631,7 @@ export interface InlineConfig {
|
||||
* Retry the test specific number of times if it fails.
|
||||
*
|
||||
* @default 0
|
||||
*/
|
||||
*/
|
||||
retry?: number
|
||||
|
||||
/**
|
||||
|
||||
@@ -104,15 +104,15 @@ export interface BaseCoverageOptions {
|
||||
include?: string[]
|
||||
|
||||
/**
|
||||
* Extensions for files to be included in coverage
|
||||
*
|
||||
* @default ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.vue', '.svelte', '.marko']
|
||||
*/
|
||||
* Extensions for files to be included in coverage
|
||||
*
|
||||
* @default ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.vue', '.svelte', '.marko']
|
||||
*/
|
||||
extension?: string | string[]
|
||||
|
||||
/**
|
||||
* List of files excluded from coverage as glob patterns
|
||||
*/
|
||||
* List of files excluded from coverage as glob patterns
|
||||
*/
|
||||
exclude?: string[]
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { VitestEnvironment } from './config'
|
||||
import type { BenchmarkResult } from './benchmark'
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
// eslint-disable-next-line ts/no-namespace
|
||||
namespace Chai {
|
||||
interface Assertion {
|
||||
containSubset(expected: any): Assertion
|
||||
|
||||
@@ -83,16 +83,16 @@ interface WorkerContextOptions {
|
||||
isolate?: boolean
|
||||
|
||||
/**
|
||||
* Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
|
||||
*
|
||||
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
||||
*
|
||||
* Set to `process.execArgv` to pass all arguments of the current process.
|
||||
*
|
||||
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
||||
*
|
||||
* @default [] // no execution arguments are passed
|
||||
*/
|
||||
* Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
|
||||
*
|
||||
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
||||
*
|
||||
* Set to `process.execArgv` to pass all arguments of the current process.
|
||||
*
|
||||
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
||||
*
|
||||
* @default [] // no execution arguments are passed
|
||||
*/
|
||||
execArgv?: string[]
|
||||
}
|
||||
|
||||
@@ -107,15 +107,15 @@ interface VmOptions {
|
||||
isolate?: true
|
||||
|
||||
/**
|
||||
* Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
|
||||
*
|
||||
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
||||
*
|
||||
* Set to `process.execArgv` to pass all arguments of the current process.
|
||||
*
|
||||
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
||||
*
|
||||
* @default [] // no execution arguments are passed
|
||||
*/
|
||||
* Pass additional arguments to `node` process when spawning `worker_threads` or `child_process`.
|
||||
*
|
||||
* See [Command-line API | Node.js](https://nodejs.org/docs/latest/api/cli.html) for more information.
|
||||
*
|
||||
* Set to `process.execArgv` to pass all arguments of the current process.
|
||||
*
|
||||
* Be careful when using, it as some options may crash worker, e.g. --prof, --title. See https://github.com/nodejs/node/issues/41103
|
||||
*
|
||||
* @default [] // no execution arguments are passed
|
||||
*/
|
||||
execArgv?: string[]
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ export function getAllMockableProperties(obj: any, isModule: boolean, constructo
|
||||
if (descriptor)
|
||||
allProps.set(key, { key, descriptor })
|
||||
})
|
||||
// eslint-disable-next-line no-cond-assign
|
||||
} while (curr = Object.getPrototypeOf(curr))
|
||||
// default is not specified in ownKeys, if module is interoped
|
||||
if (isModule && !allProps.has('default') && 'default' in obj) {
|
||||
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
"module": "./dist/index.js",
|
||||
"types": "./index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"*.d.ts"
|
||||
"*.d.ts",
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rimraf dist && rollup -c",
|
||||
|
||||
Vendored
+4
-4
@@ -1,8 +1,8 @@
|
||||
type CloneOption = 'native' | 'ponyfill' | 'none';
|
||||
type CloneOption = 'native' | 'ponyfill' | 'none'
|
||||
interface DefineWorkerOptions {
|
||||
clone: CloneOption;
|
||||
clone: CloneOption
|
||||
}
|
||||
|
||||
declare function defineWebWorkers(options?: DefineWorkerOptions): void;
|
||||
declare function defineWebWorkers(options?: DefineWorkerOptions): void
|
||||
|
||||
export { defineWebWorkers };
|
||||
export { defineWebWorkers }
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"*.d.ts",
|
||||
"*.mjs"
|
||||
"*.mjs",
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.0.0 || >=20.0.0"
|
||||
|
||||
Generated
+578
-522
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
import { existsSync, rmSync } from 'node:fs'
|
||||
import test from 'node:test'
|
||||
import * as assert from 'node:assert'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import test from 'node:test'
|
||||
import { startVitest } from 'vitest/node'
|
||||
|
||||
if (existsSync('./bench.json'))
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "node16",
|
||||
"esModuleInterop": true,
|
||||
"rootDir": ".",
|
||||
"module": "node16",
|
||||
"paths": {
|
||||
"#src/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ declare module 'vitest' {
|
||||
}
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
// eslint-disable-next-line ts/no-namespace
|
||||
namespace jest {
|
||||
interface Matchers<R> {
|
||||
toBeJestCompatible(): R
|
||||
|
||||
@@ -15,6 +15,6 @@ it('vitest resolves url to installed url package, but node:url to internal Node
|
||||
expect(nodeUrl).toHaveProperty('URLSearchParams')
|
||||
expect(nodeUrl).toHaveProperty('fileURLToPath')
|
||||
|
||||
// eslint-disable-next-line n/no-deprecated-api
|
||||
// eslint-disable-next-line node/no-deprecated-api
|
||||
expect(packageUrl.parse !== nodeUrl.parse).toBe(true)
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/quotes */
|
||||
/* eslint-disable style/quotes */
|
||||
|
||||
import { expect, test, vi } from 'vitest'
|
||||
import { testOutsideInlineSnapshot } from './snapshots-outside'
|
||||
@@ -42,13 +42,13 @@ test('from outside', () => {
|
||||
|
||||
test('with big array', () => {
|
||||
expect({
|
||||
this: { is: new Set(['one', new Array(30).fill({})]) },
|
||||
this: { is: new Set(['one', Array.from({ length: 30 }).fill({})]) },
|
||||
}).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('with big string', () => {
|
||||
expect({
|
||||
this: { is: new Set(['one', new Array(30).fill('zoo').join()]) },
|
||||
this: { is: new Set(['one', Array.from({ length: 30 }).fill('zoo').join()]) },
|
||||
}).toMatchSnapshot()
|
||||
})
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* eslint-disable @typescript-eslint/quotes */
|
||||
import { expect, it } from 'vitest'
|
||||
|
||||
it('should have sourcemaps', () => {
|
||||
expect('\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9').toBeTruthy()
|
||||
// eslint-disable-next-line style/quotes
|
||||
expect("\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9").toBeTruthy()
|
||||
expect(`\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9`).toBeTruthy()
|
||||
})
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user