Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion oxlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
options: {
typeAware: true,
},
plugins: ['typescript', 'node', 'import', 'unicorn'],
plugins: ['typescript', 'node', 'import', 'unicorn', 'vitest'],
jsPlugins: ['eslint-plugin-n', 'eslint-plugin-regexp', '@e18e/eslint-plugin'],
categories: {
correctness: 'error',
Expand Down Expand Up @@ -94,9 +94,22 @@ export default defineConfig({
// https://github.com/oxc-project/oxc/issues/14895
'typescript/consistent-generic-constructors': 'off',

// These type-aware rules are disabled for compatibility with the codebase.
'vitest/no-conditional-expect': 'off',
'vitest/no-conditional-tests': 'off',

'import/no-duplicates': 'error',
'import/default': 'off',

'vitest/valid-expect': ['error', { maxArgs: 2 }],
'vitest/valid-title': 'off',
'vitest/no-disabled-tests': 'off',
'vitest/expect-expect': 'off',
// https://github.com/oxc-project/oxc/issues/29167
'vitest/no-standalone-expect': 'off',
// https://github.com/oxc-project/oxc/issues/29165
'vitest/require-mock-type-parameters': 'off',

'node/no-exports-assign': 'error',
'n/no-unpublished-bin': 'error',
'n/no-unsupported-features/es-builtins': 'error',
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-legacy/src/__tests__/snippets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ for (const version of shouldFailVersions) {
ecmaVersion: version,
sourceType: 'module',
})
}).toThrow()
}).toThrow('Unexpected token')
})
}

