Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: 应用调试工程 #2494

Merged
merged 19 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions __tests__/integration/gallery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const TEST_CASES = [
{
name: 'variFlight',
sleepTime: 1000,
snapshots: false,
},
];

describe('Gallery Snapshot', () => {
generateCanvasTestCases('Gallery', TEST_CASES);
generateCanvasTestCases('gallery', TEST_CASES);
});
4 changes: 1 addition & 3 deletions __tests__/integration/heatmap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ const TEST_CASES = [
},
{
name: 'grid',
snapshots: false,
},
{
name: 'hexagon',
snapshots: false,
},
];

describe('Heatmap Snapshot', () => {
generateCanvasTestCases('Heatmap', TEST_CASES);
generateCanvasTestCases('heatmap', TEST_CASES);
});
4 changes: 1 addition & 3 deletions __tests__/integration/line.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const TEST_CASES = [
},
{
name: 'dash',
snapshots: false,
sleepTime: 500,
},
{
Expand All @@ -25,7 +24,6 @@ const TEST_CASES = [
},
{
name: 'greatcircle',
snapshots: false,
sleepTime: 500,
},
{
Expand All @@ -35,5 +33,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);
});
9 changes: 4 additions & 5 deletions __tests__/integration/point.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@ const TEST_CASES = [
},
{
name: 'dot',
snapshots: false,
snapshot: false,
},
{
name: 'fill',
},
{
name: 'fill_image',
sleepTime: 1000,
name: 'fillImage',
},
{
name: 'image',
snapshots: false,
snapshot: false,
},
{
name: 'text',
},
];

describe('Point Snapshot', () => {
generateCanvasTestCases('Point', TEST_CASES);
generateCanvasTestCases('point', TEST_CASES);
});
8 changes: 4 additions & 4 deletions __tests__/integration/polygon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ const TEST_CASES = [
},
{
name: 'ocean',
snapshots: false,
snapshot: false,
},
{
name: 'texture',
snapshots: false,
snapshot: false,
},
{
name: 'water',
snapshots: false,
snapshot: false,
},
];

describe('Polygon Snapshot', () => {
generateCanvasTestCases('Polygon', TEST_CASES);
generateCanvasTestCases('polygon', TEST_CASES);
});
Binary file removed __tests__/integration/snapshots/Gallery_fujian.png
Binary file not shown.
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Heatmap_normal.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Line_arc.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Line_arc3D.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Line_arc_plane.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Line_dash.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Line_flow.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Line_normal.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Line_simple.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Line_wall.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Mask_multi.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Mask_single.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Point_billboard.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Point_column.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Point_fill.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Point_fill_image.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Point_text.png
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Polygon_extrude.png
Binary file not shown.
Binary file not shown.
Binary file removed __tests__/integration/snapshots/Polygon_fill.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/integration/snapshots/heatmap_grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/integration/snapshots/line_arc.png
Binary file added __tests__/integration/snapshots/line_arc3D.png
Binary file added __tests__/integration/snapshots/line_dash.png
Binary file added __tests__/integration/snapshots/line_flow.png
Binary file added __tests__/integration/snapshots/line_normal.png
Binary file added __tests__/integration/snapshots/line_simple.png
Binary file added __tests__/integration/snapshots/line_wall.png
Binary file added __tests__/integration/snapshots/mask_multi.png
Binary file added __tests__/integration/snapshots/mask_single.png
Binary file added __tests__/integration/snapshots/point_column.png
Binary file added __tests__/integration/snapshots/point_fill.png
Binary file added __tests__/integration/snapshots/point_text.png
Binary file added __tests__/integration/snapshots/polygon_fill.png
28 changes: 20 additions & 8 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}/?type=${namespace}&name=${name}`;
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
21 changes: 13 additions & 8 deletions examples/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import type { RenderDemoMap, RenderDemoOptions } from './types';
import type { GUIOptions, TestCaseBasemap } from './types';

export const MAP_TYPES: RenderDemoMap[] = [
export const DEFAULT_GUI_OPTIONS: GUIOptions = {
map: 'Map',
renderer: 'device',
animate: false,
enableWebGPU: false,
};

export const SEARCH_PARAMS_KEYS = ['namespace', 'name', 'snapshot'].concat(
Object.keys(DEFAULT_GUI_OPTIONS),
);

export const MAP_TYPES: TestCaseBasemap[] = [
'Map',
'GaodeMap',
'Mapbox',
Expand All @@ -10,9 +21,3 @@ export const MAP_TYPES: RenderDemoMap[] = [
'TMap',
'GoogleMap',
] as const;

export const DEFAULT_RENDER_OPTIONS: RenderDemoOptions = {
map: 'Map',
renderer: 'device',
animate: false,
};
26 changes: 12 additions & 14 deletions examples/demos/basemap/amap-data.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { LineLayer, Scene, Source } from '@antv/l7';
import * as allMap from '@antv/l7-maps';
import type { RenderDemoOptions } from '../../types';
import { LineLayer, Source } from '@antv/l7';
import type { TestCase } from '../../types';
import { CaseScene } from '../../utils';

export function MapRender(options: RenderDemoOptions) {
const scene = new Scene({
id: 'map',
renderer: options.renderer,
map: new allMap[options.map]({
style: 'normal',
export const amapData: TestCase = async (options) => {
const scene = await CaseScene({
...options,
mapConfig: {
center: [121.434765, 31.256735],
zoom: 14.83,
maxZoom: 25,
}),
},
});

const geoData = {
type: 'FeatureCollection',
features: [
Expand Down Expand Up @@ -40,8 +39,7 @@ export function MapRender(options: RenderDemoOptions) {
.style({
opacity: 1,
});
scene.addLayer(layer);

scene.on('loaded', () => {
scene.addLayer(layer);
});
}
return scene;
};
4 changes: 2 additions & 2 deletions examples/demos/basemap/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { MapRender as amapData } from './amap-data';
export { MapRender as wgs84Data } from './wgs84-data';
export { amapData } from './amap-data';
export { wgs84Data } from './wgs84-data';
29 changes: 13 additions & 16 deletions examples/demos/basemap/wgs84-data.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { LineLayer, Scene, Source } from '@antv/l7';
import * as allMap from '@antv/l7-maps';
import { LineLayer, Source } from '@antv/l7';
import type { Map } from 'maplibre-gl';
import type { RenderDemoOptions } from '../../types';
import type { TestCase } from '../../types';
import { CaseScene } from '../../utils';

export function MapRender(options: RenderDemoOptions) {
const scene = new Scene({
id: 'map',
renderer: options.renderer,
map: new allMap[options.map]({
style: ['MapLibre', 'Mapbox'].includes(options.map)
? 'https://basemaps.cartocdn.com/gl/positron-nolabels-gl-style/style.json'
: 'normal',
export const wgs84Data: TestCase = async (options) => {
const scene = await CaseScene({
...options,
mapConfig: {
center: [121.434765, 31.256735],
zoom: 14.83,
maxZoom: 23.9,
}),
},
});

const geoData = {
type: 'FeatureCollection',
features: [
Expand Down Expand Up @@ -44,9 +41,7 @@ export function MapRender(options: RenderDemoOptions) {
opacity: 1,
});

scene.on('loaded', () => {
scene.addLayer(layer);
});
scene.addLayer(layer);

if (scene.getType() === 'mapbox') {
const baseMap = scene.map as Map;
Expand All @@ -70,4 +65,6 @@ export function MapRender(options: RenderDemoOptions) {
});
});
}
}

return scene;
};
49 changes: 0 additions & 49 deletions examples/demos/bugfix/color.ts

This file was deleted.

Loading
Loading