Skip to content

Commit

Permalink
chore: always upload snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed Nov 30, 2023
1 parent 556ad9c commit a7f8250
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 153 deletions.
6 changes: 3 additions & 3 deletions __tests__/integration/canvas.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as _2d from '../demos/2d';
import * as d3 from '../demos/d3';
import { generateCanvasTestCase } from './canvas';
import { generateCanvasTestCase } from './utils/generator';

describe('Canvas Snapshot', () => {
generateCanvasTestCase('2d', _2d);
// generateCanvasTestCase('d3', d3);
generateCanvasTestCase('canvas', '2d', _2d);
generateCanvasTestCase('canvas', 'd3', d3);
});
43 changes: 5 additions & 38 deletions __tests__/integration/svg.spec.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
import { chromium, devices } from 'playwright';
import * as basic2d from '../demos/2d';
import './utils/useSnapshotMatchers';
import { sleep } from './utils/sleep';
import * as _2d from '../demos/2d';
import * as d3 from '../demos/d3';
import { generateCanvasTestCase } from './utils/generator';

const namespace = '2d';
describe('SVG Snapshot', () => {
Object.keys(basic2d).forEach((key) => {
it(key, async () => {
// Setup
const browser = await chromium.launch({
args: ['--headless', '--no-sandbox'],
});
const context = await browser.newContext(devices['Desktop Chrome']);
const page = await context.newPage();

await page.addInitScript(() => {
window['USE_PLAYWRIGHT'] = 1;
window['DEFAULT_RENDERER'] = 'svg';
});

// Go to test page served by vite devServer.
const url = `http://localhost:${globalThis.PORT}/?name=${namespace}-${key}`;
await page.goto(url);

await sleep(300);

// Chart already rendered, capture into buffer.
const buffer = await page.locator('svg').screenshot();

const dir = `${__dirname}/snapshots/${namespace}/svg`;
try {
const maxError = 0;
expect(buffer).toMatchCanvasSnapshot(dir, key, { maxError });
} finally {
await context.close();
await browser.close();
}
});
});
generateCanvasTestCase('svg', '2d', _2d);
generateCanvasTestCase('svg', 'd3', d3);
});
69 changes: 0 additions & 69 deletions __tests__/integration/util.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { chromium, devices } from 'playwright';
import './utils/useSnapshotMatchers';
import { sleep } from './utils/sleep';
import './useSnapshotMatchers';
import { sleep } from './sleep';

export function generateCanvasTestCase(
renderer: 'canvas' | 'svg' | 'webgl',
namespace: string,
tests: Record<string, any>,
params?: Partial<{
Expand All @@ -23,7 +24,7 @@ export function generateCanvasTestCase(

await page.addInitScript(() => {
window['USE_PLAYWRIGHT'] = 1;
window['DEFAULT_RENDERER'] = 'canvas';
window['DEFAULT_RENDERER'] = renderer;
window['CANVAS_WIDTH'] = width;
window['CANVAS_HEIGHT'] = height;
});
Expand All @@ -35,9 +36,11 @@ export function generateCanvasTestCase(
await sleep(300);

// Chart already rendered, capture into buffer.
const buffer = await page.locator('canvas').screenshot();
const buffer = await page
.locator(renderer === 'svg' ? 'svg' : 'canvas')
.screenshot();

const dir = `${__dirname}/snapshots/${namespace}/canvas`;
const dir = `${__dirname}/snapshots/${namespace}/${renderer}`;
try {
const maxError = 0;
expect(buffer).toMatchCanvasSnapshot(dir, key, { maxError });
Expand Down
43 changes: 5 additions & 38 deletions __tests__/integration/webgl.spec.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
import { chromium, devices } from 'playwright';
import * as basic2d from '../demos/2d';
import './utils/useSnapshotMatchers';
import { sleep } from './utils/sleep';
import * as _2d from '../demos/2d';
import * as d3 from '../demos/d3';
import { generateCanvasTestCase } from './utils/generator';

const namespace = '2d';
describe('WebGL Snapshot', () => {
Object.keys(basic2d).forEach((key) => {
it(key, async () => {
// Setup
const browser = await chromium.launch({
args: ['--headless', '--no-sandbox'],
});
const context = await browser.newContext(devices['Desktop Chrome']);
const page = await context.newPage();

await page.addInitScript(() => {
window['USE_PLAYWRIGHT'] = 1;
window['DEFAULT_RENDERER'] = 'webgl';
});

// Go to test page served by vite devServer.
const url = `http://localhost:${globalThis.PORT}/?name=${namespace}-${key}`;
await page.goto(url);

await sleep(300);

// Chart already rendered, capture into buffer.
const buffer = await page.locator('canvas').screenshot();

const dir = `${__dirname}/snapshots/${namespace}/webgl`;
try {
const maxError = 0;
expect(buffer).toMatchCanvasSnapshot(dir, key, { maxError });
} finally {
await context.close();
await browser.close();
}
});
});
generateCanvasTestCase('webgl', '2d', _2d);
generateCanvasTestCase('webgl', 'd3', d3);
});

0 comments on commit a7f8250

Please sign in to comment.