build: adjust dts test setup

This commit is contained in:
Evan You 2023-02-03 17:10:31 +08:00
parent d10a81eacb
commit 1ddde63b40
28 changed files with 50 additions and 45 deletions

View File

@ -32,7 +32,7 @@ module.exports = {
overrides: [ overrides: [
// tests, no restrictions (runs in Node / jest with jsdom) // tests, no restrictions (runs in Node / jest with jsdom)
{ {
files: ['**/__tests__/**', 'test-dts/**'], files: ['**/__tests__/**', 'packages/dts-test/**'],
rules: { rules: {
'no-restricted-globals': 'off', 'no-restricted-globals': 'off',
'no-restricted-syntax': 'off', 'no-restricted-syntax': 'off',

View File

@ -17,7 +17,7 @@
"test-unit": "vitest -c vitest.unit.config.ts", "test-unit": "vitest -c vitest.unit.config.ts",
"test-e2e": "node scripts/build.mjs vue -f global -d && vitest -c vitest.e2e.config.ts", "test-e2e": "node scripts/build.mjs vue -f global -d && vitest -c vitest.e2e.config.ts",
"test-dts": "run-s build-dts test-dts-only", "test-dts": "run-s build-dts test-dts-only",
"test-dts-only": "tsc -p ./test-dts/tsconfig.build.json", "test-dts-only": "tsc -p ./packages/dts-test/tsconfig.test.json",
"test-coverage": "vitest -c vitest.unit.config.ts --coverage", "test-coverage": "vitest -c vitest.unit.config.ts --coverage",
"release": "node scripts/release.mjs", "release": "node scripts/release.mjs",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
@ -37,7 +37,6 @@
"preinstall": "node ./scripts/preinstall.mjs", "preinstall": "node ./scripts/preinstall.mjs",
"postinstall": "simple-git-hooks" "postinstall": "simple-git-hooks"
}, },
"types": "test-dts/index.d.ts",
"simple-git-hooks": { "simple-git-hooks": {
"pre-commit": "pnpm lint-staged && pnpm check", "pre-commit": "pnpm lint-staged && pnpm check",
"commit-msg": "node scripts/verifyCommit.mjs" "commit-msg": "node scripts/verifyCommit.mjs"
@ -69,9 +68,6 @@
"@typescript-eslint/parser": "^5.23.0", "@typescript-eslint/parser": "^5.23.0",
"@vitest/coverage-istanbul": "^0.28.2", "@vitest/coverage-istanbul": "^0.28.2",
"@vue/consolidate": "0.17.3", "@vue/consolidate": "0.17.3",
"@vue/reactivity": "workspace:*",
"@vue/runtime-core": "workspace:*",
"@vue/runtime-dom": "workspace:*",
"brotli": "^1.3.2", "brotli": "^1.3.2",
"chalk": "^4.1.0", "chalk": "^4.1.0",
"conventional-changelog-cli": "^2.0.31", "conventional-changelog-cli": "^2.0.31",
@ -105,7 +101,6 @@
"tslib": "^2.4.0", "tslib": "^2.4.0",
"typescript": "^4.9.0", "typescript": "^4.9.0",
"vite": "^4.0.4", "vite": "^4.0.4",
"vitest": "^0.28.2", "vitest": "^0.28.2"
"vue": "workspace:*"
} }
} }

View File

@ -0,0 +1,7 @@
# dts-test
Tests Typescript types to ensure the types remain as expected.
- This directory is included in the root `tsconfig.json`, where package imports are aliased to `src` directories, so in IDEs and the `pnpm check` script the types are validated against source code.
- When runnong `tsc` with `packages/dts-test/tsconfig.test.json`, packages are resolved using using normal `node` resolution, so the types are validated against actual **built** types. This requires the types to be built first via `pnpm build-types`.

View File

@ -1,7 +1,7 @@
// This directory contains a number of d.ts assertions // This directory contains a number of d.ts assertions
// use \@ts-expect-error where errors are expected. // use \@ts-expect-error where errors are expected.
export * from '@vue/runtime-dom' export * from 'vue'
export function describe(_name: string, _fn: () => void): void export function describe(_name: string, _fn: () => void): void
export function test(_name: string, _fn: () => any): void export function test(_name: string, _fn: () => any): void

View File

@ -0,0 +1,10 @@
{
"name": "dts-test",
"private": true,
"dependencies": {
"vue": "workspace:*",
"@vue/runtime-core": "workspace:*",
"@vue/runtime-dom": "workspace:*",
"@vue/reactivity": "workspace:*"
}
}

View File

@ -1,5 +1,11 @@
import { WritableComputedRef } from '@vue/reactivity' import {
import { expectType, ref, computed, Ref, ComputedRef } from './index' expectType,
ref,
computed,
Ref,
ComputedRef,
WritableComputedRef
} from './index'
import 'vue/macros-global' import 'vue/macros-global'
import { RefType, RefTypes } from 'vue/macros' import { RefType, RefTypes } from 'vue/macros'

View File

@ -1,4 +1,3 @@
import { ComponentPropsOptions } from '@vue/runtime-core'
import { isArray, isPromise, isFunction } from '@vue/shared' import { isArray, isPromise, isFunction } from '@vue/shared'
import { import {
getCurrentInstance, getCurrentInstance,
@ -8,7 +7,11 @@ import {
unsetCurrentInstance unsetCurrentInstance
} from './component' } from './component'
import { EmitFn, EmitsOptions } from './componentEmits' import { EmitFn, EmitsOptions } from './componentEmits'
import { ComponentObjectPropsOptions, ExtractPropTypes } from './componentProps' import {
ComponentPropsOptions,
ComponentObjectPropsOptions,
ExtractPropTypes
} from './componentProps'
import { warn } from './warning' import { warn } from './warning'
// dev only // dev only

View File

@ -18,9 +18,6 @@ importers:
'@typescript-eslint/parser': ^5.23.0 '@typescript-eslint/parser': ^5.23.0
'@vitest/coverage-istanbul': ^0.28.2 '@vitest/coverage-istanbul': ^0.28.2
'@vue/consolidate': 0.17.3 '@vue/consolidate': 0.17.3
'@vue/reactivity': workspace:*
'@vue/runtime-core': workspace:*
'@vue/runtime-dom': workspace:*
brotli: ^1.3.2 brotli: ^1.3.2
chalk: ^4.1.0 chalk: ^4.1.0
conventional-changelog-cli: ^2.0.31 conventional-changelog-cli: ^2.0.31
@ -55,7 +52,6 @@ importers:
typescript: ^4.9.0 typescript: ^4.9.0
vite: ^4.0.4 vite: ^4.0.4
vitest: ^0.28.2 vitest: ^0.28.2
vue: workspace:*
devDependencies: devDependencies:
'@babel/parser': 7.20.15 '@babel/parser': 7.20.15
'@babel/types': 7.20.7 '@babel/types': 7.20.7
@ -71,9 +67,6 @@ importers:
'@typescript-eslint/parser': 5.50.0_jofidmxrjzhj7l6vknpw5ecvfe '@typescript-eslint/parser': 5.50.0_jofidmxrjzhj7l6vknpw5ecvfe
'@vitest/coverage-istanbul': 0.28.3_jsdom@21.1.0+terser@5.16.2 '@vitest/coverage-istanbul': 0.28.3_jsdom@21.1.0+terser@5.16.2
'@vue/consolidate': 0.17.3 '@vue/consolidate': 0.17.3
'@vue/reactivity': link:packages/reactivity
'@vue/runtime-core': link:packages/runtime-core
'@vue/runtime-dom': link:packages/runtime-dom
brotli: 1.3.3 brotli: 1.3.3
chalk: 4.1.2 chalk: 4.1.2
conventional-changelog-cli: 2.2.2 conventional-changelog-cli: 2.2.2
@ -108,7 +101,6 @@ importers:
typescript: 4.9.5 typescript: 4.9.5
vite: 4.1.1_ghge5pqdvzsmxto52quo4r2say vite: 4.1.1_ghge5pqdvzsmxto52quo4r2say
vitest: 0.28.3_jsdom@21.1.0+terser@5.16.2 vitest: 0.28.3_jsdom@21.1.0+terser@5.16.2
vue: link:packages/vue
packages/compiler-core: packages/compiler-core:
specifiers: specifiers:
@ -188,6 +180,18 @@ importers:
'@vue/compiler-dom': link:../compiler-dom '@vue/compiler-dom': link:../compiler-dom
'@vue/shared': link:../shared '@vue/shared': link:../shared
packages/dts-test:
specifiers:
'@vue/reactivity': workspace:*
'@vue/runtime-core': workspace:*
'@vue/runtime-dom': workspace:*
vue: workspace:*
dependencies:
'@vue/reactivity': link:../reactivity
'@vue/runtime-core': link:../runtime-core
'@vue/runtime-dom': link:../runtime-dom
vue: link:../vue
packages/reactivity: packages/reactivity:
specifiers: specifiers:
'@vue/shared': 3.2.47 '@vue/shared': 3.2.47

View File

@ -22,7 +22,8 @@ const entries = {
const nonSrcPackages = [ const nonSrcPackages = [
'sfc-playground', 'sfc-playground',
'size-check', 'size-check',
'template-explorer' 'template-explorer',
'dts-test'
] ]
for (const dir of dirs) { for (const dir of dirs) {

View File

@ -1,13 +0,0 @@
# Test-ts
Tests Typescript types to ensure the types remain as expected.
## Configuration
### tsconfig.json
Config used to test against the package source
### tsconfig.build.json
Replaces the `vue` and `@vue/*` dependencies with the built Typescript to ensure the published types are correct.

View File

@ -1,8 +0,0 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"declaration": true
},
"exclude": ["../packages/*/__tests__", "../packages/template-explorer"]
}

View File

@ -10,6 +10,6 @@
"packages/template-explorer", "packages/template-explorer",
"packages/sfc-playground", "packages/sfc-playground",
"packages/size-check", "packages/size-check",
"test-dts" "packages/dts-test"
] ]
} }

View File

@ -32,6 +32,6 @@
"packages/*/src", "packages/*/src",
"packages/runtime-dom/types/jsx.d.ts", "packages/runtime-dom/types/jsx.d.ts",
"packages/*/__tests__", "packages/*/__tests__",
"test-dts" "packages/dts-test"
] ]
} }