From ee6dd0b5569c01eb914d3d6c17f89e879ef48ff0 Mon Sep 17 00:00:00 2001 From: Igor Zinken Date: Thu, 23 Mar 2023 21:24:56 +0100 Subject: [PATCH] Migrated all unit tests to TypeScript --- src/rendering/cache/bitmap-cache.ts | 17 +++++++++++++---- src/services/render-service.ts | 10 ++-------- .../{file-types.spec.js => file-types.spec.ts} | 0 ...{image-types.spec.js => image-types.spec.ts} | 0 ...sh-factory.spec.js => brush-factory.spec.ts} | 0 ...factory.spec.js => document-factory.spec.ts} | 0 ...-factory.spec.js => effects-factory.spec.ts} | 0 ...-factory.spec.js => filters-factory.spec.ts} | 0 ...ry.spec.js => history-state-factory.spec.ts} | 0 ...er-factory.spec.js => layer-factory.spec.ts} | 0 ...e-factory.spec.js => sprite-factory.spec.ts} | 0 ...ext-factory.spec.js => text-factory.spec.ts} | 0 .../{image-math.spec.js => image-math.spec.ts} | 0 .../{point-math.spec.js => point-math.spec.ts} | 0 ...ngle-math.spec.js => rectangle-math.spec.ts} | 0 ...tion-math.spec.js => selection-math.spec.ts} | 0 .../{unit-math.spec.js => unit-math.spec.ts} | 0 ...itmap-cache.spec.js => bitmap-cache.spec.ts} | 0 ...vas-module.spec.js => canvas-module.spec.ts} | 0 ...t-module.spec.js => document-module.spec.ts} | 0 ...ry-module.spec.js => history-module.spec.ts} | 0 ...mage-module.spec.js => image-module.spec.ts} | 0 ...odule.spec.js => preferences-module.spec.ts} | 0 ...{tool-module.spec.js => tool-module.spec.ts} | 0 .../unit/store/{store.spec.js => store.spec.ts} | 0 ...ument-util.spec.js => document-util.spec.ts} | 0 tsconfig.app.json | 2 +- tsconfig.check.json | 2 +- 28 files changed, 17 insertions(+), 14 deletions(-) rename tests/unit/definitions/{file-types.spec.js => file-types.spec.ts} (100%) rename tests/unit/definitions/{image-types.spec.js => image-types.spec.ts} (100%) rename tests/unit/factories/{brush-factory.spec.js => brush-factory.spec.ts} (100%) rename tests/unit/factories/{document-factory.spec.js => document-factory.spec.ts} (100%) rename tests/unit/factories/{effects-factory.spec.js => effects-factory.spec.ts} (100%) rename tests/unit/factories/{filters-factory.spec.js => filters-factory.spec.ts} (100%) rename tests/unit/factories/{history-state-factory.spec.js => history-state-factory.spec.ts} (100%) rename tests/unit/factories/{layer-factory.spec.js => layer-factory.spec.ts} (100%) rename tests/unit/factories/{sprite-factory.spec.js => sprite-factory.spec.ts} (100%) rename tests/unit/factories/{text-factory.spec.js => text-factory.spec.ts} (100%) rename tests/unit/math/{image-math.spec.js => image-math.spec.ts} (100%) rename tests/unit/math/{point-math.spec.js => point-math.spec.ts} (100%) rename tests/unit/math/{rectangle-math.spec.js => rectangle-math.spec.ts} (100%) rename tests/unit/math/{selection-math.spec.js => selection-math.spec.ts} (100%) rename tests/unit/math/{unit-math.spec.js => unit-math.spec.ts} (100%) rename tests/unit/rendering/cache/{bitmap-cache.spec.js => bitmap-cache.spec.ts} (100%) rename tests/unit/store/modules/{canvas-module.spec.js => canvas-module.spec.ts} (100%) rename tests/unit/store/modules/{document-module.spec.js => document-module.spec.ts} (100%) rename tests/unit/store/modules/{history-module.spec.js => history-module.spec.ts} (100%) rename tests/unit/store/modules/{image-module.spec.js => image-module.spec.ts} (100%) rename tests/unit/store/modules/{preferences-module.spec.js => preferences-module.spec.ts} (100%) rename tests/unit/store/modules/{tool-module.spec.js => tool-module.spec.ts} (100%) rename tests/unit/store/{store.spec.js => store.spec.ts} (100%) rename tests/unit/utils/{document-util.spec.js => document-util.spec.ts} (100%) diff --git a/src/rendering/cache/bitmap-cache.ts b/src/rendering/cache/bitmap-cache.ts index 9c96d51..906c3c6 100644 --- a/src/rendering/cache/bitmap-cache.ts +++ b/src/rendering/cache/bitmap-cache.ts @@ -20,13 +20,20 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import type { Layer } from "@/definitions/document"; +import type { Layer, Filters, Text } from "@/definitions/document"; -const layerCache: Map = new Map(); +export type RenderCache = { + text?: Text; + textBitmap?: HTMLCanvasElement; + filters?: Filters; + filterData?: ImageData; +}; -export const getLayerCache = ( layer: Layer ): any => layerCache.get( layer.id ); +const layerCache: Map = new Map(); -export const setLayerCache = ( layer: Layer, props: any ): void => { +export const getLayerCache = ( layer: Layer ): RenderCache => layerCache.get( layer.id ); + +export const setLayerCache = ( layer: Layer, props: RenderCache ): void => { const cache = getLayerCache( layer ) ?? {}; layerCache.set( layer.id, { ...cache, ...props }); }; @@ -35,7 +42,9 @@ export const hasLayerCache = ( layer: Layer ): boolean => layerCache.has( layer. export const clearCacheProperty = ( layer: Layer, propertyName: string ): void => { const cache = getLayerCache( layer ); + // @ts-expect-error using string as key if ( cache?.[ propertyName ] ) { + // @ts-expect-error using string as key delete cache[ propertyName ]; } }; diff --git a/src/services/render-service.ts b/src/services/render-service.ts index 53ef84c..0776d62 100644 --- a/src/services/render-service.ts +++ b/src/services/render-service.ts @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import Vue from "vue"; -import type { Layer, Filters, Text } from "@/definitions/document"; +import type { Layer } from "@/definitions/document"; import { LayerTypes } from "@/definitions/layer-types"; import { getSpriteForLayer } from "@/factories/sprite-factory"; import { hasFilters, isEqual as isFiltersEqual } from "@/factories/filters-factory"; @@ -29,6 +29,7 @@ import { isEqual as isTextEqual } from "@/factories/text-factory"; import { createCanvas, cloneCanvas, matchDimensions } from "@/utils/canvas-util"; import { replaceLayerSource } from "@/utils/layer-util"; import { getLayerCache, setLayerCache } from "@/rendering/cache/bitmap-cache"; +import type { RenderCache } from "@/rendering/cache/bitmap-cache"; import { renderMultiLineText } from "@/rendering/text"; import { loadGoogleFont } from "@/services/font-service"; import FilterWorker from "@/workers/filter.worker?worker"; @@ -40,13 +41,6 @@ type RenderJob = { error: ( error?: any ) => void; }; -type RenderCache = { - text?: Text; - textBitmap?: HTMLCanvasElement; - filters?: Filters; - filterData?: ImageData; -}; - const jobQueue: RenderJob[] = []; let UID = 0; diff --git a/tests/unit/definitions/file-types.spec.js b/tests/unit/definitions/file-types.spec.ts similarity index 100% rename from tests/unit/definitions/file-types.spec.js rename to tests/unit/definitions/file-types.spec.ts diff --git a/tests/unit/definitions/image-types.spec.js b/tests/unit/definitions/image-types.spec.ts similarity index 100% rename from tests/unit/definitions/image-types.spec.js rename to tests/unit/definitions/image-types.spec.ts diff --git a/tests/unit/factories/brush-factory.spec.js b/tests/unit/factories/brush-factory.spec.ts similarity index 100% rename from tests/unit/factories/brush-factory.spec.js rename to tests/unit/factories/brush-factory.spec.ts diff --git a/tests/unit/factories/document-factory.spec.js b/tests/unit/factories/document-factory.spec.ts similarity index 100% rename from tests/unit/factories/document-factory.spec.js rename to tests/unit/factories/document-factory.spec.ts diff --git a/tests/unit/factories/effects-factory.spec.js b/tests/unit/factories/effects-factory.spec.ts similarity index 100% rename from tests/unit/factories/effects-factory.spec.js rename to tests/unit/factories/effects-factory.spec.ts diff --git a/tests/unit/factories/filters-factory.spec.js b/tests/unit/factories/filters-factory.spec.ts similarity index 100% rename from tests/unit/factories/filters-factory.spec.js rename to tests/unit/factories/filters-factory.spec.ts diff --git a/tests/unit/factories/history-state-factory.spec.js b/tests/unit/factories/history-state-factory.spec.ts similarity index 100% rename from tests/unit/factories/history-state-factory.spec.js rename to tests/unit/factories/history-state-factory.spec.ts diff --git a/tests/unit/factories/layer-factory.spec.js b/tests/unit/factories/layer-factory.spec.ts similarity index 100% rename from tests/unit/factories/layer-factory.spec.js rename to tests/unit/factories/layer-factory.spec.ts diff --git a/tests/unit/factories/sprite-factory.spec.js b/tests/unit/factories/sprite-factory.spec.ts similarity index 100% rename from tests/unit/factories/sprite-factory.spec.js rename to tests/unit/factories/sprite-factory.spec.ts diff --git a/tests/unit/factories/text-factory.spec.js b/tests/unit/factories/text-factory.spec.ts similarity index 100% rename from tests/unit/factories/text-factory.spec.js rename to tests/unit/factories/text-factory.spec.ts diff --git a/tests/unit/math/image-math.spec.js b/tests/unit/math/image-math.spec.ts similarity index 100% rename from tests/unit/math/image-math.spec.js rename to tests/unit/math/image-math.spec.ts diff --git a/tests/unit/math/point-math.spec.js b/tests/unit/math/point-math.spec.ts similarity index 100% rename from tests/unit/math/point-math.spec.js rename to tests/unit/math/point-math.spec.ts diff --git a/tests/unit/math/rectangle-math.spec.js b/tests/unit/math/rectangle-math.spec.ts similarity index 100% rename from tests/unit/math/rectangle-math.spec.js rename to tests/unit/math/rectangle-math.spec.ts diff --git a/tests/unit/math/selection-math.spec.js b/tests/unit/math/selection-math.spec.ts similarity index 100% rename from tests/unit/math/selection-math.spec.js rename to tests/unit/math/selection-math.spec.ts diff --git a/tests/unit/math/unit-math.spec.js b/tests/unit/math/unit-math.spec.ts similarity index 100% rename from tests/unit/math/unit-math.spec.js rename to tests/unit/math/unit-math.spec.ts diff --git a/tests/unit/rendering/cache/bitmap-cache.spec.js b/tests/unit/rendering/cache/bitmap-cache.spec.ts similarity index 100% rename from tests/unit/rendering/cache/bitmap-cache.spec.js rename to tests/unit/rendering/cache/bitmap-cache.spec.ts diff --git a/tests/unit/store/modules/canvas-module.spec.js b/tests/unit/store/modules/canvas-module.spec.ts similarity index 100% rename from tests/unit/store/modules/canvas-module.spec.js rename to tests/unit/store/modules/canvas-module.spec.ts diff --git a/tests/unit/store/modules/document-module.spec.js b/tests/unit/store/modules/document-module.spec.ts similarity index 100% rename from tests/unit/store/modules/document-module.spec.js rename to tests/unit/store/modules/document-module.spec.ts diff --git a/tests/unit/store/modules/history-module.spec.js b/tests/unit/store/modules/history-module.spec.ts similarity index 100% rename from tests/unit/store/modules/history-module.spec.js rename to tests/unit/store/modules/history-module.spec.ts diff --git a/tests/unit/store/modules/image-module.spec.js b/tests/unit/store/modules/image-module.spec.ts similarity index 100% rename from tests/unit/store/modules/image-module.spec.js rename to tests/unit/store/modules/image-module.spec.ts diff --git a/tests/unit/store/modules/preferences-module.spec.js b/tests/unit/store/modules/preferences-module.spec.ts similarity index 100% rename from tests/unit/store/modules/preferences-module.spec.js rename to tests/unit/store/modules/preferences-module.spec.ts diff --git a/tests/unit/store/modules/tool-module.spec.js b/tests/unit/store/modules/tool-module.spec.ts similarity index 100% rename from tests/unit/store/modules/tool-module.spec.js rename to tests/unit/store/modules/tool-module.spec.ts diff --git a/tests/unit/store/store.spec.js b/tests/unit/store/store.spec.ts similarity index 100% rename from tests/unit/store/store.spec.js rename to tests/unit/store/store.spec.ts diff --git a/tests/unit/utils/document-util.spec.js b/tests/unit/utils/document-util.spec.ts similarity index 100% rename from tests/unit/utils/document-util.spec.js rename to tests/unit/utils/document-util.spec.ts diff --git a/tsconfig.app.json b/tsconfig.app.json index 5fe0f43..63f1901 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -11,7 +11,7 @@ "noImplicitAny": true, "removeComments": true, "paths": { - "@/*": [ "./src/*" ] + "@/*": [ "./src/*", "./tests/*" ] } }, "exclude": [ diff --git a/tsconfig.check.json b/tsconfig.check.json index e129b63..c49b1d7 100644 --- a/tsconfig.check.json +++ b/tsconfig.check.json @@ -1,6 +1,6 @@ { "extends": "./tsconfig.app.json", - "includes": [ "src/**/*.ts" ], + "includes": [ "src/**/*.ts", "tests/**/*.ts" ], "compilerOptions": { "skipLibCheck": true }