build: separate src and test tsconfig

This commit is contained in:
Evan You 2022-05-20 14:35:56 +08:00
parent d8c3bbfa44
commit 575f07643d
11 changed files with 131 additions and 116 deletions

71
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,71 @@
name: 'ci'
on:
push:
branches:
- '**'
pull_request:
branches:
- main
jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install pnpm
uses: pnpm/action-setup@v2
- name: Set node version to 16
uses: actions/setup-node@v2
with:
node-version: 16
cache: 'pnpm'
- run: pnpm install
- name: Run unit tests
run: pnpm run test:unit
# e2e-test:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - name: Install pnpm
# uses: pnpm/action-setup@v2
# - name: Set node version to 16
# uses: actions/setup-node@v2
# with:
# node-version: 16
# cache: 'pnpm'
# - run: pnpm install
# - name: Run e2e tests
# run: pnpm run test:e2e
lint-and-test-dts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install pnpm
uses: pnpm/action-setup@v2
- name: Set node version to 16
uses: actions/setup-node@v2
with:
node-version: 16
cache: 'pnpm'
- run: pnpm install
- name: Run srouce type check
run: pnpm run ts-check
- name: Run eslint
run: pnpm run lint
- name: Run type declaration tests
run: pnpm run test:types

View File

@ -1,6 +1,7 @@
{
"name": "vue",
"version": "2.6.14",
"packageManager": "pnpm@7.1.0",
"description": "Reactive, component-oriented view layer for modern web interfaces.",
"main": "dist/vue.runtime.common.js",
"module": "dist/vue.runtime.esm.js",
@ -17,17 +18,17 @@
"dev": "rollup -w -c scripts/config.js --environment TARGET:web-full-dev",
"dev:cjs": "rollup -w -c scripts/config.js --environment TARGET:web-runtime-cjs-dev",
"dev:esm": "rollup -w -c scripts/config.js --environment TARGET:web-runtime-esm",
"dev:test": "karma start test/unit/karma.dev.config.ts",
"dev:ssr": "rollup -w -c scripts/config.js --environment TARGET:web-server-renderer",
"dev:compiler": "rollup -w -c scripts/config.js --environment TARGET:web-compiler ",
"build": "node scripts/build.js",
"build:ssr": "npm run build -- web-runtime-cjs,web-server-renderer",
"test": "npm run lint && npm run ts-check && npm run test:types && npm run test:cover && npm run test:e2e -- --env phantomjs && npm run test:ssr",
"test": "npm run lint && npm run ts-check && npm run test:types && npm run test:unit && npm run test:e2e",
"test:unit": "vitest run",
"test:e2e": "npm run build -- web-full-prod,web-server-basic-renderer && node test/e2e/runner.ts",
"test:types": "tsc -p ./types/tsconfig.json",
"lint": "eslint src scripts test",
"ts-check": "tsc --noEmit",
"ts-check": "tsc -p tsconfig.json --noEmit",
"ts-check:test": "tsc -p test/tsconfig.json --noEmit",
"bench:ssr": "npm run build:ssr && node benchmarks/ssr/renderToString.js && node benchmarks/ssr/renderToStream.js",
"release": "bash scripts/release.sh",
"release:note": "node scripts/gen-release-note.js",

View File

@ -4,10 +4,14 @@
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"noEmit": true
"noEmit": true,
"paths": {
"vue": ["../../../types/index.d.ts"]
}
},
"compileOnSave": false,
"include": [
"**/*.ts"
"**/*.ts",
"../../../types"
]
}

View File

