Skip to content

Commit

Permalink
chore: improve build time and memory usage (vitest-dev#4369)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Oct 25, 2023
1 parent ffaf16b commit 9527e65
Show file tree
Hide file tree
Showing 75 changed files with 361 additions and 396 deletions.
11 changes: 0 additions & 11 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@
],
"groupName": "all non-major examples dependencies",
"groupSlug": "all-minor-patch-examples"
},
{
"excludePackagePatterns": [
"@vitest/test-"
],
"matchUpdateTypes": [
"minor",
"patch"
],
"groupName": "all non-major dependencies",
"groupSlug": "all-minor-patch"
}
],
"ignoreDeps": [
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"test:ci": "CI=true pnpm -r --stream --filter !test-fails --filter !test-browser --filter !test-esm --filter !test-browser run test --allowOnly",
"test:ci:vm-threads": "CI=true pnpm -r --stream --filter !test-fails --filter !test-coverage --filter !test-single-thread --filter !test-browser --filter !test-esm --filter !test-browser run test --allowOnly --pool vmThreads",
"test:ci:no-threads": "CI=true pnpm -r --stream --filter !test-fails --filter !test-vm-threads --filter !test-coverage --filter !test-watch --filter !test-bail --filter !test-esm --filter !test-browser run test --allowOnly --pool forks",
"typecheck": "tsc --noEmit",
"typecheck:why": "tsc --noEmit --explainFiles > explainTypes.txt",
"typecheck": "tsc -p tsconfig.check.json --noEmit",
"typecheck:why": "tsc -p tsconfig.check.json --noEmit --explainFiles > explainTypes.txt",
"ui:build": "vite build packages/ui",
"ui:dev": "vite packages/ui",
"ui:test": "npm -C packages/ui run test:run",
Expand All @@ -40,7 +40,6 @@
"devDependencies": {
"@antfu/eslint-config": "^0.39.6",
"@antfu/ni": "^0.21.4",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.1",
Expand Down
6 changes: 1 addition & 5 deletions packages/browser/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import dts from 'rollup-plugin-dts'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import alias from '@rollup/plugin-alias'
import pkg from './package.json' assert { type: 'json' }

const external = [
Expand All @@ -14,16 +13,13 @@ const external = [
]

const plugins = [
alias({
entries: [{ find: /^node:(.+)$/, replacement: '$1' }],
}),
resolve({
preferBuiltins: true,
}),
json(),
commonjs(),
esbuild({
target: 'node14',
target: 'node18',
}),
]

Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/client/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createClient } from '@vitest/ws-client'
import type { ResolvedConfig } from 'vitest'
import type { CancelReason, VitestRunner } from '@vitest/runner'
import type { VitestExecutor } from 'vitest/src/runtime/execute'
import type { VitestExecutor } from '../../../vitest/src/runtime/execute'
import { createBrowserRunner } from './runner'
import { importId } from './utils'
import { setupConsoleLogSpy } from './logger'
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/client/runner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { File, TaskResultPack, Test } from '@vitest/runner'
import type { ResolvedConfig } from 'vitest'
import { rpc } from './rpc'
import type { ResolvedConfig } from '#types'

interface BrowserRunnerOptions {
config: ResolvedConfig
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/client/snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SnapshotEnvironment } from 'vitest'
import { rpc } from './rpc'
import type { SnapshotEnvironment } from '#types'

export class BrowserSnapshotEnvironment implements SnapshotEnvironment {
getVersion(): string {
Expand Down
8 changes: 7 additions & 1 deletion packages/browser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": [
"node",
"vite/client"
]
},
"exclude": ["dist", "node_modules"]
}
8 changes: 1 addition & 7 deletions packages/coverage-istanbul/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import esbuild from 'rollup-plugin-esbuild'
import dts from 'rollup-plugin-dts'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import alias from '@rollup/plugin-alias'
import nodeResolve from '@rollup/plugin-node-resolve'
import { join } from 'pathe'
import pkg from './package.json' assert { type: 'json' }
Expand All @@ -24,16 +23,11 @@ const external = [
]

const plugins = [
alias({
entries: [
{ find: /^node:(.+)$/, replacement: '$1' },
],
}),
nodeResolve(),
json(),
commonjs(),
esbuild({
target: 'node14',
target: 'node18',
}),
]

Expand Down
5 changes: 5 additions & 0 deletions packages/coverage-istanbul/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"include": ["./src/**/*.ts"],
"exclude": ["./dist"]
}
8 changes: 1 addition & 7 deletions packages/coverage-v8/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import esbuild from 'rollup-plugin-esbuild'
import dts from 'rollup-plugin-dts'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import alias from '@rollup/plugin-alias'
import nodeResolve from '@rollup/plugin-node-resolve'
import { join } from 'pathe'
import pkg from './package.json' assert { type: 'json' }
Expand All @@ -25,16 +24,11 @@ const external = [
]

