Skip to content

Commit ebda73c

Browse files
committed
update contributing guide
1 parent f3cc537 commit ebda73c

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

CONTRIBUTING.md

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,57 @@
11
# Contributing Guide
22

3-
## pnpm
3+
## Repo setup
44

5-
This project uses pnpm to manage monorepo. You should run `pnpm i` after cloning this repo.
5+
This repo uses [pnpm](https://pnpm.io/) to manage monorepo.
66

7-
## Tests
7+
1. Run `pnpm install` in the repo root folder to install and link dependencies.
8+
2. Run `pnpm run build` in the repo root folder to build all packages. You can also do that manually by running `pnpm run build` in folders `packages/react-pages` and `packages/theme-doc`.
9+
3. Run `pnpm run dev` in the repo root folder to build and watch all packages. You can also do that manually by running `pnpm run dev` in folders `packages/react-pages` and `packages/theme-doc`. It will rebuild automatically whenever you change the package source code. So we prefer `pnpm run dev` to `pnpm run build` when changing source code frequently.
810

9-
The test setup is copied from [vite](https://github.com/vitejs/vite/blob/f6b58a0f535b1c26f9c1dfda74c28c685402c3c9/jest.config.js#L1). Fixtures and test cases is under `packages/playground`.
10-
11-
> There must be no more than one `.spec.ts` file for each fixture. Otherwise it will cause Error like `Error: EEXIST: file already exists, mkdir '/home/csr/vite-plugin-react-pages/temp/basic'`. There is some flaws with current test setup (which is copied from vite's repo).
12-
13-
## Run playgrounds
11+
## Running playgrounds
1412

1513
```sh
16-
cd packages/playground/basic/ # or other playgrounds
17-
npm run dev
14+
cd packages/playground/use-theme-doc/ # or other playgrounds
15+
pnpm run dev
16+
pnpm run build
17+
pnpm run ssr
1818
```
19+
20+
## Debugging
21+
22+
To use breakpoints and explore code execution, you can use the ["Run and Debug"](https://code.visualstudio.com/docs/editor/debugging) feature from **VS Code**.
23+
24+
1. Add a `debugger` statement where you want to stop the code execution.
25+
2. If you add `debugger` to the source code of a package, make sure to use `pnpm run build` or `pnpm run dev` to build the package after modifying the code.
26+
3. Click the "Run and Debug" icon in the activity bar of VS Code, which opens the [_Run and Debug view_](https://code.visualstudio.com/docs/editor/debugging#_run-and-debug-view).
27+
4. Click the "JavaScript Debug Terminal" button in the _Run and Debug view_, which opens a terminal in VS Code.
28+
5. From that terminal, go to `packages/playground/xxx`, and run `pnpm run dev` or `pnpm run build` or `pnpm run ssr`.
29+
6. The execution will stop at the `debugger` statement, and you can use the [Debug toolbar](https://code.visualstudio.com/docs/editor/debugging#_debug-actions) to continue, step over, and restart the process...
30+
31+
## Running tests
32+
33+
This project uses [playwright](https://playwright.dev/) to run integration tests.
34+
35+
If you are running tests for the first time in this repo, you should run `pnpm run install-test-deps` in repo root folder to install test deps.
36+
37+
After having test deps installed, run `pnpm run test` to run all tests.
38+
Or run `pnpm run test-serve` to run tests in vite serve mode only.
39+
Or run `pnpm run test-build` to run tests in vite build mode only.
40+
Or run `pnpm run test-ssr` to run tests in ssr mode only.
41+
42+
Run `pnpm run test file-name-filter` to filter on file name. For example, `pnpm run test hmr` will run tests in `packages/playground/use-theme-doc/__tests__/hmr.spec.ts`.
43+
44+
Adding `--debug` after any test command will make it run in debug mode. For example, `pnpm run test hmr --debug`. With this mode enabled, you can play with browser developer tools, exploring selectors, and stop test with `await page.pause()`. Checkout [playwright debug doc](https://playwright.dev/docs/debug#playwright-inspector) to learn more.
45+
46+
Checkout more test arguments at [playwright doc](https://playwright.dev/docs/test-cli). Most notable arguments are:
47+
48+
- `--debug`
49+
- `--max-failures=1` make test stop when it encounter the first error, so that you can tackle one problem at a time.
50+
- `--headed`
51+
- `--workers=1` prevent playwright using multiple thread to run tests in parallel.
52+
53+
## Writing tests
54+
55+
Currently all runnable tests are located at `packages/playground/use-theme-doc/__tests__/`. You can see them as examples.
56+
57+
Test utils are set up at `test-setup/utils/index.ts`. They are [playwright test fixtures](https://playwright.dev/docs/test-fixtures).

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"main": "index.js",
66
"license": "MIT",
77
"scripts": {
8+
"build": "pnpm -r --filter='./packages/*' run build",
9+
"dev": "pnpm -r --parallel --filter='./packages/*' run dev",
810
"format": "prettier --write ./**/*.{js,ts,tsx}",
911
"ver": "pnpm recursive --filter create-vite-pages --filter vite-plugin-react-pages --filter vite-pages-theme-basic --filter vite-pages-theme-doc exec -- npm version",
1012
"ver:p": "npm run ver -- patch",

0 commit comments

Comments
 (0)