Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type error #1002

Merged
merged 1 commit into from
Mar 23, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 19 additions & 11 deletions packages/vitest/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import alias from '@rollup/plugin-alias'
import license from 'rollup-plugin-license'
import c from 'picocolors'
import fg from 'fast-glob'
import { defineConfig } from 'rollup'

import pkg from './package.json'

Expand Down Expand Up @@ -101,17 +102,24 @@ export default ({ watch }) => [
external,
plugins,
},
...dtsEntries.map(input => ({
input,
output: {
file: input.replace('src/', 'dist/').replace('.ts', '.d.ts'),
format: 'esm',
},
external,
plugins: [
dts({ respectExternal: true }),
],
})),
...dtsEntries.map((input) => {
const _external = external
// index is vitest default types export
if (!input.includes('index'))
_external.push('vitest')

return defineConfig({
input,
output: {
file: input.replace('src/', 'dist/').replace('.ts', '.d.ts'),
format: 'esm',
},
external: _external,
plugins: [
dts({ respectExternal: true }),
],
})
}),
]

function licensePlugin() {
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { UserConfig as ViteUserConfig } from 'vite'
import type { InlineConfig } from './types'

export interface UserConfig extends ViteUserConfig {
test?: InlineConfig
test?: ViteUserConfig['test']
}

// will import vitest declare test in module 'vite'
export { configDefaults } from './defaults'

export function defineConfig(config: UserConfig) {
Expand Down
5 changes: 4 additions & 1 deletion packages/vitest/src/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { ResolvedC8Options, UserConfig } from './types'
// rollup dts building will external vitest
// so output dts entry using vitest to import internal types
// eslint-disable-next-line no-restricted-imports
import type { ResolvedC8Options, UserConfig } from 'vitest'

export const defaultInclude = ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
export const defaultExclude = ['**/node_modules/**', '**/dist/**', '**/cypress/**', '**/.{idea,git,cache,output,temp}/**']
Expand Down
8 changes: 3 additions & 5 deletions test/reporters/custom-reporter.vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { Reporter } from 'vitest'
import type { Vitest } from 'vitest/src/node'

import { defineConfig } from 'vite'
import type { Reporter, Vitest } from 'vitest'
import { defineConfig } from 'vitest/config'

class TestReporter implements Reporter {
ctx!: Vitest
Expand All @@ -18,6 +16,6 @@ class TestReporter implements Reporter {
export default defineConfig({
test: {
include: ['tests/reporters.spec.ts'],
reporters: new TestReporter(),
reporters: [new TestReporter()],
},
})
9 changes: 9 additions & 0 deletions test/reporters/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"paths": {
"vitest": ["./packages/vitest/index.d.ts"],
"vitest/node": ["./packages/vitest/node.d.ts"],
"vitest/config": ["./packages/vitest/config.d.ts"],
}
}
}