Skip to content

Commit 472832c

Browse files
committed
test: fix async tests
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.
1 parent 722db8a commit 472832c

File tree

75 files changed

+1189
-1088
lines changed

Some content is hidden

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

75 files changed

+1189
-1088
lines changed

Documentation/content/docs/develop_test.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ test('Validate vtkMyClass properties', (t) => {
4545
```js ClassName/test/testRendering.js
4646
import test from 'tape';
4747

48-
import vtkOpenGLRenderWindow from '../../../../Rendering/OpenGL/RenderWindow';
49-
import vtkRenderWindow from '../../../../Rendering/Core/RenderWindow';
50-
import vtkRenderer from '../../../../Rendering/Core/Renderer';
51-
import vtkConeSource from '../../../../Filters/Sources/ConeSource';
52-
import vtkActor from '../../../../Rendering/Core/Actor';
53-
import vtkMapper from '../../../../Rendering/Core/Mapper';
48+
import vtkOpenGLRenderWindow from '@kitware/vtk.js/Rendering/OpenGL/RenderWindow';
49+
import vtkRenderWindow from '@kitware/vtk.js/Rendering/Core/RenderWindow';
50+
import vtkRenderer from '@kitware/vtk.js/Rendering/Core/Renderer';
51+
import vtkConeSource from '@kitware/vtk.js/Filters/Sources/ConeSource';
52+
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
53+
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
5454

5555
import baseline from './testClassName.png';
56-
import testUtils from '../../../../Testing/testUtils';
56+
import testUtils from '@kitware/vtk.js/Testing/testUtils';
5757

5858
test.onlyIfWebGL('Test vtkClassName Rendering', (t) => {
5959
// Create some control UI
@@ -82,11 +82,12 @@ test.onlyIfWebGL('Test vtkClassName Rendering', (t) => {
8282
renderWindow.addView(glwindow);
8383
glwindow.setSize(400, 400);
8484

85-
glwindow.captureNextImage().then((image) => {
85+
const promise = glwindow.captureNextImage().then((image) => {
8686
// compareImages(image, baselines, testName, tapeContext, threshold = 5, nextCallback = null)
87-
testUtils.compareImages(image, [baseline], 'Filters/Sources/ConeSource/', t);
87+
return testUtils.compareImages(image, [baseline], 'Filters/Sources/ConeSource/', t);
8888
});
8989
renderWindow.render();
90+
return promise;
9091
});
9192
```
9293

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

134135
- Add an invalid baseline (any PNG file) and rename it as the required baseline.
135136
For example, to create a baseline for `testCylinder.js` copy *testCone.png* to *Sources/Filters/Sources/CylinderSource/test/testCylinder.png*.
136-
- 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.
137+
- 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.
137138
- The test execution creates a file **Utilities/TestResults/Test-Report.html**. Open this in the browser.
138139
- The file should show the test output versus the invalid baseline image, as well as a diff.
139140
Right-click on the test output image and save it as the valid baseline.
140141
- Re-run the test to ensure that it passes with the valid baseline.
141-
- Commit the baseline image to the git source tree.
142+
- Commit the baseline image to the git source tree.

Sources/Common/Core/LookupTable/test/testCategoricalColors.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
1313
import baseline from './testCategoricalColors.png';
1414

1515
test.onlyIfWebGL('Test Categorical Colors', (t) => {
16-
const gc = testUtils.createGarbageCollector(t);
16+
const gc = testUtils.createGarbageCollector();
1717
t.ok('rendering', 'vtkLookupTable TestCategoricalColors');
1818
// testUtils.keepDOM();
1919

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

111-
glwindow.captureNextImage().then((image) => {
112-
testUtils.compareImages(
113-
image,
114-
[baseline],
115-
'Common/Core/LookupTable/testCategoricalColors',
116-
t,
117-
5,
118-
gc.releaseResources
119-
);
120-
});
111+
const promise = glwindow
112+
.captureNextImage()
113+
.then((image) =>
114+
testUtils.compareImages(
115+
image,
116+
[baseline],
117+
'Common/Core/LookupTable/testCategoricalColors',
118+
t,
119+
5
120+
)
121+
)
122+
.finally(gc.releaseResources);
121123
renderWindow.render();
124+
return promise;
122125
});

Sources/Common/Core/LookupTable/test/testScalarBar.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import vtkScalarBarActor from 'vtk.js/Sources/Rendering/Core/ScalarBarActor';
1111
import baseline from './testScalarBar.png';
1212
import baseline2 from './testScalarBar2.png';
1313

14-
test('Test ScalarBar', (t) => {
15-
const gc = testUtils.createGarbageCollector(t);
14+
test.onlyIfWebGL('Test ScalarBar', (t) => {
15+
const gc = testUtils.createGarbageCollector();
1616
t.ok('rendering', 'vtkLookupTable TestScalarBar');
1717

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

90-
glwindow.captureNextImage().then((image) => {
91-
testUtils.compareImages(
92-
image,
93-
[baseline, baseline2],
94-
'Common/Core/LookupTable/testScalarBar',
95-
t,
96-
5,
97-
gc.releaseResources
98-
);
99-
});
90+
const promise = glwindow
91+
.captureNextImage()
92+
.then((image) =>
93+
testUtils.compareImages(
94+
image,
95+
[baseline, baseline2],
96+
'Common/Core/LookupTable/testScalarBar',
97+
t,
98+
5
99+
)
100+
)
101+
.finally(gc.releaseResources);
100102
renderWindow.render();
103+
return promise;
101104
});

Sources/Common/Core/LookupTable/test/testSetTable.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
1313
import baseline from './testSetTable.png';
1414

1515
test.onlyIfWebGL('Test LookupTable setTable', (t) => {
16-
const gc = testUtils.createGarbageCollector(t);
16+
const gc = testUtils.createGarbageCollector();
1717
t.ok('rendering', 'vtkLookupTable TestSetTable');
1818
// testUtils.keepDOM();
1919

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

135-
glwindow.captureNextImage().then((image) => {
136-
testUtils.compareImages(
137-
image,
138-
[baseline],
139-
'Common/Core/LookupTable/testSetTable',
140-
t,
141-
5,
142-
gc.releaseResources
143-
);
144-
});
135+
const promise = glwindow
136+
.captureNextImage()
137+
.then((image) =>
138+
testUtils.compareImages(
139+
image,
140+
[baseline],
141+
'Common/Core/LookupTable/testSetTable',
142+
t,
143+
5
144+
)
145+
)
146+
.finally(gc.releaseResources);
145147
renderWindow.render();
148+
return promise;
146149
});

Sources/Common/DataModel/Cone/test/testConeImplicitFunction.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
1313
import baseline from './testConeImplicitFunction.png';
1414

1515
test.onlyIfWebGL('Test Cone Implicit Function', (t) => {
16-
const gc = testUtils.createGarbageCollector(t);
16+
const gc = testUtils.createGarbageCollector();
1717
t.ok('rendering', 'Cone Implicit Function');
1818

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

6060
renderWindow.render();
6161

62-
glwindow.captureNextImage().then((image) => {
63-
testUtils.compareImages(
64-
image,
65-
[baseline],
66-
'Common/DataModel/Cone/testConeImplicitFunction',
67-
t,
68-
1.0,
69-
gc.releaseResources
70-
);
71-
});
62+
const promise = glwindow
63+
.captureNextImage()
64+
.then((image) =>
65+
testUtils.compareImages(
66+
image,
67+
[baseline],
68+
'Common/DataModel/Cone/testConeImplicitFunction',
69+
t,
70+
1.0
71+
)
72+
)
73+
.finally(gc.releaseResources);
7274
renderWindow.render();
75+
return promise;
7376
});

Sources/Filters/General/AppendPolyData/test/testAppendPolyData.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ test('Test addInputData edge case', (t) => {
9090
});
9191

9292
test.onlyIfWebGL('Test vtkAppendPolyData rendering', (t) => {
93-
const gc = testUtils.createGarbageCollector(t);
93+
const gc = testUtils.createGarbageCollector();
9494
t.ok('rendering', 'vtkAppendPolyData Rendering');
9595

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

165-
glwindow.captureNextImage().then((image) => {
166-
testUtils.compareImages(
167-
image,
168-
[baseline],
169-
'Filters/General/AppendPolyData/testAppendPolyData',
170-
t,
171-
2.5,
172-
gc.releaseResources
173-
);
174-
});
165+
const promise = glwindow
166+
.captureNextImage()
167+
.then((image) =>
168+
testUtils.compareImages(
169+
image,
170+
[baseline],
171+
'Filters/General/AppendPolyData/testAppendPolyData',
172+
t,
173+
2.5
174+
)
175+
)
176+
.finally(gc.releaseResources);
175177
renderWindow.render();
178+
return promise;
176179
});

Sources/Filters/General/ImageDataOutlineFilter/test/testImageDataOutlineFilter.js

+24-34
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import baselineFaces from './testImageDataOutlineFilter_Faces.png';
2222
import baselineLines from './testImageDataOutlineFilter_Lines.png';
2323

2424
test.onlyIfWebGL('Test ImageDataOutlineFilter', (t) => {
25-
const gc = testUtils.createGarbageCollector(t);
25+
const gc = testUtils.createGarbageCollector();
2626

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

143-
let resolve;
144-
const promise = new Promise((res) => {
145-
resolve = res;
146-
});
147-
148-
glwindow.captureNextImage().then((image) => {
149-
testUtils.compareImages(
150-
image,
151-
[baselineLines],
152-
'Filters/General/ImageDataOutlineFilter_Lines',
153-
t,
154-
1,
155-
resolve
143+
const promise = glwindow
144+
.captureNextImage()
145+
.then((image) =>
146+
testUtils.compareImages(
147+
image,
148+
[baselineLines],
149+
'Filters/General/ImageDataOutlineFilter_Lines',
150+
t,
151+
1
152+
)
156153
);
157-
});
158154

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

172-
let resolve;
173-
const promise = new Promise((res) => {
174-
resolve = res;
175-
});
176-
177-
glwindow.captureNextImage().then((image) => {
178-
testUtils.compareImages(
179-
image,
180-
[baselineFaces],
181-
'Filters/General/ImageDataOutlineFilter_Faces',
182-
t,
183-
1,
184-
resolve
168+
const promise = glwindow
169+
.captureNextImage()
170+
.then((image) =>
171+
testUtils.compareImages(
172+
image,
173+
[baselineFaces],
174+
'Filters/General/ImageDataOutlineFilter_Faces',
175+
t,
176+
1
177+
)
185178
);
186-
});
187179

188180
renderWindow.render();
189181
return promise;
190182
}
191183

192-
[
193-
testImageDataOutlineAsLines,
194-
testImageDataOutlineAsFaces,
195-
gc.releaseResources,
196-
].reduce((current, next) => current.then(next), Promise.resolve());
184+
return [testImageDataOutlineAsLines, testImageDataOutlineAsFaces]
185+
.reduce((current, next) => current.then(next), Promise.resolve())
186+
.finally(gc.releaseResources);
197187
});

Sources/Filters/General/MoleculeToRepresentation/test/testMultipleBonds.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import testMolecule from 'vtk.js/Data/molecule/test-multiple-bonds.cjson';
1414
import baseline from './testMolecule_multiple_bonds.png';
1515

1616
test.onlyIfWebGL('Test MultipleBonds', (t) => {
17-
const gc = testUtils.createGarbageCollector(t);
17+
const gc = testUtils.createGarbageCollector();
1818
t.ok('Filter: MoleculeToRepresentation');
1919

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

7373
// capturing and comparing the images
74-
glwindow.captureNextImage().then((image) => {
75-
testUtils.compareImages(
76-
image,
77-
[baseline],
78-
'Filters/General/MoleculeToRepresentation/testMultipleBonds',
79-
t,
80-
1,
81-
gc.releaseResources
82-
);
83-
});
74+
const promise = glwindow
75+
.captureNextImage()
76+
.then((image) =>
77+
testUtils.compareImages(
78+
image,
79+
[baseline],
80+
'Filters/General/MoleculeToRepresentation/testMultipleBonds',
81+
t,
82+
1
83+
)
84+
)
85+
.finally(gc.releaseResources);
8486
renderWindow.render();
87+
return promise;
8588
});

0 commit comments

Comments
 (0)