mirror of
https://github.com/nature-of-code/noc-book-2
synced 2024-11-16 07:47:48 +01:00
test update: screenshots dimensions exception list
This commit is contained in:
parent
fe14982fb5
commit
6cf28f7312
1 changed files with 21 additions and 6 deletions
|
@ -8,6 +8,12 @@ const editorUrls = getEditorUrls();
|
|||
|
||||
// ---
|
||||
|
||||
const exceptions = new Map([
|
||||
['figure_4_8_image', [1280, 480]],
|
||||
['figure_4_8_circles', [1280, 480]],
|
||||
['figure_i_2_bell_curve', [1440, 480]],
|
||||
]);
|
||||
|
||||
describe('Validate examples screenshots`', () => {
|
||||
const createCanvasRegex = /\s*createCanvas\(\s*(\d+)\s*,\s*(\d+)/;
|
||||
|
||||
|
@ -17,12 +23,21 @@ describe('Validate examples screenshots`', () => {
|
|||
const screenshotPath = path.join(exampleDir, 'screenshot.png');
|
||||
expect(fs.existsSync(screenshotPath)).toBe(true);
|
||||
|
||||
// extract the sketch canvas dimensions from the `createCanvas()` function call in `sketch.js`
|
||||
const sketchFilePath = path.join(exampleDir, 'sketch.js');
|
||||
const sketchFile = fs.readFileSync(sketchFilePath).toString();
|
||||
const canvasSize = createCanvasRegex.exec(sketchFile);
|
||||
const expectedWidth = Number(canvasSize[1]) * 2;
|
||||
const expectedHeight = Number(canvasSize[2]) * 2;
|
||||
let expectedWidth;
|
||||
let expectedHeight;
|
||||
const dirName = path.basename(exampleDir);
|
||||
|
||||
if (exceptions.has(dirName)) {
|
||||
// use the dimensions from the `exceptions` map
|
||||
[expectedWidth, expectedHeight] = exceptions.get(dirName);
|
||||
} else {
|
||||
// extract the sketch canvas dimensions from the `createCanvas()` function call in `sketch.js`
|
||||
const sketchFilePath = path.join(exampleDir, 'sketch.js');
|
||||
const sketchFile = fs.readFileSync(sketchFilePath).toString();
|
||||
const canvasSize = createCanvasRegex.exec(sketchFile);
|
||||
expectedWidth = Number(canvasSize[1]) * 2;
|
||||
expectedHeight = Number(canvasSize[2]) * 2;
|
||||
}
|
||||
|
||||
// get the actual dimensions of the screenshot
|
||||
const { width, height } = await sharp(screenshotPath).metadata();
|
||||
|
|
Loading…
Reference in a new issue