From 0c3e1cd89e6aba2408ae628979d7c0db3153946f Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Tue, 25 Jul 2023 14:43:50 +0700 Subject: [PATCH 1/6] chore(web): cleans up test-resource import path --- common/web/gesture-recognizer/package.json | 3 +++ .../src/test/auto/headless/gesturePath.js | 2 +- .../src/test/auto/headless/pathStats.ts | 2 +- .../src/test/auto/headless/recordedSegmentations.js | 2 +- .../gesture-recognizer/src/test/auto/tsconfig.json | 12 ++++++++++++ 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 common/web/gesture-recognizer/src/test/auto/tsconfig.json diff --git a/common/web/gesture-recognizer/package.json b/common/web/gesture-recognizer/package.json index 48e4d34606..40fa25468a 100644 --- a/common/web/gesture-recognizer/package.json +++ b/common/web/gesture-recognizer/package.json @@ -26,6 +26,9 @@ "ts-node": "^10.9.1", "typescript": "^4.9.5" }, + "imports": { + "#tools": "./build/tools/obj/index.js" + }, "scripts": { "build": "gosh ./build.sh", "test": "gosh ./test.sh" diff --git a/common/web/gesture-recognizer/src/test/auto/headless/gesturePath.js b/common/web/gesture-recognizer/src/test/auto/headless/gesturePath.js index 3c1690eb28..67590e4c73 100644 --- a/common/web/gesture-recognizer/src/test/auto/headless/gesturePath.js +++ b/common/web/gesture-recognizer/src/test/auto/headless/gesturePath.js @@ -6,7 +6,7 @@ import fs from 'fs'; import { GesturePath } from '@keymanapp/gesture-recognizer'; import { timedPromise } from '@keymanapp/web-utils'; -import { TouchpathTurtle } from '../../../../build/tools/obj/index.js'; +import { TouchpathTurtle } from '#tools'; // Ensures that the resources are resolved relative to this script, not to the cwd when the test // runner was launched. diff --git a/common/web/gesture-recognizer/src/test/auto/headless/pathStats.ts b/common/web/gesture-recognizer/src/test/auto/headless/pathStats.ts index f9535ecd96..ffea495a97 100644 --- a/common/web/gesture-recognizer/src/test/auto/headless/pathStats.ts +++ b/common/web/gesture-recognizer/src/test/auto/headless/pathStats.ts @@ -1,7 +1,7 @@ import { assert } from 'chai'; import { CumulativePathStats, InputSample } from '@keymanapp/gesture-recognizer'; -import { TouchpathTurtle } from '../../../../build/tools/obj/index.js'; +import { TouchpathTurtle } from '#tools'; describe("CumulativePathStats", function() { it("Sample count = 0", function() { diff --git a/common/web/gesture-recognizer/src/test/auto/headless/recordedSegmentations.js b/common/web/gesture-recognizer/src/test/auto/headless/recordedSegmentations.js index cb87813879..b457167113 100644 --- a/common/web/gesture-recognizer/src/test/auto/headless/recordedSegmentations.js +++ b/common/web/gesture-recognizer/src/test/auto/headless/recordedSegmentations.js @@ -10,7 +10,7 @@ const PromiseStatuses = PromiseStatusModule.PromiseStatuses; import { PathSegmenter } from '@keymanapp/gesture-recognizer'; -import { HeadlessInputEngine } from '../../../../build/tools/obj/index.js'; +import { HeadlessInputEngine } from '#tools'; // Ensures that the resources are resolved relative to this script, not to the cwd when the test // runner was launched. diff --git a/common/web/gesture-recognizer/src/test/auto/tsconfig.json b/common/web/gesture-recognizer/src/test/auto/tsconfig.json new file mode 100644 index 0000000000..9bbd199269 --- /dev/null +++ b/common/web/gesture-recognizer/src/test/auto/tsconfig.json @@ -0,0 +1,12 @@ +/* + * VS Code Intellisense needs this helper in order to properly use subpath imports in the + * test specs found under the `headless` subfolder. Otherwise, it'll report errors while + * editing - even if the tests themselves actually work. + */ +{ + // Enabling the following line re-breaks it for some reason? + // "extends": "../../../tsconfig.json", + "compilerOptions": { + "moduleResolution": "Node16", + } +} From de9b5a386c9db0ff5cfc7886534956abb79361ec Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Tue, 25 Jul 2023 14:44:25 +0700 Subject: [PATCH 2/6] change(web): turtle.wait uses similar pattern to turtle.move again --- .../unit-test-resources/src/touchpathTurtle.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts b/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts index 065245c9c3..891a506ede 100644 --- a/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts +++ b/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts @@ -76,6 +76,7 @@ export class TouchpathTurtle extends EventEmitter) { @@ -102,23 +103,20 @@ export class TouchpathTurtle extends EventEmitter Date: Tue, 25 Jul 2023 14:44:39 +0700 Subject: [PATCH 3/6] change(web): generic typing for path-stats --- .../src/engine/headless/cumulativePathStats.ts | 12 ++++++------ .../src/engine/headless/gesturePath.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/common/web/gesture-recognizer/src/engine/headless/cumulativePathStats.ts b/common/web/gesture-recognizer/src/engine/headless/cumulativePathStats.ts index c2021fb16d..a22957c2a3 100644 --- a/common/web/gesture-recognizer/src/engine/headless/cumulativePathStats.ts +++ b/common/web/gesture-recognizer/src/engine/headless/cumulativePathStats.ts @@ -45,7 +45,7 @@ export function sigMinus(operand1: number, operand2: number) { * * Instances of this class are immutable. */ -export class CumulativePathStats { +export class CumulativePathStats { /** * Provides linear-regression statistics & fitting values based on the underlying `CumulativePathStats` * object used to generate it. All operations are O(1). @@ -204,8 +204,8 @@ export class CumulativePathStats { constructor(); constructor(sample: InputSample); - constructor(instance: CumulativePathStats); - constructor(obj?: InputSample | CumulativePathStats) { + constructor(instance: CumulativePathStats); + constructor(obj?: InputSample | CumulativePathStats) { if(!obj) { return; } @@ -232,7 +232,7 @@ export class CumulativePathStats { * @returns A new, separate instance for the cumulative properties up to the * newly-sampled point. */ - public extend(sample: InputSample): CumulativePathStats { + public extend(sample: InputSample): CumulativePathStats { if(!this._initialSample) { this._initialSample = sample; this.baseSample = sample; @@ -301,7 +301,7 @@ export class CumulativePathStats { * from this instance's current accumulation. * @returns */ - public deaccumulate(subsetStats?: CumulativePathStats): CumulativePathStats { + public deaccumulate(subsetStats?: CumulativePathStats): CumulativePathStats { // Possible addition: use `this.buildRenormalized` on the returned version // if catastrophic cancellation effects (random, small floating point errors) // are not sufficiently mitigated & handled by the measures currently in place. @@ -509,7 +509,7 @@ export class CumulativePathStats { * errors than the old instance whenever they do occur. * @returns */ - public buildRenormalized(): CumulativePathStats { + public buildRenormalized(): CumulativePathStats { // Other (internal) notes: the internal mapping of the new instance will not // match that of the old instance. This should not affect the practical // results of any mapping to and from the external coordinate space, however. diff --git a/common/web/gesture-recognizer/src/engine/headless/gesturePath.ts b/common/web/gesture-recognizer/src/engine/headless/gesturePath.ts index 71525bb30a..62220a6a95 100644 --- a/common/web/gesture-recognizer/src/engine/headless/gesturePath.ts +++ b/common/web/gesture-recognizer/src/engine/headless/gesturePath.ts @@ -48,7 +48,7 @@ export class GesturePath extends EventEmitter> { private _isComplete: boolean = false; private _wasCancelled?: boolean; - private _stats: CumulativePathStats; + private _stats: CumulativePathStats; public get stats() { // Is (practically) immutable, so it's safe to expose the instance directly. @@ -75,7 +75,7 @@ export class GesturePath extends EventEmitter> { instance._isComplete = true; instance._wasCancelled = jsonObj.wasCancelled; - let stats = instance.samples.reduce((stats: CumulativePathStats, sample) => stats.extend(sample), new CumulativePathStats()); + let stats = instance.samples.reduce((stats: CumulativePathStats, sample) => stats.extend(sample), new CumulativePathStats()); instance._stats = stats; return instance; From 71201ddaa790a8eb16ab8c207439e2dd1564815a Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Wed, 26 Jul 2023 08:25:27 +0700 Subject: [PATCH 4/6] fix(web): better gesture test-tsconfig --- common/web/gesture-recognizer/src/test/auto/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/web/gesture-recognizer/src/test/auto/tsconfig.json b/common/web/gesture-recognizer/src/test/auto/tsconfig.json index 9bbd199269..399b5d3ace 100644 --- a/common/web/gesture-recognizer/src/test/auto/tsconfig.json +++ b/common/web/gesture-recognizer/src/test/auto/tsconfig.json @@ -5,7 +5,7 @@ */ { // Enabling the following line re-breaks it for some reason? - // "extends": "../../../tsconfig.json", + "extends": "../../../../tsconfig.kmw-main-base.json", "compilerOptions": { "moduleResolution": "Node16", } From 9e028cad1fe2169a92ccaf2fac78193ba028f18c Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Wed, 26 Jul 2023 08:26:49 +0700 Subject: [PATCH 5/6] chore(web): Apply suggestions from code review Co-authored-by: Marc Durdin --- .../src/tools/unit-test-resources/src/touchpathTurtle.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts b/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts index 891a506ede..9f97970ca4 100644 --- a/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts +++ b/common/web/gesture-recognizer/src/tools/unit-test-resources/src/touchpathTurtle.ts @@ -105,7 +105,7 @@ export class TouchpathTurtle extends EventEmitter 0!"); } const startSample = this.location; From 089cdbf6617b28b91a8b743c7db35e0fea0055a0 Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Fri, 28 Jul 2023 08:08:44 +0700 Subject: [PATCH 6/6] chore(web): Apply suggestions from code review --- common/web/gesture-recognizer/src/test/auto/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/common/web/gesture-recognizer/src/test/auto/tsconfig.json b/common/web/gesture-recognizer/src/test/auto/tsconfig.json index 399b5d3ace..ae2302aa52 100644 --- a/common/web/gesture-recognizer/src/test/auto/tsconfig.json +++ b/common/web/gesture-recognizer/src/test/auto/tsconfig.json @@ -4,7 +4,6 @@ * editing - even if the tests themselves actually work. */ { - // Enabling the following line re-breaks it for some reason? "extends": "../../../../tsconfig.kmw-main-base.json", "compilerOptions": { "moduleResolution": "Node16",