@ -1,6 +1,6 @@
import config from '../config'
import { warn } from './debug'
import { inBrowser, inWeex } from './env'
import { inBrowser } from './env'
import { isPromise } from 'shared/util'
import { pushTarget, popTarget } from '../observer/dep'
@ -73,11 +73,7 @@ function logError(err, vm, info) {
warn(`Error in ${info}: "${err.toString()}"`, vm)
}
/* istanbul ignore else */
if (
(inBrowser || inWeex) &&
typeof console !== 'undefined' &&
!__SSR_TEST__
) {
if (inBrowser && typeof console !== 'undefined' && !__SSR_TEST__) {
console.error(err)
} else {
throw err

View File

@ -64,9 +64,9 @@ export function updateListeners(
createOnceHandler: Function,
vm: Component
) {
let name, def, cur, old, event
let name, cur, old, event
for (name in on) {
def = cur = on[name]
cur = on[name]
old = oldOn[name]
event = normalizeEvent(name)
if (isUndef(cur)) {

View File

@ -1,58 +0,0 @@
// http://nightwatchjs.org/guide#settings-file
module.exports = {
'src_folders': ['test/e2e/specs'],
'output_folder': 'test/e2e/reports',
'custom_commands_path': ['node_modules/nightwatch-helpers/commands'],
'custom_assertions_path': ['node_modules/nightwatch-helpers/assertions'],
'selenium': {
'start_process': true,
'server_path': require('selenium-server').path,
'host': '127.0.0.1',
'port': 4444,
'cli_args': {
'webdriver.chrome.driver': require('chromedriver').path
// , 'webdriver.gecko.driver': require('geckodriver').path
}
},
'test_settings': {
'default': {
'selenium_port': 4444,
'selenium_host': 'localhost',
'silent': true,
'screenshots': {
'enabled': true,
'on_failure': true,
'on_error': false,
'path': 'test/e2e/screenshots'
}
},
'chrome': {
'desiredCapabilities': {
'browserName': 'chrome',
'javascriptEnabled': true,
'acceptSslCerts': true
}
},
'firefox': {
'desiredCapabilities': {
'browserName': 'firefox',
'javascriptEnabled': true,
'acceptSslCerts': true,
'marionette': true
}
},
'phantomjs': {
'desiredCapabilities': {
'browserName': 'phantomjs',
'javascriptEnabled': true,
'acceptSslCerts': true,
'phantomjs.binary.path': require('phantomjs-prebuilt').path
}
}
}
}

View File

@ -1,34 +0,0 @@
const path = require('path')
const spawn = require('cross-spawn')
const httpServer = require('http-server')
const server = httpServer.createServer({
root: path.resolve(__dirname, '../../')
})
server.listen(8080)
let args = process.argv.slice(2)
if (args.indexOf('--config') === -1) {
args = args.concat(['--config', 'test/e2e/nightwatch.config.ts'])
}
if (args.indexOf('--env') === -1) {
args = args.concat(['--env', 'chrome,phantomjs'])
}
const i = args.indexOf('--test')
if (i > -1) {
args[i + 1] = 'test/e2e/specs/' + args[i + 1] + '.js'
}
const runner = spawn('./node_modules/.bin/nightwatch', args, {
stdio: 'inherit'
})
runner.on('exit', function (code) {
server.close()
process.exit(code)
})
runner.on('error', function (err) {
server.close()
throw err
})

View File

@ -7,7 +7,7 @@ module.exports = {
.assert.notVisible('.footer')
.assert.count('.filters .selected', 1)
.assert.evaluate(function () {
return document.querySelector('.filters .selected').textContent === 'All'
return document.querySelector('.filters .selected')!.textContent === 'All'
})
createNewItem('test')

View File

@ -13,7 +13,7 @@ module.exports = {
.click('.bold')
.assert.visible('#demo ul')
.assert.evaluate(function () {
return document.querySelector('#demo li ul').children.length === 4
return document.querySelector('#demo li ul')!.children.length === 4
})
.assert.containsText('#demo li div span', '[-]')
.assert.containsText('#demo > .item > ul > .item:nth-child(1)', 'hello')
@ -24,7 +24,7 @@ module.exports = {
// add items to root
.click('#demo > .item > ul > .add')
.assert.evaluate(function () {
return document.querySelector('#demo li ul').children.length === 5
return document.querySelector('#demo li ul')!.children.length === 5
})
.assert.containsText('#demo > .item > ul > .item:nth-child(1)', 'hello')
.assert.containsText('#demo > .item > ul > .item:nth-child(2)', 'wat')
@ -35,7 +35,7 @@ module.exports = {
// add another item
.click('#demo > .item > ul > .add')
.assert.evaluate(function () {
return document.querySelector('#demo li ul').children.length === 6
return document.querySelector('#demo li ul')!.children.length === 6
})
.assert.containsText('#demo > .item > ul > .item:nth-child(1)', 'hello')
.assert.containsText('#demo > .item > ul > .item:nth-child(2)', 'wat')
@ -48,7 +48,7 @@ module.exports = {
.assert.visible('#demo ul ul')
.assert.containsText('#demo ul > .item:nth-child(3)', '[-]')
.assert.evaluate(function () {
return document.querySelector('#demo ul ul').children.length === 5
return document.querySelector('#demo ul ul')!.children.length === 5
})
.click('.bold')
@ -63,8 +63,8 @@ module.exports = {
.assert.count('.item > ul', 5)
.assert.containsText('#demo ul > .item:nth-child(1)', '[-]')
.assert.evaluate(function () {
const firstItem = document.querySelector('#demo ul > .item:nth-child(1)')
const ul = firstItem.querySelector('ul')
const firstItem = document.querySelector('#demo ul > .item:nth-child(1)')!
const ul = firstItem.querySelector('ul')!
return ul.children.length === 2
})
.end()

37
test/tsconfig.json Normal file
View File

@ -0,0 +1,37 @@
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist",
"sourceMap": true,
"target": "esnext",
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"allowJs": true,
"noImplicitAny": false,
"noImplicitThis": false,
"noUnusedLocals": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"removeComments": false,
"jsx": "preserve",
"lib": ["esnext", "dom"],
"types": ["node", "vitest/globals"],
"paths": {
"compiler/*": ["../src/compiler/*"],
"core/*": ["../src/core/*"],
"server/*": ["../src/server/*"],
"sfc/*": ["../src/sfc/*"],
"shared/*": ["../src/shared/*"],
"web/*": ["../src/platforms/web/*"],
"vue": ["../src/platforms/web/entry-runtime-with-compiler"]
}
},
"include": ["../src", "../typescript", "."]
}

View File

@ -19,7 +19,7 @@
"removeComments": false,
"jsx": "preserve",
"lib": ["esnext", "dom"],
"types": ["node", "vitest/globals"],
"types": ["node"],
"paths": {
"compiler/*": ["src/compiler/*"],
"core/*": ["src/core/*"],
@ -33,7 +33,5 @@
"vue": ["src/platforms/web/entry-runtime-with-compiler"]
}
},
"include": ["src", "test-dts", "typescript", "test"],
"exclude": ["node_modules", "packages", "types"]
"include": ["src", "typescript"],
}