Skip to content

Commit

Permalink
Merge pull request #65 from Stassi/feature/test-utility-extraction
Browse files Browse the repository at this point in the history
feature/test-utility-extraction
  • Loading branch information
Stassi authored Oct 24, 2024
2 parents da8220e + a23f4b9 commit bb21603
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 38 deletions.
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

0 comments on commit bb21603

Please sign in to comment.