Skip to content

Commit b65080f

Browse files
committed
Merge branch 'dev-2.0' into webgpu
2 parents e7c1d6b + b858de8 commit b65080f

36 files changed

+7283
-5660
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 54 deletions
This file was deleted.

.github/config.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,26 @@
44

55
# Comment to be posted to on first time issues
66
newIssueWelcomeComment: >
7-
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!
8-
# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome
7+
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms.
8+
9+
For guidance on contributing, check out our [contributing guidelines](https://github.com/processing/p5.js/blob/main/CONTRIBUTING.md) and other [resources for contributors](https://p5js.org/contribute/).
10+
11+
💬 If you have questions or need support, feel free to join the [Processing Foundation Forum](https://discourse.processing.org/) or visit our [Community page](https://p5js.org/community/).
912
13+
📜 Please also review our [Code of Conduct](https://p5js.org/code-of-conduct/) to understand our community standards.
14+
15+
Thank You!
16+
# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome
1017
# Comment to be posted to on PRs from first time contributors in your repository
1118
newPRWelcomeComment: >
12-
🎉 Thanks for opening this pull request! Please check out our [contributing guidelines](https://github.com/processing/p5.js/blob/main/CONTRIBUTING.md) if you haven't already. And be sure to add yourself to the [list of contributors on the readme page](https://github.com/processing/p5.js#contributors)!
19+
🎉 Thanks for opening this pull request! For guidance on contributing, check out our [contributor guidelines](https://p5js.org/contribute/contributor_guidelines/) and other [resources for contributors](https://p5js.org/contribute)!
20+
21+
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
22+
23+
🌸 Once your PR is merged, be sure to [add yourself](https://github.com/processing/p5.js/issues/2309) to the [list of contributors on the readme page](https://github.com/processing/p5.js#contributors) !
24+
25+
26+
Thank You!
1327
1428
# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge
1529

.gitignore

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1-
*.DS_Store
2-
.project
1+
!*.gitkeep
2+
3+
.nyc_output/*
4+
# .vscode/settings.json
35
node_modules/*
6+
7+
analyzer/
8+
bower-repo/
9+
coverage/
10+
examples/3d/
411
experiments/*
12+
dist/
13+
docs/reference/*
14+
docs/data.json
515
lib_old/*
616
lib/p5.*
17+
lib/p5-test.js
718
lib/modules
8-
docs/reference/*
9-
!*.gitkeep
10-
examples/3d/
11-
.idea
12-
dist/
13-
*.d.ts
14-
p5.zip
15-
bower-repo/
1619
p5-website/
17-
.vscode/settings.json
18-
.nyc_output/*
19-
coverage/
20-
lib/p5-test.js
20+
preview/
2121
release/
22+
__screenshots__/
23+
24+
*.d.ts
25+
p5.zip
2226
yarn.lock
23-
docs/data.json
24-
analyzer/
25-
preview/
26-
__screenshots__/
27+
todo.md
28+
29+
*.DS_Store
30+
.idea
31+
.project

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"prettier.enable": false,
3+
"eslint.enable": true,
4+
"eslint.validate": [
5+
{ "language": "html", "autoFix": false },
6+
{ "language": "javascript", "autoFix": false },
7+
{ "language": "markdown", "autoFix": false },
8+
],
9+
"editor.defaultFormatter": null,
10+
"editor.formatOnSave": false,
11+
"editor.codeActionsOnSave": {},
12+
"javascript.format.enable": false
13+
}
203 KB
Loading
143 KB
Loading

contributor_docs/unit_testing.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ As you can see, the subfolders in the `unit` subfolder roughly correspond to the
2525

2626
## Testing frameworks
2727

28-
p5.js uses [Mocha](https://mochajs.org) as a test runner. It is responsible for running the test code as well as providing a solid framework for reporting test results (i.e., the very long output you see in the terminal when you run the tests!)
28+
p5.js 2.0 runs its tests with [Vitest](https://vitest.dev), which provides Mocha-compatible globals (`suite`, `test`, etc.). It is responsible for running the test code as well as providing a solid framework for reporting test results (i.e., the very long output you see in the terminal when you run the tests!)
2929

30-
However, Mocha by itself doesn’t do any testing; for that, we need an assertion library. An assertion library is a collection of handy functions that lets us test various properties of our code, such as whether two values are equal, two values are of the same type, whether a function throws an error, and many more. p5.js uses [Chai's `assert` (and `expect`)](https://www.chaijs.com/api/assert/) to write individual statements about how the code should behave.
30+
However, Vitest still needs an assertion layer, and it bundles Chai for that. An assertion library is a collection of handy functions that lets us test various properties of our code, such as whether two values are equal, two values are of the same type, whether a function throws an error, and many more. p5.js uses [Chai's `assert` (and `expect`)](https://www.chaijs.com/api/assert/) to write individual statements about how the code should behave. You can also import `assert` and `expect` straight from Vitest (Vitest bundles Chai internally):
31+
32+
```js
33+
import { assert, expect } from 'vitest'
34+
```
3135

3236

3337
## Writing unit tests
@@ -40,7 +44,7 @@ To start writing unit tests, first pick a unit. A unit can be a function or a va
4044
- it should be `true` if multiple keys are pressed
4145
- it should be `false` if no keys are pressed
4246

43-
In the example below, `suite()` and `test()` are both built-in functions provided by Mocha as part of the test environment. If you look into the test file (eg. `test/unit/events/keyboard.js`) you may find additional built-in functions such as `setup()` and `teardown()` as well. Each `suite()` describes a unit of p5.js that you are writing a test for (a function, a variable, etc). Each `test()` in a `suite()` is an individual test case that checks a single feature/behavior of the unit being tested. The first argument passed to `suite()` and `test()` is a description of the suite/test, and its purpose is to give clear output in the terminal for the test case.
47+
In the example below, `suite()` and `test()` are both built-in functions provided by Vitest’s Mocha-compatible API. If you look into the test file (eg. `test/unit/events/keyboard.js`) you may find additional built-in functions such as `setup()` and `teardown()` as well. Each `suite()` describes a unit of p5.js that you are writing a test for (a function, a variable, etc). Each `test()` in a `suite()` is an individual test case that checks a single feature/behavior of the unit being tested. The first argument passed to `suite()` and `test()` is a description of the suite/test, and its purpose is to give clear output in the terminal for the test case.
4448

4549
- `p5.prototype.keyIsPressed` is the unit being tested in this suite.
4650
- There are three tests in this suite:
@@ -81,7 +85,7 @@ setup(function(done) {
8185

8286
The `p` parameter, which is used in instance mode to access various p5.js variables and functions, is then assigned to `myp5`. This setup allows you to use `myp5` to access p5.js variables and functions anywhere in the testing code to test their functionalities.
8387

84-
Remember that, as previously mentioned, Mocha is a test runner but by itself doesn’t do any testing; we need Chai for that. Consider the following:
88+
Remember, Vitest supplies the runner; Chai (bundled by Vitest) supplies the assertions. Consider the following:
8589

8690
```js
8791
test('keyIsPressed is a boolean', function() {
@@ -182,10 +186,14 @@ Here are the conventions and best practices that p5.js uses for unit tests which
182186

183187
## Running tests
184188

185-
The most straightforward way to run the tests is by using the `npm test` command in your terminal. However, `npm test` usually takes a long time to run simply because of the large number of test cases p5.js has. It can also sometimes be a bit repetitive to make some changes, run `npm test`, make some more changes, and run `npm test` again. Here are some tricks that can help streamline this process:
189+
The most straightforward way to run the tests is by using the `npm test` command in your terminal. However, `npm test` usually takes a long time to run simply because of the large number of test cases p5.js has. We don’t need to run `npm test` over and over after each change. As soon as we save our code, we can see in the browser or terminal whether the tests pass or not.
190+
191+
This screenshot shows how the test executes on the website and in the terminal.
192+
193+
<img src="./images/unit-visual-test.png" width="300" alt="Web test" /> | <img src="./images/unit-visual-test-terminal.png" width="250" alt="Terminal test" />
186194

187-
- Use the `npx grunt watch:main` command to automatically build and test p5.js whenever you save changes to p5.js source files. This will save you from having to manually run tests whenever you are making frequent changes to the codebase.
188-
- You can mark certain test suites to be skipped or be the only suite that is run with the `.skip` and `.only` syntax.
195+
196+
- You can also mark certain test suites to be skipped or be the only suite that is run with the `.skip` and `.only` syntax.
189197

190198
```js
191199
// This test suite will not run
@@ -199,7 +207,11 @@ The most straightforward way to run the tests is by using the `npm test` command
199207
});
200208
```
201209

202-
- You can also run `grunt yui:dev` to launch a local server with the reference and a test runner. Once live, you can go to [`http://127.0.0.1:9001/test/test.html`](http://127.0.0.1:9001/test/test.html) to run tests live in your browser. This can be useful if you want to use a debugger in the middle of a test case or if you want to log complex objects. If you want to filter tests by the name of the test case, you can add a search term after a `?grep=` URL parameter, e.g.: [`http://127.0.0.1:9001/test/test.html?grep=framebuffer`](http://127.0.0.1:9001/test/test.html?grep=framebuffer)
210+
- When you run `npm test`, Vitest launches two browser windows. The first window (usually at http://localhost:63315) renders and executes all unit and visual tests; it provides a built‐in interface where you can click on filters (for failed, skipped, passed tests, etc.) to narrow down the results. The layout in this window is self-explanatory. Each test suite and spec is listed with its status, and you can easily expand or collapse sections to see details, rerun individual tests, or inspect error messages.
211+
212+
- The second window hosts Vitest’s DevTools/BiDi control channel, where you’ll see raw JSON frames exchanged between Vitest and the browser. That second window isn’t an extra test suite, it simply facilitates communication and result reporting, so you can safely ignore it unless you’re debugging Vitest’s runner itself.
213+
214+
203215

204216

205217
## Visual tests
@@ -217,13 +229,11 @@ visualTest('2D objects maintain correct size', function(p5, screenshot) {
217229
});
218230
```
219231

220-
If you need to add a new test file, add it to that folder, then add the filename to the list in `test/visual/visualTestList.js`. Additionally, if you want that file to be run automatically as part of continuous integration on every pull request, add the filename to the `visual` list in `test/unit/spec.js`.
232+
To add a new test file, place it into `test/unit/visual/cases`. This will be auto-discovered by Vitest - no manual registration needed.
221233

222234
When you add a new test, running `npm test` will generate new screenshots for any visual tests that do not yet have them. Those screenshots will then be used as a reference the next time tests run to make sure the sketch looks the same. If a test intentionally needs to look different, you can delete the folder matching the test name in the `test/unit/visual/screenshots` folder, and then re-run `npm test` to generate a new one.
223235

224-
To manually inspect all visual tests, run `grunt yui:dev` to launch a local server, then go to http://127.0.0.1:9001/test/visual.html to see a list of all test cases.
225-
226-
236+
Running `npm test` launches Vitest’s interactive UI at http://localhost:63315, where you can view the list of all test cases including visual tests as well.
227237
In a continuous integration (CI) environment, optimizing test speed is essential. It is advantageous to keep the code concise, avoid unnecessary frames, minimize canvas size, and load assets only when essential for the specific functionality under test.
228238
To address scenarios involving operations like asynchronous 3D model rendering, consider returning a promise that resolves upon completing all the necessary tests, ensuring efficiency in your visual testing approach. Here's an example of how you can asynchronous 3D model rendering in your visual tests:
229239

0 commit comments

Comments
 (0)