Skip to content

Commit

Permalink
Merge branch 'main' into feat/move-providers-to-browser
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Oct 25, 2023
2 parents 70f9adf + 2af2ba7 commit 3aec1bf
Show file tree
Hide file tree
Showing 18 changed files with 487 additions and 865 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-and-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inputs:
node-version:
required: false
description: Node version for setup-node
default: 18.x
default: 20.x

runs:
using: composite
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node_version: [18]
node_version: [18, 20]
include:
- os: macos-latest
node_version: 18
node_version: 20
- os: windows-latest
node_version: 18
node_version: 20
fail-fast: false

steps:
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:

- uses: ./.github/actions/setup-and-cache
with:
node-version: 18
node-version: 20

- name: Install
run: pnpm i
Expand All @@ -120,7 +120,7 @@ jobs:

- uses: ./.github/actions/setup-and-cache
with:
node-version: 18
node-version: 20

- uses: browser-actions/setup-chrome@v1
- uses: browser-actions/setup-firefox@v1
Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:

- uses: ./.github/actions/setup-and-cache
with:
node-version: 18
node-version: 20

- uses: browser-actions/setup-chrome@v1
- uses: browser-actions/setup-edge@v1
Expand Down Expand Up @@ -191,7 +191,7 @@ jobs:

- uses: ./.github/actions/setup-and-cache
with:
node-version: 18
node-version: 20

- name: Install
run: sudo pnpm i --frozen-lockfile
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x

- run: npx changelogithub
env:
Expand Down
11 changes: 1 addition & 10 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Directory to save cache files.

### deps

- **Type:** `{ optimizer?, registerNodeLoader?, ... }`
- **Type:** `{ optimizer?, ... }`

Handling for dependencies resolution.

Expand Down Expand Up @@ -278,15 +278,6 @@ By default, files inside `node_modules` are externalized and not transformed, un
At the moment, this option only works with [`vmThreads`](#vmthreads) pool.
:::

#### deps.registerNodeLoader<NonProjectOption />

- **Type:** `boolean`
- **Default:** `false`

Use [experimental Node loader](https://nodejs.org/api/esm.html#loaders) to resolve imports inside externalized files, using Vite resolve algorithm.

If disabled, your `alias` and `<plugin>.resolveId` won't affect imports inside externalized packages (by default, `node_modules`).

#### deps.interopDefault

- **Type:** `boolean`
Expand Down
6 changes: 3 additions & 3 deletions examples/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"coverage": "vitest --coverage"
},
"dependencies": {
"solid-js": "^1.4.3"
"solid-js": "^1.8.3"
},
"devDependencies": {
"@solidjs/testing-library": "^0.8.4",
"@testing-library/jest-dom": "^5.16.4",
"jsdom": "latest",
"solid-testing-library": "^0.5.0",
"vite": "latest",
"vite-plugin-solid": "^2.5.0",
"vite-plugin-solid": "^2.7.2",
"vitest": "latest"
}
}
2 changes: 1 addition & 1 deletion examples/solid/test/Hello.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'vitest'
import { fireEvent, render } from 'solid-testing-library'
import { fireEvent, render } from '@solidjs/testing-library'
import { Hello } from '../components/Hello'

