Skip to content

Commit

Permalink
fix: type error (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho committed Mar 23, 2022
1 parent 68ed206 commit ce7927d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
30 changes: 19 additions & 11 deletions packages/vitest/rollup.config.js
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
@@ -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
@@ -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
@@ -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
@@ -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"],
}
}
}

0 comments on commit ce7927d

Please sign in to comment.