From ced717995b107402726f5215c8fb495abc368eb0 Mon Sep 17 00:00:00 2001 From: Andreas Stassivik Date: Thu, 24 Oct 2024 04:55:00 -0700 Subject: [PATCH 1/5] `expectImagesLoaded` extraction --- src/test-utilities/expect-images-loaded.ts | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test-utilities/expect-images-loaded.ts diff --git a/src/test-utilities/expect-images-loaded.ts b/src/test-utilities/expect-images-loaded.ts new file mode 100644 index 0000000..77dddc6 --- /dev/null +++ b/src/test-utilities/expect-images-loaded.ts @@ -0,0 +1,29 @@ +export function expectImagesLoaded(source: string): () => Promise { + return async (): Promise => { + 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) + } + } +} From dfcda154dc469543157846137791f4c0664017cc Mon Sep 17 00:00:00 2001 From: Andreas Stassivik Date: Thu, 24 Oct 2024 04:55:55 -0700 Subject: [PATCH 2/5] `expectImagesLoaded` integration --- .../custom-icons/custom-icons.test.ts | 35 ++----------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/src/tutorial/custom-icons/custom-icons.test.ts b/src/tutorial/custom-icons/custom-icons.test.ts index e157920..11a39c0 100644 --- a/src/tutorial/custom-icons/custom-icons.test.ts +++ b/src/tutorial/custom-icons/custom-icons.test.ts @@ -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', @@ -9,39 +11,6 @@ describe('custom icons tutorial', (): void => { describe('map', (): void => { describe('markers with custom icons', (): void => { - function expectImagesLoaded(source: string): () => Promise { - return async (): Promise => { - 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.', From 35fdaaa1ab61629c023bfb44a714b1de83caac06 Mon Sep 17 00:00:00 2001 From: Andreas Stassivik Date: Thu, 24 Oct 2024 05:02:26 -0700 Subject: [PATCH 3/5] prevent declaration file generation from `src/test-utilities` --- rollup.config.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rollup.config.ts b/rollup.config.ts index 6df98d7..d950106 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -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(), From 170ef0d524e7c8ecafba28048394fb2fbaa8df95 Mon Sep 17 00:00:00 2001 From: Andreas Stassivik Date: Thu, 24 Oct 2024 05:03:58 -0700 Subject: [PATCH 4/5] top-level `test-utilities` path/name mappings replace relative imports --- package.json | 3 +++ tsconfig.json | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7ed6fd6..8aef325 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,9 @@ "globalSetup": "jest-environment-puppeteer/setup", "globalTeardown": "jest-environment-puppeteer/teardown", "maxWorkers": 1, + "moduleNameMapper": { + "^test-utilities/(.*)\\.js$": "/src/test-utilities/$1.ts" + }, "preset": "ts-jest/presets/default-esm", "setupFilesAfterEnv": [ "expect-puppeteer" diff --git a/tsconfig.json b/tsconfig.json index 07acb9a..d5c9a23 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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" From a23f4b987017022fe53c67caab6a7b1a7097944b Mon Sep 17 00:00:00 2001 From: Andreas Stassivik Date: Thu, 24 Oct 2024 05:06:27 -0700 Subject: [PATCH 5/5] 0.0.65 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index cba3ec9..2bbdf95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@stassi/leaf", - "version": "0.0.64", + "version": "0.0.65", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@stassi/leaf", - "version": "0.0.64", + "version": "0.0.65", "cpu": [ "arm64", "x64" diff --git a/package.json b/package.json index 8aef325..ac3899f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stassi/leaf", - "version": "0.0.64", + "version": "0.0.65", "description": "Leaflet adapter.", "keywords": [ "cartography",