Expand Down
12 changes: 8 additions & 4 deletions packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1276,9 +1276,13 @@ describe('resolveEnvPrefix', () => {

test(`throw error if envPrefix contains ''`, () => {
let config: UserConfig = { envPrefix: '' }
expect(() => resolveEnvPrefix(config)).toThrow()
expect(() => resolveEnvPrefix(config)).toThrow(
'could lead unexpected exposure of sensitive information',
)
config = { envPrefix: ['', 'CUSTOM_'] }
expect(() => resolveEnvPrefix(config)).toThrow()
expect(() => resolveEnvPrefix(config)).toThrow(
'could lead unexpected exposure of sensitive information',
)
})

test(`show a warning message if envPrefix contains a whitespace`, () => {
Expand Down Expand Up @@ -1432,12 +1436,12 @@ describe('resolveConfig', () => {
).toBeUndefined()
})

test('resolveConfig with root path including "#" and "?" and "*" should warn ', async () => {
test('resolveConfig with root path including "#" and "?" and "*" should warn', async () => {
expect.assertions(1)

const logger = createLogger('info')
logger.warn = (str) => {
expect(str).to.include(
expect(str).toContain(
'Consider renaming the directory without the characters',
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ describe('parse positives', () => {

// ? is not escaped on windows (? cannot be used as a filename on windows)
it.skipIf(isWindows)('? in url', async () => {
// oxlint-disable-next-line vitest/prefer-snapshot-hint -- https://github.com/oxc-project/oxc/issues/29183
expect(await run('`./mo?ds/${base ?? foo}.js?url`')).toMatchSnapshot()
})

// ? is not escaped on windows (? cannot be used as a filename on windows)
it.skipIf(isWindows)('? in worker', async () => {
// oxlint-disable-next-line vitest/prefer-snapshot-hint -- https://github.com/oxc-project/oxc/issues/29183
expect(await run('`./mo?ds/${base ?? foo}.js?worker`')).toMatchSnapshot()
})

Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/server/__tests__/moduleGraph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('moduleGraph', () => {
const entryModule = await moduleGraph.ensureEntryFromUrl(entryUrl, false)
entryModule.ssrError = new Error(`unable to execute module`)

expect(entryModule.ssrError).to.be.a('error')
expect(entryModule.ssrError).toBeInstanceOf(Error)
moduleGraph.invalidateModule(entryModule)
expect(entryModule.ssrError).toBe(null)
})
Expand All @@ -32,7 +32,7 @@ describe('moduleGraph', () => {
const mod1 = await moduleGraph.ensureEntryFromUrl('/x.js', false)
mod1.meta = meta
const mod2 = await moduleGraph.ensureEntryFromUrl('/xx.js', false)
expect(mod2.meta).to.equal(meta)
expect(mod2.meta).toStrictEqual(meta)
})

it('ensure backward compatibility', async () => {
Expand Down
2 changes: 1 addition & 1 deletion playground/dynamic-import/__tests__/dynamic-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ test.runIf(isBuild)('dynamic import treeshaken file', async () => {
test.runIf(isBuild)('should not preload for non-analyzable urls', () => {
const js = findAssetFile(/index-[-\w]{8}\.js$/)
// should match e.g. await import(e.jss);o(".view",p===i)
expect(js).to.match(/\.jss\);/)
expect(js).toMatch(/\.jss\);/)
})

describe(
Expand Down
1 change: 1 addition & 0 deletions playground/fs-serve/__tests__/fs-serve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ describe.runIf(isServe)('invalid request', () => {
},
]
for (const { name, target, status, content } of testCases) {
// oxlint-disable-next-line vitest/valid-title
test(name, async () => {
const response = await sendRawRequest(viteTestUrl, target)
expect(response).toContain(status)
Expand Down
8 changes: 6 additions & 2 deletions playground/hmr-ssr/__tests__/hmr-ssr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,9 +773,13 @@ describe('acceptExports', () => {
})
}

describe('import * from ...', () => testStarExports('star-imports'))
describe('import * from ...', () => {
testStarExports('star-imports')
})

describe('dynamic import(...)', () => testStarExports('dynamic-imports'))
describe('dynamic import(...)', () => {
testStarExports('dynamic-imports')
})
})
})

Expand Down
9 changes: 7 additions & 2 deletions playground/hmr/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,13 @@ if (!isBuild) {
})
}

describe('import * from ...', () => testStarExports('star-imports'))
describe('import * from ...', () => {
testStarExports('star-imports')
})

describe('dynamic import(...)', () => testStarExports('dynamic-imports'))
describe('dynamic import(...)', () => {
testStarExports('dynamic-imports')
})
})
})

Expand Down Expand Up @@ -1035,6 +1039,7 @@ if (!isBuild) {
() => removeFile(childFile),
`${childFile} is disposed`,
),
// oxlint-disable-next-line vitest/require-awaited-expect-poll -- https://github.com/oxc-project/oxc/issues/29173
expect
.poll(() => page.textContent('.file-delete-restore'))
.toMatch('parent:not-child'),
Expand Down
36 changes: 19 additions & 17 deletions playground/optimize-deps/__tests__/optimize-deps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,23 +343,25 @@ describe('optimize-deps', clientOptimizerUnsupported, () => {
describe.runIf(isServe)('optimizeDeps config', () => {
test('supports include glob syntax', () => {
const metadata = readDepOptimizationMetadata()
expect(Object.keys(metadata.optimized)).to.include.members([
'@vitejs/test-dep-optimize-exports-with-glob',
'@vitejs/test-dep-optimize-exports-with-glob/named',
'@vitejs/test-dep-optimize-exports-with-glob/glob-dir/foo',
'@vitejs/test-dep-optimize-exports-with-glob/glob-dir/bar',
'@vitejs/test-dep-optimize-exports-with-glob/glob-dir/nested/baz',
'@vitejs/test-dep-optimize-exports-with-root-glob',
'@vitejs/test-dep-optimize-exports-with-root-glob/file1.js',
'@vitejs/test-dep-optimize-exports-with-root-glob/index.js',
'@vitejs/test-dep-optimize-exports-with-root-glob/dir/file2.js',
'@vitejs/test-dep-optimize-with-glob',
'@vitejs/test-dep-optimize-with-glob/index.js',
'@vitejs/test-dep-optimize-with-glob/named.js',
'@vitejs/test-dep-optimize-with-glob/glob/foo.js',
'@vitejs/test-dep-optimize-with-glob/glob/bar.js',
'@vitejs/test-dep-optimize-with-glob/glob/nested/baz.js',
])
expect(Object.keys(metadata.optimized)).toStrictEqual(
expect.arrayContaining([
'@vitejs/test-dep-optimize-exports-with-glob',
'@vitejs/test-dep-optimize-exports-with-glob/named',
'@vitejs/test-dep-optimize-exports-with-glob/glob-dir/foo',
'@vitejs/test-dep-optimize-exports-with-glob/glob-dir/bar',
'@vitejs/test-dep-optimize-exports-with-glob/glob-dir/nested/baz',
'@vitejs/test-dep-optimize-exports-with-root-glob',
'@vitejs/test-dep-optimize-exports-with-root-glob/file1.js',
'@vitejs/test-dep-optimize-exports-with-root-glob/index.js',
'@vitejs/test-dep-optimize-exports-with-root-glob/dir/file2.js',
'@vitejs/test-dep-optimize-with-glob',
'@vitejs/test-dep-optimize-with-glob/index.js',
'@vitejs/test-dep-optimize-with-glob/named.js',
'@vitejs/test-dep-optimize-with-glob/glob/foo.js',
'@vitejs/test-dep-optimize-with-glob/glob/bar.js',
'@vitejs/test-dep-optimize-with-glob/glob/nested/baz.js',
]),
)
})
})

Expand Down
Loading