Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed May 10, 2022
2 parents 0da5252 + ba6cae9 commit 2c22ada
Show file tree
Hide file tree
Showing 973 changed files with 6,955 additions and 4,221 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.cjs
Expand Up @@ -63,7 +63,7 @@ module.exports = defineConfig({
'node/no-extraneous-import': [
'error',
{
allowModules: ['vite', 'less', 'sass']
allowModules: ['vite', 'less', 'sass', 'vitest']
}
],
'node/no-extraneous-require': [
Expand Down Expand Up @@ -103,13 +103,13 @@ module.exports = defineConfig({
}
},
{
files: ['packages/vite/types/**'],
files: ['packages/vite/types/**', '*.spec.ts'],
rules: {
'node/no-extraneous-import': 'off'
}
},
{
files: ['packages/playground/**'],
files: ['playground/**'],
rules: {
'node/no-extraneous-import': 'off',
'node/no-extraneous-require': 'off'
Expand Down
6 changes: 1 addition & 5 deletions .github/renovate.json5
@@ -1,11 +1,7 @@
{
"extends": ["config:base", "schedule:weekly", "group:allNonMajor"],
"labels": ["dependencies"],
"ignorePaths": [
"packages/playground/**",
"packages/create-vite/template-*/**",
"**/__tests__/**"
],
"ignorePaths": ["**/__tests__/**"],
"pin": false,
"rangeStrategy": "bump",
"node": false,
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/ci.yml
Expand Up @@ -13,6 +13,8 @@ on:
- feat/*
- fix/*
- perf/*
- v1
- v2
pull_request:
workflow_dispatch:

Expand All @@ -27,12 +29,17 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node_version: [12, 14, 16, 17]
node_version: [14, 16, 18]
include:
- os: macos-latest
node_version: 16
- os: macos-latest
node_version: 18
- os: windows-latest
node_version: 16
# Maybe bug with jest on windows and node-v18
# - os: windows-latest
# node_version: 18
fail-fast: false

name: "Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }}"
Expand All @@ -42,8 +49,6 @@ jobs:

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 6

- name: Set node version to ${{ matrix.node_version }}
uses: actions/setup-node@v3
Expand All @@ -63,6 +68,9 @@ jobs:
- name: Build plugin-react
run: pnpm run build-plugin-react

- name: Test unit
run: pnpm run test-unit

- name: Test serve
run: pnpm run test-serve -- --runInBand

Expand All @@ -80,8 +88,6 @@ jobs:

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 6

- name: Set node version to 16
uses: actions/setup-node@v3
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/semantic-pull-request.yml
@@ -0,0 +1,18 @@
name: Semantic Pull Request

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
runs-on: ubuntu-latest
name: Semantic Pull Request
steps:
- name: Validate PR title
uses: amannn/action-semantic-pull-request@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 11 additions & 10 deletions .gitignore
@@ -1,14 +1,15 @@
.DS_Store
node_modules
!**/glob-import/dir/node_modules
dist
dist-ssr
TODOs.md
*.log
temp
explorations
.DS_Store
.idea
*.local
/packages/vite/LICENSE
*.cpuprofile
*.local
*.log
/.vscode/
/packages/vite/LICENSE
dist
dist-ssr
explorations
node_modules
playground-temp
temp
TODOs.md
6 changes: 3 additions & 3 deletions .prettierignore
Expand Up @@ -8,6 +8,6 @@ LICENSE.md
.prettierignore
pnpm-lock.yaml
pnpm-workspace.yaml
packages/playground/tsconfig-json-load-error/has-error/tsconfig.json
packages/playground/html/invalid.html
packages/playground/worker/classic-worker.js
playground/tsconfig-json-load-error/has-error/tsconfig.json
playground/html/invalid.html
playground/worker/classic-worker.js
36 changes: 24 additions & 12 deletions CONTRIBUTING.md
Expand Up @@ -26,7 +26,7 @@ If you want to use break point and explore code execution you can use the ["Run

3. Click on the "JavaScript Debug Terminal" button.

4. It will open a terminal, then go to `packages/playground/xxx` and run `pnpm run dev`.
4. It will open a terminal, then go to `playground/xxx` and run `pnpm run dev`.

5. The execution will stop and you'll use the [Debug toolbar](https://code.visualstudio.com/docs/editor/debugging#_debug-actions) to continue, step over, restart the process...

Expand All @@ -42,7 +42,7 @@ Some errors are masked and hidden away because of the layers of abstraction and

1. In the sources panel in the right column, click the play button to resume execution and allow the tests to run which will open a Chromium instance.

1. Focusing the Chomium instance, you can open the browser devtools and inspect the console there to find the underlying problems.
1. Focusing the Chromium instance, you can open the browser devtools and inspect the console there to find the underlying problems.

1. To close everything, just stop the test process back in your terminal.

Expand All @@ -67,22 +67,32 @@ And re-run `pnpm install` to link the package.

## Running Tests

Each package under `packages/playground/` contains a `__tests__` directory. The tests are run using [Jest](https://jestjs.io/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `jest.config.js` and `scripts/jest*` files.
### Integration Tests

Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390).
Each package under `playground/` contains a `__tests__` directory. The tests are run using [Jest](https://jestjs.io/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `jest.config.js` and `scripts/jest*` files.

Each test can be run under either dev server mode or build mode.
Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390). Also you may want to [set git `core.symlinks` to `true` to solve issues with symlinks in git](https://github.com/vitejs/vite/issues/5242).

- `pnpm test` by default runs every test in both serve and build mode.
Each integration test can be run under either dev server mode or build mode.

- `pnpm test` by default runs every integration test in both serve and build mode, and also unit tests.

- `pnpm run test-serve` runs tests only under serve mode. This is just calling `jest` so you can pass any Jest flags to this command. Since Jest will attempt to run tests in parallel, if your machine has many cores this may cause flaky test failures with multiple Playwright instances running at the same time. You can force the tests to run in series with `pnpm run test-serve -- --runInBand`.

- `pnpm run test-build` runs tests only under build mode.

- You can also use `pnpm run test-serve -- [match]` or `pnpm run test-build -- [match]` to run tests in a specific playground package, e.g. `pnpm run test-serve -- css` will run tests for both `playground/css` and `playground/css-codesplit` under serve mode.
- You can also use `pnpm run test-serve -- [match]` or `pnpm run test-build -- [match]` to run tests in a specific playground package, e.g. `pnpm run test-serve -- asset` will run tests for both `playground/asset` and `vite/src/node/__tests__/asset` under serve mode and `vite/src/node/__tests__/**/*` just run in serve mode.

Note package matching is not available for the `pnpm test` script, which always runs all tests.

### Unit Tests

Other than tests under `playground/` for integration tests, packages might contains unit tests under their `__tests__` directory. Unit tests are powered by [Vitest](https://vitest.dev/). The detailed config is inside `vitest.config.ts` files.

- `pnpm run test-unit` runs unit tests under each package.

- You can also use `pnpm run test-unit -- [match]` to run related tests.

### Test Env and Helpers

Inside playground tests, a global `page` object is automatically available, which is a Playwright [`Page`](https://playwright.dev/docs/api/class-page) instance that has already navigated to the served page of the current playground. So writing a test is as simple as:
Expand All @@ -93,18 +103,20 @@ test('should work', async () => {
})
```

Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are available in `packages/playground/testUtils.ts`.
Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are available in `playground/testUtils.ts`.

Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/9c6501d9c363eaa3c1e7708d531fb2a92b633db6/scripts/jestPerTestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build.

### Extending the Test Suite

To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading are tested in the [assets playground](https://github.com/vitejs/vite/tree/main/packages/playground/assets). In this Vite App, there is a test for `?raw` imports, with [a section is defined in the `index.html` for it](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/index.html#L121):
To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading are tested in the [assets playground](https://github.com/vitejs/vite/tree/main/playground/assets). In this Vite App, there is a test for `?raw` imports, with [a section is defined in the `index.html` for it](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/playground/assets/index.html#L121):

```html
<h2>?raw import</h2>
<code class="raw"></code>
```

This will be modified [with the result of a file import](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/index.html#L151):
This will be modified [with the result of a file import](https://github.com/vitejs/vite/blob/main/playground/assets/index.html#L151):

```js
import rawSvg from './nested/fragment.svg?raw'
Expand All @@ -119,7 +131,7 @@ function text(el, text) {
}
```

In the [spec tests](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/__tests__/assets.spec.ts#L180), the modifications to the DOM listed above are used to test this feature:
In the [spec tests](https://github.com/vitejs/vite/blob/main/playground/assets/__tests__/assets.spec.ts#L180), the modifications to the DOM listed above are used to test this feature:

```js
test('?raw import', async () => {
Expand All @@ -136,7 +148,7 @@ To work around this, playground packages that uses the `file:` protocol should a
```jsonc
"scripts": {
//...
"postinstall": "ts-node ../../../scripts/patchFileDeps.ts"
"postinstall": "ts-node ../../scripts/patchFileDeps.ts"
}
```

Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -35,6 +35,8 @@ In addition, Vite is highly extensible via its [Plugin API](https://vitejs.dev/g

## Packages

> This branch is for the upcoming v3.0, if you are looking for current stable releases, check the [`v2` branch](https://github.com/vitejs/vite/tree/v2) instead.
| Package | Version (click for changelogs) |
| ------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------- |
| [vite](packages/vite) | [![vite version](https://img.shields.io/npm/v/vite.svg?label=%20)](packages/vite/CHANGELOG.md) |
Expand Down
18 changes: 12 additions & 6 deletions docs/.vitepress/config.js → docs/.vitepress/config.ts
@@ -1,9 +1,6 @@
// @ts-check
import { defineConfig } from 'vitepress'

/**
* @type {import('vitepress').UserConfig}
*/
module.exports = {
export default defineConfig({
title: 'Vite',
description: 'Next Generation Frontend Tooling',
head: [['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }]],
Expand Down Expand Up @@ -64,6 +61,15 @@ module.exports = {
}
]
},
{
text: 'v3 (next)',
items: [
{
text: 'v2.x (stable)',
link: 'https://v2.vitejs.dev'
}
]
},
{
text: 'Languages',
items: [
Expand Down Expand Up @@ -169,4 +175,4 @@ module.exports = {
]
}
}
}
})

0 comments on commit 2c22ada

Please sign in to comment.