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

feature/test-utility-extraction #65

Merged
merged 5 commits into from
Oct 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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stassi/leaf",
"version": "0.0.64",
"version": "0.0.65",
"description": "Leaflet adapter.",
"keywords": [
"cartography",
Expand Down Expand Up @@ -46,6 +46,9 @@
"globalSetup": "jest-environment-puppeteer/setup",
"globalTeardown": "jest-environment-puppeteer/teardown",
"maxWorkers": 1,
"moduleNameMapper": {
"^test-utilities/(.*)\\.js$": "<rootDir>/src/test-utilities/$1.ts"
},
"preset": "ts-jest/presets/default-esm",
"setupFilesAfterEnv": [
"expect-puppeteer"
Expand Down
6 changes: 5 additions & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ const aliasOptions: RollupAliasOptions = {
inject(injectOptions),
typescript({
declaration: true,
exclude: ['rollup.config.ts', 'src/tutorial/**/*.ts'],
exclude: [
'rollup.config.ts',
'src/test-utilities/**/*.ts',
'src/tutorial/**/*.ts',
],
outDir: './dist',
}),
terser(),
Expand Down
29 changes: 29 additions & 0 deletions src/test-utilities/expect-images-loaded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export function expectImagesLoaded(source: string): () => Promise<void> {
return async (): Promise<void> => {
await page.waitForFunction(
(src: string): boolean => {
return Array.from(document.querySelectorAll(`img[src="${src}"]`)).every(
(img: Element): boolean =>
img instanceof HTMLImageElement
? img.complete && img.naturalHeight > 0 && img.naturalWidth > 0
: false,
)
},
undefined,
source,
)

for (const img of await page.$$(`img[src="${source}"]`)) {
expect(
await img.evaluate(
({
complete,
naturalHeight,
naturalWidth,
}: HTMLImageElement): boolean =>
complete && naturalHeight > 0 && naturalWidth > 0,
),
).toBe(true)
}
}
}
35 changes: 2 additions & 33 deletions src/tutorial/custom-icons/custom-icons.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expectImagesLoaded } from 'test-utilities/expect-images-loaded.js'

describe('custom icons tutorial', (): void => {
describe.each([1, 2])(
'device scale factor: %d',
Expand All @@ -9,39 +11,6 @@ describe('custom icons tutorial', (): void => {

describe('map', (): void => {
describe('markers with custom icons', (): void => {
function expectImagesLoaded(source: string): () => Promise<void> {
return async (): Promise<void> => {
await page.waitForFunction(
(src: string): boolean => {
return Array.from(
document.querySelectorAll(`img[src="${src}"]`),
).every((img: Element): boolean =>
img instanceof HTMLImageElement
? img.complete &&
img.naturalHeight > 0 &&
img.naturalWidth > 0
: false,
)
},
undefined,
source,
)

for (const img of await page.$$(`img[src="${source}"]`)) {
expect(
await img.evaluate(
({
complete,
naturalHeight,
naturalWidth,
}: HTMLImageElement): boolean =>
complete && naturalHeight > 0 && naturalWidth > 0,
),
).toBe(true)
}
}
}

describe.each([
{
popupText: 'I am a green leaf.',
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"module": "ESNext",
"moduleResolution": "node",
"paths": {
"@stassi/leaf": ["src/index.ts"]
"@stassi/leaf": ["src/index.ts"],
"test-utilities/*": ["src/test-utilities/*"]
},
"strict": true,
"target": "ESNext"
Expand Down