Skip to content

Commit

Permalink
chore: update path
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed May 23, 2024
1 parent 373c622 commit 2389d00
Show file tree
Hide file tree
Showing 94 changed files with 54 additions and 22 deletions.
2 changes: 1 addition & 1 deletion __tests__/integration/gallery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ const TEST_CASES = [
];

describe('Gallery Snapshot', () => {
generateCanvasTestCases('Gallery', TEST_CASES);
generateCanvasTestCases('gallery', TEST_CASES);
});
2 changes: 1 addition & 1 deletion __tests__/integration/heatmap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ const TEST_CASES = [
];

describe('Heatmap Snapshot', () => {
generateCanvasTestCases('Heatmap', TEST_CASES);
generateCanvasTestCases('heatmap', TEST_CASES);
});
2 changes: 1 addition & 1 deletion __tests__/integration/line.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ const TEST_CASES = [
];

describe('Line Snapshot', () => {
generateCanvasTestCases('Line', TEST_CASES);
generateCanvasTestCases('line', TEST_CASES);
});
2 changes: 1 addition & 1 deletion __tests__/integration/mask.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ const TEST_CASES = [
];

describe('Mask Snapshot', () => {
generateCanvasTestCases('Mask', TEST_CASES);
generateCanvasTestCases('mask', TEST_CASES);
});
3 changes: 1 addition & 2 deletions __tests__/integration/point.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const TEST_CASES = [
},
{
name: 'fill_image',
sleepTime: 1000,
},
{
name: 'image',
Expand All @@ -28,5 +27,5 @@ const TEST_CASES = [
];

describe('Point Snapshot', () => {
generateCanvasTestCases('Point', TEST_CASES);
generateCanvasTestCases('point', TEST_CASES);
});
2 changes: 1 addition & 1 deletion __tests__/integration/polygon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ const TEST_CASES = [
];

describe('Polygon Snapshot', () => {
generateCanvasTestCases('Polygon', TEST_CASES);
generateCanvasTestCases('polygon', TEST_CASES);
});
26 changes: 19 additions & 7 deletions __tests__/integration/utils/generator.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import type { Browser, BrowserContext, Page } from 'playwright';
import type { Browser, BrowserContext } from 'playwright';
import { chromium, devices } from 'playwright';
import { sleep } from './sleep';
import './useSnapshotMatchers';

export function generateCanvasTestCases(
namespace: string,
tests: { name: string; sleepTime?: number; snapshots?: boolean }[],
tests: { name: string; sleepTime?: number; snapshot?: boolean }[],
) {
const port = (globalThis as any).PORT;
let browser: Browser, context: BrowserContext, page: Page;
let browser: Browser, context: BrowserContext;

beforeAll(async () => {
// Setup
browser = await chromium.launch({
args: ['--headless', '--no-sandbox'],
});
context = await browser.newContext(devices['Desktop Chrome']);
page = await context.newPage();
await context.exposeFunction('screenshot', () => {});
});

afterAll(async () => {
Expand All @@ -26,15 +24,29 @@ export function generateCanvasTestCases(
});

tests
.filter((test) => test.snapshots !== false)
.filter((test) => test.snapshot !== false)
.map((test) => {
const { name, sleepTime = 200 } = test;
const key = `${namespace}_${name}`;

it(key, async () => {
const page = await context.newPage();

let resolveReady: () => void;
const readyPromise = new Promise<void>((resolve) => {
resolveReady = () => {
resolve();
};
});

await page.exposeFunction('screenshot', async () => {
resolveReady();
});

// Go to test page served by vite devServer.
const url = `http://localhost:${port}/?namespace=${namespace}&name=${name}&snapshot=true`;
await page.goto(url);
await readyPromise;
await sleep(sleepTime);

// Chart already rendered, capture into buffer.
Expand All @@ -45,7 +57,7 @@ export function generateCanvasTestCases(
try {
expect(buffer).toMatchCanvasSnapshot(dir, key, { maxError });
} finally {
//
page.close();
}
});
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export const hexagon: TestCase = async (options) => {
].reverse(),
);

scene.startAnimate();
// scene.startAnimate();
scene.addLayer(layer);
scene.render();
// scene.render();

return scene;
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 13 additions & 2 deletions examples/demos_next/index.ts → examples/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import * as RasterTestCases from './raster';
import * as TileTestCases from './tile';
import * as WebgpuTestCases from './webgpu';

export { BasemapTestCases, CanvasTestCases, PointTestCases };

export const TestCases = new Map<string, [string, TestCase][]>([
['bugfix', Object.entries(BugfixTestCases)],
['point', Object.entries(PointTestCases)],
Expand All @@ -32,3 +30,16 @@ export const TestCases = new Map<string, [string, TestCase][]>([
['webgpu', Object.entries(WebgpuTestCases)],
['extend', Object.entries(ExtendTestCases)],
]);

export function geSnapshotTestsFromNamespace(namespace: string) {
const testcases = TestCases.get(namespace);
if (!testcases) return [];
const demo = testcases
.filter(([, demo]) => Boolean(demo.snapshot))
.map(([name, demo]) => ({
name,
snapshot: Boolean(demo.snapshot),
sleepTime: typeof demo?.snapshot === 'object' ? demo.snapshot?.sleepTime : undefined,
}));
return demo;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 14 additions & 4 deletions examples/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Scene } from '@antv/l7-scene';
import { Cascader } from 'antd';
import { Cascader, ConfigProvider } from 'antd';
import 'antd/dist/reset.css';
import type { Controller } from 'lil-gui';
import GUI from 'lil-gui';
import React, { useEffect, useRef, useState } from 'react';
import { DEFAULT_GUI_OPTIONS, MAP_TYPES, SEARCH_PARAMS_KEYS } from './constants';
import { TestCases } from './demos_next';
import { TestCases } from './demos';
import type { GUIOptions } from './types';

const DEMO_LIST = Array.from(TestCases).map(([namespace, cases]) => {
Expand Down Expand Up @@ -66,6 +66,12 @@ export const Main = () => {
if (TestCase.extendGUI) {
extendGUI = TestCase.extendGUI?.(guiRef.current!);
}

// @ts-ignore
if (isSnapshotMode && window.screenshot) {
// @ts-ignore
await window.screenshot();
}
};

asyncFun();
Expand All @@ -74,6 +80,9 @@ export const Main = () => {
return () => {
scene?.destroy();
extendGUI.forEach((d) => d.destroy());
while (mapContainer.current?.firstChild) {
mapContainer.current.removeChild(mapContainer.current.lastChild!);
}
};
}, [viewDemo, guiOptions]);

Expand All @@ -84,14 +93,15 @@ export const Main = () => {
return (
<>
{!isSnapshotMode && (
<div style={{ position: 'absolute', left: '20px', zIndex: 10, top: '20px' }}>
<ConfigProvider theme={{ components: { Cascader: { dropdownHeight: 400 } } }}>
<Cascader
style={{ position: 'absolute', left: '20px', zIndex: 10, top: '20px' }}
size="large"
defaultValue={viewDemo}
options={DEMO_LIST}
onChange={onDemoViewChange}
/>
</div>
</ConfigProvider>
)}
<div ref={mapContainer} style={{ width: '100%', height: '100%' }} />
</>
Expand Down

0 comments on commit 2389d00

Please sign in to comment.