Skip to content

Commit

Permalink
speed up golden rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
elalish committed May 17, 2024
1 parent c9a3ca0 commit 38ea88a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 84 deletions.
63 changes: 36 additions & 27 deletions src/workflows/render-goldens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@

import {spawn} from 'child_process';
import {promises as fs} from 'fs';
import HTTPServer from 'http-server';
import module from 'module';
import {dirname, join, resolve} from 'path';
import yargs from 'yargs';
import {hideBin} from 'yargs/helpers';

import {ArtifactCreator} from '../artifact-creator.js';
import {ImageComparisonConfig} from '../common.js';
import {ConfigReader} from '../config-reader.js';

import {rendererOffline} from './render-goldens/renderer-offline.js';
import {rendererScreenshot} from './render-goldens/renderer-screenshot.js';

type CommandLineArgs =
{
Expand Down Expand Up @@ -191,26 +192,34 @@ async function main() {

const configReader = new ConfigReader(config);

for (const scenarioBase of scenarios) {
const scenarioName = scenarioBase.name;
const scenario = configReader.scenarioConfig(scenarioName);
const {model, lighting, dimensions, exclude} = scenario!;
const scenarioGoldensDirectory = join(goldensDirectory, scenarioName);
const {width, height} = dimensions;

try {
await fs.mkdir(scenarioGoldensDirectory);
} catch (error) {
// Ignored...
}

for (const renderer of renderers) {
const {
name: rendererName,
description: rendererDescription,
scripts: scripts,
command: rendererCommand
} = renderer;
const server = HTTPServer.createServer({root: '', cache: -1});
server.listen(args.port);

for (const renderer of renderers) {
const {
name: rendererName,
description: rendererDescription,
scripts: scripts,
command: rendererCommand
} = renderer;

const screenshotCreator = new ArtifactCreator(
config,
rootDirectory,
`http://localhost:${args.port}/test/renderers/${rendererName}/`);

for (const scenarioBase of scenarios) {
const scenarioName = scenarioBase.name;
const scenario = configReader.scenarioConfig(scenarioName);
const {model, lighting, dimensions, exclude} = scenario!;
const scenarioGoldensDirectory = join(goldensDirectory, scenarioName);
const {width, height} = dimensions;

try {
await fs.mkdir(scenarioGoldensDirectory);
} catch (error) {
// Ignored...
}

if (exclude != null && exclude.includes(rendererName) ||
rendererWhitelist != null && !rendererWhitelist.has(rendererName)) {
Expand Down Expand Up @@ -277,23 +286,23 @@ async function main() {
}
} else {
try {
await rendererScreenshot(
config,
rootDirectory,
await screenshotCreator.captureScreenshot(
rendererName,
scenarioName,
dimensions,
goldenPath,
width,
height,
args.port,
-1,
args.quiet);
} catch (error) {
throw new Error(`Failed to update ${
rendererDescription} screenshot: ${error.message}`);
}
}
}

screenshotCreator.close();
}
server.close();
};

updateScreenshots(config).then(() => exit(0)).catch((error) => {
Expand Down
57 changes: 0 additions & 57 deletions src/workflows/render-goldens/renderer-screenshot.ts

This file was deleted.

0 comments on commit 38ea88a

Please sign in to comment.