describe('<Hello />', () => {
Expand Down
7 changes: 7 additions & 0 deletions examples/solid/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ export default defineConfig({
isolate: false,
},
},
deps: {
optimizer: {
web: {
exclude: ['solid-js'],
},
},
},
},
plugins: [solid()],
resolve: {
Expand Down
1 change: 0 additions & 1 deletion packages/vitest/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const entries = [
'src/runtime/worker.ts',
'src/runtime/vm.ts',
'src/runtime/child.ts',
'src/runtime/loader.ts',
'src/runtime/entry.ts',
'src/runtime/entry-vm.ts',
'src/integrations/spy.ts',
Expand Down
10 changes: 0 additions & 10 deletions packages/vitest/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,6 @@ export function resolveConfig(
?? resolve(resolved.root, resolved.runner)
}

if (resolved.deps.registerNodeLoader) {
const transformMode = resolved.environment === 'happy-dom' || resolved.environment === 'jsdom' ? 'web' : 'ssr'
console.warn(
c.yellow(
`${c.inverse(c.yellow(' Vitest '))} "deps.registerNodeLoader" is deprecated.`
+ `If you rely on aliases inside external packages, use "deps.optimizer.${transformMode}.include" instead.`,
),
)
}

resolved.testNamePattern = resolved.testNamePattern
? resolved.testNamePattern instanceof RegExp
? resolved.testNamePattern
Expand Down
23 changes: 4 additions & 19 deletions packages/vitest/src/node/pool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { pathToFileURL } from 'node:url'
import mm from 'micromatch'
import { resolve } from 'pathe'
import { distDir, rootDir } from '../paths'
import type { Pool } from '../types'
import type { Vitest } from './core'
import { createChildProcessPool } from './pools/child'
Expand All @@ -27,9 +24,6 @@ export interface PoolProcessOptions {
env: Record<string, string>
}

const loaderPath = pathToFileURL(resolve(distDir, './loader.js')).href
const suppressLoaderWarningsPath = resolve(rootDir, './suppress-warnings.cjs')

export function createPool(ctx: Vitest): ProcessPool {
const pools: Record<Pool, ProcessPool | null> = {
forks: null,
Expand Down Expand Up @@ -74,19 +68,10 @@ export function createPool(ctx: Vitest): ProcessPool {

const options: PoolProcessOptions = {
...ctx.projectFiles,
execArgv: ctx.config.deps.registerNodeLoader
? [
...execArgv,
'--require',
suppressLoaderWarningsPath,
'--experimental-loader',
loaderPath,
...conditions,
]
: [
...execArgv,
...conditions,
],
execArgv: [
...execArgv,
...conditions,
],
env: {
TEST: 'true',
VITEST: 'true',
Expand Down
8 changes: 6 additions & 2 deletions packages/vitest/src/runtime/child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ async function init(ctx: ChildContext) {
isChildProcess: true,
}

// @ts-expect-error I know what I am doing :P
globalThis.__vitest_worker__ = state
Object.defineProperty(globalThis, '__vitest_worker__', {
value: state,
configurable: true,
writable: true,
enumerable: false,
})

if (ctx.invalidates) {
ctx.invalidates.forEach((fsPath) => {
Expand Down
95 changes: 0 additions & 95 deletions packages/vitest/src/runtime/loader.ts

This file was deleted.

7 changes: 6 additions & 1 deletion packages/vitest/src/runtime/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ export async function run(ctx: WorkerContext) {
if (!isContext(context))
throw new TypeError(`Environment ${ctx.environment.name} doesn't provide a valid context. It should be created by "vm.createContext" method.`)

context.__vitest_worker__ = state
Object.defineProperty(context, '__vitest_worker__', {
value: state,
configurable: true,
writable: true,
enumerable: false,
})
// this is unfortunately needed for our own dependencies
// we need to find a way to not rely on this by default
// because browser doesn't provide these globals
Expand Down
8 changes: 6 additions & 2 deletions packages/vitest/src/runtime/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ async function init(ctx: WorkerContext) {
rpc,
}

// @ts-expect-error I know what I am doing :P
globalThis.__vitest_worker__ = state
Object.defineProperty(globalThis, '__vitest_worker__', {
value: state,
configurable: true,
writable: true,
enumerable: false,
})

if (ctx.invalidates) {
ctx.invalidates.forEach((fsPath) => {
Expand Down
9 changes: 1 addition & 8 deletions packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ interface DepsOptions {
*/
fallbackCJS?: boolean

/**
* Use experimental Node loader to resolve imports inside node_modules using Vite resolve algorithm.
* @default false
* @deprecated If you rely on aliases inside external packages, use `deps.optimizer.{web,ssr}.include` instead.
*/
registerNodeLoader?: boolean

/**
* A list of directories relative to the config file that should be treated as module directories.
*
Expand Down Expand Up @@ -805,7 +798,7 @@ export type ProjectConfig = Omit<
| 'coverage'
> & {
sequencer?: Omit<SequenceOptions, 'sequencer' | 'seed'>
deps?: Omit<DepsOptions, 'registerNodeLoader' | 'moduleDirectories'>
deps?: Omit<DepsOptions, 'moduleDirectories'>
}

export type RuntimeConfig = Pick<
Expand Down
Loading

0 comments on commit 3aec1bf

Please sign in to comment.