Skip to content

Commit

Permalink
test: fix async tests
Browse files Browse the repository at this point in the history
Tape tests should not call t.end() in async tests. The GC object is no
longer instantiated with the tape context when returning a Promise.

Some of the tests are supposed to be WebGL-only.
  • Loading branch information
floryst committed Feb 26, 2025
1 parent 722db8a commit 472832c
Show file tree
Hide file tree
Showing 75 changed files with 1,189 additions and 1,088 deletions.
23 changes: 12 additions & 11 deletions Documentation/content/docs/develop_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ test('Validate vtkMyClass properties', (t) => {
```js ClassName/test/testRendering.js
import test from 'tape';

import vtkOpenGLRenderWindow from '../../../../Rendering/OpenGL/RenderWindow';
import vtkRenderWindow from '../../../../Rendering/Core/RenderWindow';
import vtkRenderer from '../../../../Rendering/Core/Renderer';
import vtkConeSource from '../../../../Filters/Sources/ConeSource';
import vtkActor from '../../../../Rendering/Core/Actor';
import vtkMapper from '../../../../Rendering/Core/Mapper';
import vtkOpenGLRenderWindow from '@kitware/vtk.js/Rendering/OpenGL/RenderWindow';
import vtkRenderWindow from '@kitware/vtk.js/Rendering/Core/RenderWindow';
import vtkRenderer from '@kitware/vtk.js/Rendering/Core/Renderer';
import vtkConeSource from '@kitware/vtk.js/Filters/Sources/ConeSource';
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';

import baseline from './testClassName.png';
import testUtils from '../../../../Testing/testUtils';
import testUtils from '@kitware/vtk.js/Testing/testUtils';

test.onlyIfWebGL('Test vtkClassName Rendering', (t) => {
// Create some control UI
Expand Down Expand Up @@ -82,11 +82,12 @@ test.onlyIfWebGL('Test vtkClassName Rendering', (t) => {
renderWindow.addView(glwindow);
glwindow.setSize(400, 400);

glwindow.captureNextImage().then((image) => {
const promise = glwindow.captureNextImage().then((image) => {
// compareImages(image, baselines, testName, tapeContext, threshold = 5, nextCallback = null)
testUtils.compareImages(image, [baseline], 'Filters/Sources/ConeSource/', t);
return testUtils.compareImages(image, [baseline], 'Filters/Sources/ConeSource/', t);
});
renderWindow.render();
return promise;
});
```

Expand Down Expand Up @@ -133,9 +134,9 @@ Follow the following procedure to create a new baseline or change an existing ba

- Add an invalid baseline (any PNG file) and rename it as the required baseline.
For example, to create a baseline for `testCylinder.js` copy *testCone.png* to *Sources/Filters/Sources/CylinderSource/test/testCylinder.png*.
- Run the test as per [Running a single test for debugging](#Running-a-single-test-for-debugging). The test should fail because of the invalid baseline.
- Run the test as per [Running a single test for debugging](#Running-a-single-test-for-debugging). The test should fail because of the invalid baseline.
- The test execution creates a file **Utilities/TestResults/Test-Report.html**. Open this in the browser.
- The file should show the test output versus the invalid baseline image, as well as a diff.
Right-click on the test output image and save it as the valid baseline.
- Re-run the test to ensure that it passes with the valid baseline.
- Commit the baseline image to the git source tree.
- Commit the baseline image to the git source tree.
25 changes: 14 additions & 11 deletions Sources/Common/Core/LookupTable/test/testCategoricalColors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
import baseline from './testCategoricalColors.png';

test.onlyIfWebGL('Test Categorical Colors', (t) => {
const gc = testUtils.createGarbageCollector(t);
const gc = testUtils.createGarbageCollector();
t.ok('rendering', 'vtkLookupTable TestCategoricalColors');
// testUtils.keepDOM();

Expand Down Expand Up @@ -108,15 +108,18 @@ test.onlyIfWebGL('Test Categorical Colors', (t) => {
renderWindow.addView(glwindow);
glwindow.setSize(400, 400);

glwindow.captureNextImage().then((image) => {
testUtils.compareImages(
image,
[baseline],
'Common/Core/LookupTable/testCategoricalColors',
t,
5,
gc.releaseResources
);
});
const promise = glwindow
.captureNextImage()
.then((image) =>
testUtils.compareImages(
image,
[baseline],
'Common/Core/LookupTable/testCategoricalColors',
t,
5
)
)
.finally(gc.releaseResources);
renderWindow.render();
return promise;
});
27 changes: 15 additions & 12 deletions Sources/Common/Core/LookupTable/test/testScalarBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import vtkScalarBarActor from 'vtk.js/Sources/Rendering/Core/ScalarBarActor';
import baseline from './testScalarBar.png';
import baseline2 from './testScalarBar2.png';

test('Test ScalarBar', (t) => {
const gc = testUtils.createGarbageCollector(t);
test.onlyIfWebGL('Test ScalarBar', (t) => {
const gc = testUtils.createGarbageCollector();
t.ok('rendering', 'vtkLookupTable TestScalarBar');

// Create some control UI
Expand Down Expand Up @@ -87,15 +87,18 @@ test('Test ScalarBar', (t) => {
renderer.resetCamera();
renderWindow.render();

glwindow.captureNextImage().then((image) => {
testUtils.compareImages(
image,
[baseline, baseline2],
'Common/Core/LookupTable/testScalarBar',
t,
5,
gc.releaseResources
);
});
const promise = glwindow
.captureNextImage()
.then((image) =>
testUtils.compareImages(
image,
[baseline, baseline2],
'Common/Core/LookupTable/testScalarBar',
t,
5
)
)
.finally(gc.releaseResources);
renderWindow.render();
return promise;
});
25 changes: 14 additions & 11 deletions Sources/Common/Core/LookupTable/test/testSetTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
import baseline from './testSetTable.png';

test.onlyIfWebGL('Test LookupTable setTable', (t) => {
const gc = testUtils.createGarbageCollector(t);
const gc = testUtils.createGarbageCollector();
t.ok('rendering', 'vtkLookupTable TestSetTable');
// testUtils.keepDOM();

Expand Down Expand Up @@ -132,15 +132,18 @@ test.onlyIfWebGL('Test LookupTable setTable', (t) => {
renderWindow.addView(glwindow);
glwindow.setSize(400, 400);

glwindow.captureNextImage().then((image) => {
testUtils.compareImages(
image,
[baseline],
'Common/Core/LookupTable/testSetTable',
t,
5,
gc.releaseResources
);
});
const promise = glwindow
.captureNextImage()
.then((image) =>
testUtils.compareImages(
image,
[baseline],
'Common/Core/LookupTable/testSetTable',
t,
5
)
)
.finally(gc.releaseResources);
renderWindow.render();
return promise;
});
25 changes: 14 additions & 11 deletions Sources/Common/DataModel/Cone/test/testConeImplicitFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import baseline from './testConeImplicitFunction.png';

test.onlyIfWebGL('Test Cone Implicit Function', (t) => {
const gc = testUtils.createGarbageCollector(t);
const gc = testUtils.createGarbageCollector();
t.ok('rendering', 'Cone Implicit Function');

// Create some control UI
Expand Down Expand Up @@ -59,15 +59,18 @@ test.onlyIfWebGL('Test Cone Implicit Function', (t) => {

renderWindow.render();

glwindow.captureNextImage().then((image) => {
testUtils.compareImages(
image,
[baseline],
'Common/DataModel/Cone/testConeImplicitFunction',
t,
1.0,
gc.releaseResources
);
});
const promise = glwindow
.captureNextImage()
.then((image) =>
testUtils.compareImages(
image,
[baseline],
'Common/DataModel/Cone/testConeImplicitFunction',
t,
1.0
)
)
.finally(gc.releaseResources);
renderWindow.render();
return promise;
});
25 changes: 14 additions & 11 deletions Sources/Filters/General/AppendPolyData/test/testAppendPolyData.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ test('Test addInputData edge case', (t) => {
});

test.onlyIfWebGL('Test vtkAppendPolyData rendering', (t) => {
const gc = testUtils.createGarbageCollector(t);
const gc = testUtils.createGarbageCollector();
t.ok('rendering', 'vtkAppendPolyData Rendering');

// Create some control UI
Expand Down Expand Up @@ -162,15 +162,18 @@ test.onlyIfWebGL('Test vtkAppendPolyData rendering', (t) => {
camera.azimuth(40);
renderer.resetCamera();

glwindow.captureNextImage().then((image) => {
testUtils.compareImages(
image,
[baseline],
'Filters/General/AppendPolyData/testAppendPolyData',
t,
2.5,
gc.releaseResources
);
});
const promise = glwindow
.captureNextImage()
.then((image) =>
testUtils.compareImages(
image,
[baseline],
'Filters/General/AppendPolyData/testAppendPolyData',
t,
2.5
)
)
.finally(gc.releaseResources);
renderWindow.render();
return promise;
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import baselineFaces from './testImageDataOutlineFilter_Faces.png';
import baselineLines from './testImageDataOutlineFilter_Lines.png';

test.onlyIfWebGL('Test ImageDataOutlineFilter', (t) => {
const gc = testUtils.createGarbageCollector(t);
const gc = testUtils.createGarbageCollector();

// Create some control UI
const container = document.querySelector('body');
Expand Down Expand Up @@ -140,21 +140,17 @@ test.onlyIfWebGL('Test ImageDataOutlineFilter', (t) => {
idoline.setGenerateLines(true);
idoline.setGenerateFaces(false);

let resolve;
const promise = new Promise((res) => {
resolve = res;
});

glwindow.captureNextImage().then((image) => {
testUtils.compareImages(
image,
[baselineLines],
'Filters/General/ImageDataOutlineFilter_Lines',
t,
1,
resolve
const promise = glwindow
.captureNextImage()
.then((image) =>
testUtils.compareImages(
image,
[baselineLines],
'Filters/General/ImageDataOutlineFilter_Lines',
t,
1
)
);
});

renderWindow.render();
return promise;
Expand All @@ -169,29 +165,23 @@ test.onlyIfWebGL('Test ImageDataOutlineFilter', (t) => {
idoline.setGenerateLines(false);
idoline.setGenerateFaces(true);

let resolve;
const promise = new Promise((res) => {
resolve = res;
});

glwindow.captureNextImage().then((image) => {
testUtils.compareImages(
image,
[baselineFaces],
'Filters/General/ImageDataOutlineFilter_Faces',
t,
1,
resolve
const promise = glwindow
.captureNextImage()
.then((image) =>
testUtils.compareImages(
image,
[baselineFaces],
'Filters/General/ImageDataOutlineFilter_Faces',
t,
1
)
);
});

renderWindow.render();
return promise;
}

[
testImageDataOutlineAsLines,
testImageDataOutlineAsFaces,
gc.releaseResources,
].reduce((current, next) => current.then(next), Promise.resolve());
return [testImageDataOutlineAsLines, testImageDataOutlineAsFaces]
.reduce((current, next) => current.then(next), Promise.resolve())
.finally(gc.releaseResources);
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import testMolecule from 'vtk.js/Data/molecule/test-multiple-bonds.cjson';
import baseline from './testMolecule_multiple_bonds.png';

test.onlyIfWebGL('Test MultipleBonds', (t) => {
const gc = testUtils.createGarbageCollector(t);
const gc = testUtils.createGarbageCollector();
t.ok('Filter: MoleculeToRepresentation');

// Create some control UI
Expand Down Expand Up @@ -71,15 +71,18 @@ test.onlyIfWebGL('Test MultipleBonds', (t) => {
glwindow.setSize(400, 400);

// capturing and comparing the images
glwindow.captureNextImage().then((image) => {
testUtils.compareImages(
image,
[baseline],
'Filters/General/MoleculeToRepresentation/testMultipleBonds',
t,
1,
gc.releaseResources
);
});
const promise = glwindow
.captureNextImage()
.then((image) =>
testUtils.compareImages(
image,
[baseline],
'Filters/General/MoleculeToRepresentation/testMultipleBonds',
t,
1
)
)
.finally(gc.releaseResources);
renderWindow.render();
return promise;
});
Loading

0 comments on commit 472832c

Please sign in to comment.