Skip to content

Commit 973cc04

Browse files
authored
Tests: Update Unit Test Readme (#25453)
* Update Unit Test Readme Update unit test readme to reflect changes since #25380 Avoid building the library and flagging the files as changed (tests run off source) Add notes to help people running unit tests. ColorManagement.enabled is false by default. Tune logging so only genuine test failure messages are displayed. * Update ColorManagement.tests.js Minimize the console messages captured.
1 parent 57b456c commit 973cc04

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

test/unit/README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
## Setup
22

3-
- Execute `npm i --prefix test` from root folder
3+
- Execute `npm install` from the root folder
44

55
## Run
66

77
You can run the unit tests in two environments:
88

9-
- Node.js: Execute `npm run test-unit` from root folder
10-
- Browser: Execute `npm start` (or run any other local web sever) from root folder and access `http://localhost:8080/test/unit/UnitTests.html` on web browser. (See [How to run things locally](https://threejs.org/docs/#manual/introduction/How-to-run-things-locally))
9+
- Node.js: Execute `npm run test-unit` from the root folder
10+
- Browser: Execute `npx servez -p 8080 --ssl` (or run any other local web sever) from the root folder and access `https://localhost:8080/test/unit/UnitTests.html` in a web browser.
11+
12+
See [How to run things locally](https://threejs.org/docs/#manual/introduction/How-to-run-things-locally) for more information.
13+
14+
## Notes
15+
16+
Some tests can only be run in a browser environment.
17+
18+
For browser tests, futher changes to the library will not be reflected until the page is refreshed.
19+
20+
When adding or updating tests, the cost common cause of test failure is forgetting to change `QUnit.todo` to `QUnit.test` when the test is ready.
21+
22+
## Debugging
23+
24+
To debug a test, add `debugger;` to the test code. Then, run the test in a browser and open the developer tools. The test will stop at the `debugger` statement and you can inspect the code.
25+

test/unit/src/math/ColorManagement.tests.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,33 @@
22

33
import { ColorManagement } from '../../../../src/math/ColorManagement.js';
44

5+
import { CONSOLE_LEVEL } from '../../utils/console-wrapper.js';
6+
57
export default QUnit.module( 'Maths', () => {
68

79
QUnit.module( 'ColorManagement', () => {
810

911
// PROPERTIES
12+
QUnit.test( 'enabled', ( assert ) => {
13+
14+
assert.ok(
15+
ColorManagement.enabled == false,
16+
'ColorManagement.enabled is false by default.'
17+
);
18+
19+
} );
20+
1021
QUnit.test( 'legacyMode', ( assert ) => {
1122

23+
// surpress the following console message during testing
24+
// THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150.
25+
26+
console.level = CONSOLE_LEVEL.OFF;
27+
const expected = ColorManagement.legacyMode == true;
28+
console.level = CONSOLE_LEVEL.DEFAULT;
29+
1230
assert.ok(
13-
ColorManagement.legacyMode == true,
31+
expected,
1432
'ColorManagement.legacyMode is true by default.'
1533
);
1634

0 commit comments

Comments
 (0)