Skip to content

Commit

Permalink
Merge branch 'main' into fix/conditions-dev-prod
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jan 17, 2024
2 parents e4f323a + 7d9f673 commit 65621bf
Show file tree
Hide file tree
Showing 23 changed files with 376 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ jobs:
strategy:
matrix:
browser: [[chrome, chromium], [firefox, firefox], [edge, webkit]]
fail-fast: false

timeout-minutes: 30

Expand Down Expand Up @@ -186,6 +187,7 @@ jobs:
strategy:
matrix:
browser: [[chrome, chromium], [edge, webkit]]
fail-fast: false

timeout-minutes: 30

Expand Down
4 changes: 2 additions & 2 deletions examples/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"test:ui": "vite build && vitest --ui"
},
"devDependencies": {
"@playwright/test": "^1.39.0",
"@playwright/test": "^1.41.0",
"@vitest/ui": "latest",
"playwright": "^1.39.0",
"playwright": "^1.41.0",
"vite": "latest",
"vitest": "latest"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
"@vitest/ws-client": "workspace:*",
"@wdio/protocols": "^8.22.0",
"periscopic": "^4.0.2",
"playwright": "^1.40.1",
"playwright-core": "^1.40.1",
"playwright": "^1.41.0",
"playwright-core": "^1.41.0",
"safaridriver": "^0.1.2",
"vitest": "workspace:*",
"webdriverio": "^8.22.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"codemirror": "^5.65.16",
"codemirror-theme-vars": "^0.1.2",
"cypress": "^13.6.2",
"d3-graph-controller": "^3.0.2",
"d3-graph-controller": "^3.0.4",
"floating-vue": "^2.0.0-y.0",
"splitpanes": "^3.1.5",
"unocss": "^0.57.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"pretty-format": "^29.7.0"
},
"devDependencies": {
"@jridgewell/trace-mapping": "^0.3.20",
"@jridgewell/trace-mapping": "^0.3.21",
"@types/estree": "^1.0.5",
"tinyhighlight": "^0.3.2"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"vite": "^5.0.0"
},
"devDependencies": {
"@jridgewell/trace-mapping": "^0.3.20",
"@jridgewell/trace-mapping": "^0.3.21",
"@types/debug": "^4.1.12"
}
}
26 changes: 25 additions & 1 deletion packages/vite-node/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,30 @@ export class ViteNodeServer {
return 'web'
}

private getChangedModule(
id: string,
file: string,
) {
const module = this.server.moduleGraph.getModuleById(id) || this.server.moduleGraph.getModuleById(file)
if (module)
return module
const _modules = this.server.moduleGraph.getModulesByFile(file)
if (!_modules || !_modules.size)
return null
// find the latest changed module
const modules = [..._modules]
let mod = modules[0]
let latestMax = -1
for (const m of _modules) {
const timestamp = Math.max(m.lastHMRTimestamp, m.lastInvalidationTimestamp)
if (timestamp > latestMax) {
latestMax = timestamp
mod = m
}
}
return mod
}

private async _fetchModule(id: string, transformMode: 'web' | 'ssr'): Promise<FetchResult> {
let result: FetchResult

Expand All @@ -212,7 +236,7 @@ export class ViteNodeServer {

const { path: filePath } = toFilePath(id, this.server.config.root)

const moduleNode = this.server.moduleGraph.getModuleById(id) || this.server.moduleGraph.getModuleById(filePath)
const moduleNode = this.getChangedModule(id, filePath)
const cache = this.fetchCaches[transformMode].get(filePath)

// lastUpdateTimestamp is the timestamp that marks the last time the module was changed
Expand Down
6 changes: 6 additions & 0 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,12 @@ export class Vitest {
this.changedTests.add(id)
this.scheduleRerun([id])
}
else {
// it's possible that file was already there but watcher triggered "add" event instead
const needsRerun = this.handleFileChanged(id)
if (needsRerun.length)
this.scheduleRerun(needsRerun)
}
}
const watcher = this.server.watcher

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/hoistMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function getBetterEnd(code: string, node: Node) {
return end
}

const regexpHoistable = /[ \t]*\b(vi|vitest)\s*\.\s*(mock|unmock|hoisted)\(/
const regexpHoistable = /\b(vi|vitest)\s*\.\s*(mock|unmock|hoisted)\(/
const hashbangRE = /^#!.*\n/

export function hoistMocks(code: string, id: string, parse: PluginContext['parse'], colors?: Colors) {
Expand Down
4 changes: 3 additions & 1 deletion packages/vitest/src/node/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ export class Logger {
const name = project.getName()
const output = project.isCore() ? '' : ` [${name}]`

this.log(c.dim(c.green(` ${output} Browser runner started at http://${project.config.browser.api?.host || 'localhost'}:${c.bold(`${project.browser.config.server.port}`)}`)))
const resolvedUrls = project.browser.resolvedUrls
const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0]
this.log(c.dim(c.green(` ${output} Browser runner started at ${new URL('/', origin)}`)))
})

if (this.ctx.config.ui)
Expand Down
3 changes: 2 additions & 1 deletion packages/vitest/src/node/pools/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export function createBrowserPool(ctx: Vitest): ProcessPool {
const provider = project.browserProvider!
providers.add(provider)

const origin = `http://${ctx.config.browser.api?.host || 'localhost'}:${project.browser!.config.server.port}`
const resolvedUrls = project.browser?.resolvedUrls
const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0]
const paths = files.map(file => relative(project.config.root, file))

if (project.config.browser.isolate) {
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/runtime/console.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Writable } from 'node:stream'
import { Console } from 'node:console'
import { relative } from 'node:path'
import { getSafeTimers } from '@vitest/utils'
import { getColors, getSafeTimers } from '@vitest/utils'
import { RealDate } from '../integrations/mock/date'
import type { WorkerGlobalState } from '../types'

Expand Down Expand Up @@ -128,7 +128,7 @@ export function createCustomConsole(state: WorkerGlobalState) {
return new Console({
stdout,
stderr,
colorMode: true,
colorMode: getColors().isColorSupported,
groupIndentation: 2,
})
}
Loading

0 comments on commit 65621bf

Please sign in to comment.