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

feat(cli): Move the default test tile into cli package #2367

Merged
merged 4 commits into from
Jul 25, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/screenshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: (Screenshot) Screenshot Pull Request Changes
run: |
./packages/cli/bin/bmc.js screenshot --tiles packages/cli/test-tiles/default.test.tiles.json --output .artifacts/visual-snapshots
./packages/cli/bin/bmc.js screenshot --output .artifacts/visual-snapshots

- name: Save snapshots
uses: getsentry/action-visual-snapshot@v2
Expand Down
34 changes: 7 additions & 27 deletions packages/cli/src/cli/screenshot/action.screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,11 @@ import { FastifyInstance } from 'fastify/types/instance';
import { mkdir } from 'fs/promises';
import getPort from 'get-port';
import { Browser, chromium } from 'playwright';
import { z } from 'zod';
import { DefaultTestTiles, TileTestSchema } from './test.tiles.js';

export const DefaultTestTiles = './test-tiles/default.test.tiles.json';
export const DefaultHost = 'basemaps.linz.govt.nz';
export const DefaultOutput = '.artifacts/visual-snapshots/';

enum TileMatrixIdentifier {
Nztm2000Quad = 'NZTM2000Quad',
Google = 'WebMercatorQuad',
}

const zLocation = z.object({
lat: z.number().gte(-90).lte(90),
lng: z.number().gte(-180).lte(180),
z: z.number().gte(0).lte(32),
});

const zTileTest = z.object({
name: z.string(),
tileMatrix: z.nativeEnum(TileMatrixIdentifier),
location: zLocation,
tileSet: z.string(),
style: z.string().optional(),
});

export type TileTestSchema = z.infer<typeof zTileTest>;

export class CommandScreenShot extends CommandLineAction {
private config: CommandLineStringParameter;
private host: CommandLineStringParameter;
Expand Down Expand Up @@ -65,7 +43,6 @@ export class CommandScreenShot extends CommandLineAction {
argumentName: 'TILES',
parameterLongName: '--tiles',
description: 'JSON file path for the test tiles',
defaultValue: DefaultTestTiles,
});

this.assets = this.defineStringParameter({
Expand Down Expand Up @@ -113,11 +90,14 @@ export class CommandScreenShot extends CommandLineAction {
}

async takeScreenshots(host: string, chrome: Browser, logger: LogType): Promise<void> {
const tiles = this.tiles.value ?? DefaultTestTiles;
const tiles = this.tiles.value;
const outputPath = this.output.value ?? DefaultOutput;

const TestTiles = await fsa.readJson<TileTestSchema[]>(tiles);
for (const test of TestTiles) {
let testTiles = DefaultTestTiles;
if (tiles) {
testTiles = await fsa.readJson<TileTestSchema[]>(tiles);
}
for (const test of testTiles) {
const page = await chrome.newPage();

const searchParam = new URLSearchParams();
Expand Down
65 changes: 65 additions & 0 deletions packages/cli/src/cli/screenshot/test.tiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { z } from 'zod';

enum TileMatrixIdentifier {
Nztm2000Quad = 'NZTM2000Quad',
Google = 'WebMercatorQuad',
}

const zLocation = z.object({
lat: z.number().gte(-90).lte(90),
lng: z.number().gte(-180).lte(180),
z: z.number().gte(0).lte(32),
});

const zTileTest = z.object({
name: z.string(),
tileMatrix: z.nativeEnum(TileMatrixIdentifier),
location: zLocation,
tileSet: z.string(),
style: z.string().optional(),
});

export type TileTestSchema = z.infer<typeof zTileTest>;

export const DefaultTestTiles: TileTestSchema[] = [
{
name: 'health-3857-z5',
tileMatrix: TileMatrixIdentifier.Google,
location: { lat: -41.8899962, lng: 174.0492437, z: 5 },
tileSet: 'health',
},
{
name: 'health-2193-z5',
tileMatrix: TileMatrixIdentifier.Nztm2000Quad,
location: { lat: -41.8899962, lng: 174.0492437, z: 1 },
tileSet: 'aerial',
},
{
name: 'topographic-3857-z5',
tileMatrix: TileMatrixIdentifier.Google,
location: { lat: -41.8899962, lng: 174.0492437, z: 5 },
tileSet: 'topographic',
style: 'topographic',
},
{
name: 'topolite-3857-z5',
tileMatrix: TileMatrixIdentifier.Google,
location: { lat: -41.8899962, lng: 174.0492437, z: 5 },
tileSet: 'topographic',
style: 'topolite',
},
{
name: 'topographic-3857-z14',
tileMatrix: TileMatrixIdentifier.Google,
location: { lat: -41.8899962, lng: 174.0492437, z: 14 },
tileSet: 'topographic',
style: 'topographic',
},
{
name: 'topolite-3857-z17',
tileMatrix: TileMatrixIdentifier.Google,
location: { lat: -43.8063936, lng: 172.9679876, z: 17 },
tileSet: 'topographic',
style: 'topolite',
},
];
42 changes: 0 additions & 42 deletions packages/cli/test-tiles/default.test.tiles.json

This file was deleted.