Skip to content

Commit

Permalink
Tests: Update Unit Test Readme (#25453)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
epreston authored Feb 7, 2023
1 parent 57b456c commit 973cc04
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
21 changes: 18 additions & 3 deletions test/unit/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
## Setup

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

## Run

You can run the unit tests in two environments:

- Node.js: Execute `npm run test-unit` from root folder
- 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))
- Node.js: Execute `npm run test-unit` from the root folder
- 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.

See [How to run things locally](https://threejs.org/docs/#manual/introduction/How-to-run-things-locally) for more information.

## Notes

Some tests can only be run in a browser environment.

For browser tests, futher changes to the library will not be reflected until the page is refreshed.

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.

## Debugging

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.

20 changes: 19 additions & 1 deletion test/unit/src/math/ColorManagement.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@

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

import { CONSOLE_LEVEL } from '../../utils/console-wrapper.js';

export default QUnit.module( 'Maths', () => {

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

// PROPERTIES
QUnit.test( 'enabled', ( assert ) => {

assert.ok(
ColorManagement.enabled == false,
'ColorManagement.enabled is false by default.'
);

} );

QUnit.test( 'legacyMode', ( assert ) => {

// surpress the following console message during testing
// THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150.

console.level = CONSOLE_LEVEL.OFF;
const expected = ColorManagement.legacyMode == true;
console.level = CONSOLE_LEVEL.DEFAULT;

assert.ok(
ColorManagement.legacyMode == true,
expected,
'ColorManagement.legacyMode is true by default.'
);

Expand Down

0 comments on commit 973cc04

Please sign in to comment.