Skip to content

Commit 804a90a

Browse files
Filmbostock
andauthored
adopt vitest; pnpm; regenerate snapshots (#2373)
* adopt vitest; substitute images if they approximately match the expected images * yarn deduplicate * avoid toMatchFileSnapshot, for now * fix test workflow * simplify setup; jsdom * jsdom 29 * upgrade actions * more explicit context.dispatchValue test * move fast check into function * simplify withImages * declare tests in (test) source * regenerate snapshot for node 24 * don’t need alias * vitest --typecheck * switch to pnpm * regenerate snapshots * add missing d3-format dependency * pnpm/action-setup@v5 * explicitly declare tests * turn off isolation for fast tests * write -changed files --------- Co-authored-by: Mike Bostock <mbostock@gmail.com>
1 parent abb0f4b commit 804a90a

967 files changed

Lines changed: 286240 additions & 284640 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/deploy.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ jobs:
1515
name: github-pages
1616
url: ${{ steps.deployment.outputs.page_url }}
1717
steps:
18-
- uses: actions/checkout@v4
19-
- uses: actions/setup-node@v4
18+
- uses: actions/checkout@v6
19+
- uses: pnpm/action-setup@v5
2020
with:
21-
node-version: 22
22-
cache: yarn
23-
- run: yarn --frozen-lockfile
24-
- run: yarn prepublishOnly
25-
- run: yarn docs:build
21+
version: 10
22+
- uses: actions/setup-node@v6
23+
with:
24+
node-version: 24
25+
cache: pnpm
26+
- run: pnpm install
27+
- run: pnpm run prepublishOnly
28+
- run: pnpm run docs:build
2629
- uses: actions/configure-pages@v4
2730
- uses: actions/upload-pages-artifact@v3
2831
with:

.github/workflows/publish.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ jobs:
1212
contents: read
1313
packages: write
1414
steps:
15-
- uses: actions/checkout@v4
16-
- uses: actions/setup-node@v4
15+
- uses: actions/checkout@v6
16+
- uses: pnpm/action-setup@v5
1717
with:
18-
node-version: 22
19-
cache: yarn
20-
registry-url: 'https://registry.npmjs.org'
21-
- run: yarn --frozen-lockfile
22-
- run: yarn test
18+
version: 10
19+
- uses: actions/setup-node@v6
20+
with:
21+
node-version: 24
22+
cache: pnpm
23+
- run: pnpm install
24+
- run: pnpm run test
2325
- run: npm publish
2426
env:
2527
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v4
14-
- uses: actions/setup-node@v4
13+
- uses: actions/checkout@v6
14+
- uses: pnpm/action-setup@v5
1515
with:
16-
node-version: 22
17-
cache: yarn
18-
- run: yarn --frozen-lockfile
19-
- run: yarn test:mocha
20-
- run: yarn test:tsc
21-
- run: yarn test:lint
22-
- run: yarn test:prettier
23-
- run: yarn prepublishOnly
24-
- run: yarn docs:build
25-
- uses: actions/upload-artifact@v4
16+
version: 10
17+
- uses: actions/setup-node@v6
18+
with:
19+
node-version: 24
20+
cache: pnpm
21+
- run: pnpm install
22+
- run: pnpm run test:vitest
23+
- run: pnpm run test:tsc
24+
- run: pnpm run test:lint
25+
- run: pnpm run test:prettier
26+
- run: pnpm run prepublishOnly
27+
- run: pnpm run docs:build
28+
- uses: actions/upload-artifact@v7
2629
if: failure()
2730
with:
2831
name: test-output-changes

CONTRIBUTING.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We request that you abide by our [code of conduct](https://observablehq.com/@obs
99
To contribute to Observable Plot, you’ll need a local development environment to make and test changes to Plot’s source code. To get started, follow GitHub’s tutorial on [forking (and cloning) a repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo). Once you’ve cloned your fork of the Plot repository, open a terminal and `cd` in your forked repository. Then run Yarn to install dependencies:
1010

1111
```bash
12-
yarn
12+
pnpm install
1313
```
1414

1515
You may encounter an error installing [node-canvas](https://github.com/Automattic/node-canvas), such as:
@@ -28,24 +28,24 @@ brew install pkg-config cairo pango libpng jpeg giflib librsvg
2828

2929
## Testing
3030

31-
After making changes to Plot’s source code, run Plot’s test suite to verify that your code is doing what you expect and that you haven’t introduced any other unexpected changes in behavior. Plot has two types of tests: **unit tests** and **snapshot tests**. Tests are run automatically on pull requests (via GitHub Actions), but you’ll want to run them locally to verify your changes before opening a pull request. To run the tests, use Yarn:
31+
After making changes to Plot’s source code, run Plot’s test suite to verify that your code is doing what you expect and that you haven’t introduced any other unexpected changes in behavior. Plot has two types of tests: **unit tests** and **snapshot tests**. Tests are run automatically on pull requests (via GitHub Actions), but you’ll want to run them locally to verify your changes before opening a pull request. To run the tests:
3232

3333
```bash
34-
yarn test
34+
pnpm run test
3535
```
3636

3737
This will also run ESLint on Plot’s source to help catch simple mistakes, such as unused imports.
3838

3939
Please run Prettier before submitting any pull request. Check “format on save” in your code editor, or run:
4040

4141
```bash
42-
yarn prettier --write .
42+
pnpm exec prettier --write .
4343
```
4444

4545
A test coverage report can be generated with [c8](https://github.com/bcoe/c8), in text and lcov formats, to help you identify which lines of code are not (yet!) covered by tests. Just run:
4646

4747
```bash
48-
yarn test:coverage
48+
pnpm run test:coverage
4949
```
5050

5151
### Unit tests
@@ -65,7 +65,7 @@ Plot’s unit tests are written with [Mocha](https://mochajs.org).
6565
If you like, you can also run Mocha in watch mode for a specific file, so that unit tests re-run automatically when you make changes. For example:
6666

6767
```bash
68-
yarn run mocha --conditions=mocha --parallel --watch test/marks/bar-test.js
68+
pnpm run test:vitest test/marks/bar-test.js
6969
```
7070

7171
### Snapshot tests
@@ -98,7 +98,7 @@ export * from "./moby-dick.ts";
9898
The best thing about snapshot tests is that you can see the live result in your browser as you make changes to Plot’s source code! This lets you immediately assess visually what Plot is doing. To preview snapshot tests during development, Plot uses [Vite](https://vitejs.dev). To start Vite:
9999

100100
```bash
101-
yarn dev
101+
pnpm run dev
102102
```
103103

104104
This will open http://localhost:8008/ in your browser where you can choose a snapshot test. As you edit the source, the current test will update live in your browser as you save changes. You can change the selected test from the drop-down menu. When the drop-down menu is focused, the left and right arrow keys cycle between tests.
@@ -111,17 +111,17 @@ Running Plot’s snapshot tests will automatically generate any missing snapshot
111111

112112
```
113113
rm -rf test/output
114-
yarn test
114+
pnpm run test:vitest
115115
```
116116

117117
## Documentation
118118

119119
When submitting a pull request, please remember to update Plot’s documentation to reflect changes to the public API. You are also welcome to edit Plot’s [CHANGELOG.md](./CHANGELOG.md) to assist with writing future release notes. In addition, please reference any related [issues](https://github.com/observablehq/plot/issues) (or discussions) in your pull request description.
120120

121-
If you’d like to share a live demonstration or motivating example of your change to Plot, you can regenerate Plot’s release bundle using Yarn:
121+
If you’d like to share a live demonstration or motivating example of your change to Plot, you can regenerate Plot’s release bundle like so:
122122

123123
```bash
124-
yarn prepublishOnly
124+
pnpm run prepublishOnly
125125
```
126126

127127
The generated bundle `dist/plot.umd.js` can then be loaded like so:

docs/getting-started.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,20 @@ Then, create an `index.html` file as shown above in the **UMD + local** tab. If
9595

9696
## Installing from npm
9797

98-
If you’re developing a web application using Node, you can install Plot via yarn, npm, pnpm, or your preferred package manager.
98+
If you’re developing a web application using Node, you can install Plot via pnpm, npm, yarn, or your preferred package manager.
9999

100100
:::code-group
101101

102-
```bash [yarn]
103-
yarn add @observablehq/plot
102+
```bash [pnpm]
103+
pnpm add @observablehq/plot
104104
```
105105

106106
```bash [npm]
107107
npm install @observablehq/plot
108108
```
109109

110-
```bash [pnpm]
111-
pnpm add @observablehq/plot
110+
```bash [yarn]
111+
yarn add @observablehq/plot
112112
```
113113

114114
:::

package.json

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
"src/**/*.js"
2828
],
2929
"scripts": {
30-
"test": "yarn test:mocha && yarn test:tsc && yarn test:lint && yarn test:prettier",
31-
"test:coverage": "c8 yarn test:mocha",
32-
"test:mocha": "mkdir -p test/output && TZ=America/Los_Angeles tsx node_modules/.bin/mocha 'test/**/*-test.*' 'test/plot.*'",
30+
"test": "pnpm run test:vitest && pnpm run test:tsc && pnpm run test:lint && pnpm run test:prettier",
31+
"test:coverage": "TZ=America/Los_Angeles vitest run --coverage",
32+
"test:vitest": "TZ=America/Los_Angeles vitest --typecheck",
3333
"test:lint": "eslint src test",
3434
"test:prettier": "prettier --check src test",
3535
"test:tsc": "tsc",
@@ -52,40 +52,29 @@
5252
"@rollup/plugin-node-resolve": "^16.0.0",
5353
"@rollup/plugin-terser": "^0.4.0",
5454
"@types/d3": "^7.4.0",
55-
"@types/mocha": "^10.0.1",
5655
"@types/node": "^22.13.2",
5756
"@typescript-eslint/eslint-plugin": "^8.24.0",
5857
"@typescript-eslint/parser": "^8.24.0",
58+
"@vitest/coverage-v8": "^4.0.18",
5959
"apache-arrow": "^19.0.0",
60-
"c8": "^10.1.3",
6160
"canvas": "^3.1.0",
61+
"d3-format": "^3.1.2",
6262
"d3-geo-projection": "^4.0.0",
6363
"eslint": "^9.20.1",
6464
"eslint-config-prettier": "^10.0.1",
6565
"globals": "^15.15.0",
6666
"htl": "^0.3.0",
6767
"js-beautify": "1",
68-
"jsdom": "^26.0.0",
68+
"jsdom": "^29.0.1",
6969
"markdown-it-container": "^4.0.0",
70-
"mocha": "^11.1.0",
7170
"prettier": "~3.0.0",
7271
"rollup": "^4.9.1",
7372
"topojson-client": "^3.1.0",
7473
"ts-morph": "^25.0.1",
75-
"tsx": "^4.7.0",
7674
"typescript": "^5.0.2",
7775
"vite": "^6.1.0",
78-
"vitepress": "^1.3.1"
79-
},
80-
"c8": {
81-
"all": true,
82-
"include": [
83-
"src/**/*.js"
84-
],
85-
"reporter": [
86-
"text",
87-
"lcov"
88-
]
76+
"vitepress": "^1.3.1",
77+
"vitest": "^4.0.8"
8978
},
9079
"dependencies": {
9180
"d3": "^7.9.0",

0 commit comments

Comments
 (0)