const plugins = [
alias({
entries: [
{ find: /^node:(.+)$/, replacement: '$1' },
],
}),
nodeResolve(),
json(),
commonjs(),
esbuild({
target: 'node14',
target: 'node18',
}),
]

Expand Down
5 changes: 5 additions & 0 deletions packages/coverage-v8/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"include": ["./src/**/*.ts"],
"exclude": ["./dist"]
}
5 changes: 5 additions & 0 deletions packages/expect/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"include": ["./src/**/*.ts"],
"exclude": ["./dist"]
}
5 changes: 5 additions & 0 deletions packages/runner/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"include": ["./src/**/*.ts"],
"exclude": ["./dist"]
}
2 changes: 1 addition & 1 deletion packages/snapshot/src/port/inlineSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type MagicString from 'magic-string'
import { getCallLastIndex, lineSplitRE, offsetToLineNumber, positionToOffset } from '@vitest/utils'
import { getCallLastIndex, lineSplitRE, offsetToLineNumber, positionToOffset } from '../../../utils/src/index'
import type { SnapshotEnvironment } from '../types'

export interface InlineSnapshot {
Expand Down
4 changes: 2 additions & 2 deletions packages/snapshot/src/port/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import type { ParsedStack } from '@vitest/utils'
import { parseErrorStacktrace } from '@vitest/utils/source-map'
import type { OptionsReceived as PrettyFormatOptions } from 'pretty-format'
import type { ParsedStack } from '../../../utils/src/index'
import { parseErrorStacktrace } from '../../../utils/src/source-map'
import type { SnapshotData, SnapshotEnvironment, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotUpdateState } from '../types'
import type { InlineSnapshot } from './inlineSnapshot'
import { saveInlineSnapshots } from './inlineSnapshot'
Expand Down
2 changes: 1 addition & 1 deletion packages/snapshot/src/port/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { OptionsReceived as PrettyFormatOptions } from 'pretty-format'
import {
format as prettyFormat,
} from 'pretty-format'
import { isObject } from '@vitest/utils'
import { isObject } from '../../../utils/src/index'
import type { SnapshotData, SnapshotStateOptions } from '../types'
import type { SnapshotEnvironment } from '../types/environment'
import { getSerializers } from './plugins'
Expand Down
5 changes: 5 additions & 0 deletions packages/snapshot/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"include": ["./src/**/*.ts"],
"exclude": ["./dist"]
}
5 changes: 5 additions & 0 deletions packages/spy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"include": ["./src/**/*.ts"],
"exclude": ["./dist"]
}
2 changes: 1 addition & 1 deletion packages/ui/client/components/FileDetails.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import type { ModuleGraphData } from 'vitest'
import { client, current, currentLogs, isReport } from '~/composables/client'
import type { Params } from '~/composables/params'
import { viewMode } from '~/composables/params'
import type { ModuleGraph } from '~/composables/module-graph'
import { getModuleGraph } from '~/composables/module-graph'
import type { ModuleGraphData } from '#types'
const data = ref<ModuleGraphData>({ externalized: [], graph: {}, inlined: [] })
const graph = ref<ModuleGraph>({ nodes: [], links: [] })
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/components/Navigation.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { hasFailedSnapshot } from '@vitest/ws-client'
import { Tooltip as VueTooltip } from 'floating-vue'
import type { File, Task } from 'vitest'
import {
coverageConfigured,
coverageEnabled,
Expand All @@ -12,7 +13,6 @@ import {
showDashboard,
} from '../composables/navigation'
import { client, findById } from '../composables/client'
import type { File, Task } from '#types'
import { isDark, toggleDark } from '~/composables'
import { files, isReport, runAll } from '~/composables/client'
import { activeFileId } from '~/composables/params'
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/components/StatusIcon.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { hasFailedSnapshot } from '@vitest/ws-client'
import type { Task } from '#types'
import type { Task } from 'vitest'
defineProps<{ task: Task }>()
</script>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/components/TaskItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { Task } from '#types'
import type { Task } from 'vitest'
const props = defineProps<{
task: Task
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/components/TaskTree.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { Task } from '#types'
import type { Task } from 'vitest'
import { caseInsensitiveMatch } from '~/utils/task'
defineOptions({ inheritAttrs: false })
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/components/TasksList.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import type { ComputedRef } from 'vue'
import type { File, Task } from '#types'
import type { File, Task } from 'vitest'
import { findById, testRunState } from '~/composables/client'
import { activeFileId } from '~/composables/params'
import { caseInsensitiveMatch, isSuite } from '~/utils/task'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { UserConsoleLog } from '#types'
import type { UserConsoleLog } from 'vitest'
defineProps<{
taskName: string
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/components/views/ViewEditor.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import type CodeMirror from 'codemirror'
import type { ErrorWithDiff, File } from 'vitest'
import { createTooltip, destroyTooltip } from 'floating-vue'
import { openInEditor } from '../../composables/error'
import { client } from '~/composables/client'
import type { ErrorWithDiff, File } from '#types'
const props = defineProps<{
file?: File
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/components/views/ViewReport.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { faker } from '@faker-js/faker'
import type { File } from 'vitest'
import ViewReport from './ViewReport.vue'
import type { File } from '#types'
import { config } from '~/composables/client'

config.value.root = ''
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/components/views/ViewReport.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { ErrorWithDiff, File, Suite, Task } from 'vitest'
import type Convert from 'ansi-to-html'
import ViewReportError from './ViewReportError.vue'
import type { ErrorWithDiff, File, Suite, Task } from '#types'
import { isDark } from '~/composables/dark'
import { createAnsiToHtmlFilter } from '~/composables/error'
import { config } from '~/composables/client'
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/components/views/ViewReportError.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { ErrorWithDiff } from '#types'
import type { ErrorWithDiff } from 'vitest'
import { openInEditor, shouldOpenInEditor } from '~/composables/error'
const props = defineProps<{
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/composables/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createClient, getTasks } from '@vitest/ws-client'
import type { WebSocketStatus } from '@vueuse/core'
import type { File, ResolvedConfig } from 'vitest'
import type { Ref } from 'vue'
import { reactive } from 'vue'
import type { RunState } from '../../../types'
import { ENTRY_URL, isReport } from '../../constants'
import { activeFileId } from '../params'
import { createStaticClient } from './static'
import type { File, ResolvedConfig } from '#types'

export { ENTRY_URL, PORT, HOST, isReport } from '../../constants'

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/composables/module-graph.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Graph, GraphConfig, GraphController, GraphLink, GraphNode } from 'd3-graph-controller'
import { defineGraph, defineLink, defineNode } from 'd3-graph-controller'
import type { ModuleGraphData } from 'vitest/src/types'
import type { ModuleGraphData } from 'vitest'

export type ModuleType = 'external' | 'inline'
export type ModuleNode = GraphNode<ModuleType>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/composables/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { File } from 'vitest'
import { client, config, findById, testRunState } from './client'
import { activeFileId } from './params'
import type { File } from '#types'

export const currentModule = ref<File>()
export const dashboardVisible = ref(true)
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/client/utils/task.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Suite, Task } from '#types'
import type { Suite, Task } from 'vitest'

export function isSuite(task: Task): task is Suite {
return Object.hasOwnProperty.call(task, 'tasks')
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Plugin } from 'vite'
import { coverageConfigDefaults } from 'vitest/config'
import type { Vitest } from 'vitest'

export default (ctx: Vitest) => {
export default (ctx: Vitest): Plugin => {
return <Plugin>{
name: 'vitest:ui',
apply: 'serve',
Expand Down
19 changes: 16 additions & 3 deletions packages/ui/node/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ import fg from 'fast-glob'
import { stringify } from 'flatted'
import type { File, ModuleGraphData, Reporter, ResolvedConfig, Vitest } from 'vitest'
import { getModuleGraph } from '../../vitest/src/utils/graph'
import { getOutputFile } from '../../vitest/src/utils/config-helpers'

interface PotentialConfig {
outputFile?: string | Partial<Record<string, string>>
}

function getOutputFile(config: PotentialConfig | undefined) {
if (!config?.outputFile)
return

if (typeof config.outputFile === 'string')
return config.outputFile

return config.outputFile.html
}

interface HTMLReportData {
paths: string[]
Expand Down Expand Up @@ -38,14 +51,14 @@ export default class HTMLReporter implements Reporter {
}
await Promise.all(
result.files.map(async (file) => {
result.moduleGraph[file.filepath] = await getModuleGraph(this.ctx, file.filepath)
result.moduleGraph[file.filepath] = await getModuleGraph(this.ctx as any, file.filepath)
}),
)
await this.writeReport(stringify(result))
}

async writeReport(report: string) {
const htmlFile = getOutputFile(this.ctx.config, 'html') || 'html/index.html'
const htmlFile = getOutputFile(this.ctx.config) || 'html/index.html'
const htmlFileName = basename(htmlFile)
const htmlDir = resolve(this.ctx.config.root, dirname(htmlFile))

Expand Down
Loading

0 comments on commit 9527e65

Please sign in to comment.