Skip to content

Commit

Permalink
catch errors better
Browse files Browse the repository at this point in the history
  • Loading branch information
elalish committed Oct 21, 2024
1 parent 7a82c5c commit fa4bcbb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/render-fidelity-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "<model-viewer> rendering fidelity test suite and tools",
"scripts": {
"test": "node --experimental-modules ./lib/workflows/test-fidelity.js --config=./test/config.json",
"test:ci": "npm test",
"test:ci": "echo \"CI fidelity tests have a separate run\" && exit 0",
"render-goldens": "node --experimental-modules ./lib/workflows/render-goldens.js --config=./test/config.json",
"build": "tsc && rollup -c",
"prepare": "if [ ! -L './shared-assets' ]; then ln -s ../shared-assets ./shared-assets; fi",
Expand Down
14 changes: 9 additions & 5 deletions packages/render-fidelity-tools/src/artifact-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface ScenarioRecord extends ScenarioConfig {

export class ArtifactCreator {
private[$configReader]: ConfigReader = new ConfigReader(this.config);
private browser: Browser|undefined = undefined;
private browser: Browser|null = null;

constructor(
protected config: ImageComparisonConfig, protected rootDirectory: string,
Expand All @@ -42,9 +42,9 @@ export class ArtifactCreator {
}

async close() {
if (this.browser !== undefined) {
if (this.browser != null) {
await this.browser.close();
this.browser = undefined;
this.browser = null;
}
}
protected get outputDirectory(): string {
Expand Down Expand Up @@ -142,6 +142,10 @@ export class ArtifactCreator {
screenshot = await this.captureScreenshot(
renderer, scenarioName, dimensions, '', 60, quiet);
} catch (error) {
if (this.browser != null) {
await this.browser.close();
this.browser = null;
}
throw new Error(`❌ Failed to capture ${renderer}'s screenshot of ${
scenarioName}. Error message: ${error.message}`);
}
Expand Down Expand Up @@ -294,7 +298,7 @@ export class ArtifactCreator {
return;
}

if (this.browser == undefined) {
if (this.browser == null) {
console.log(`🚀 Launching browser`);
this.browser = await puppeteer.launch({headless: quiet});
}
Expand Down Expand Up @@ -364,7 +368,7 @@ export class ArtifactCreator {
if (evaluateError) {
console.log(evaluateError);
await this.browser.close();
this.browser = undefined;
this.browser = null;
throw new Error(evaluateError);
}

Expand Down

0 comments on commit fa4bcbb

Please sign in to comment.