@augment-vir/test 30.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/LICENSE-CC0 +121 -0
  2. package/LICENSE-MIT +21 -0
  3. package/dist/augments/test-web.d.ts +13 -0
  4. package/dist/augments/test-web.js +21 -0
  5. package/dist/augments/universal-testing-suite/it-cases.d.ts +21 -0
  6. package/dist/augments/universal-testing-suite/it-cases.js +54 -0
  7. package/dist/augments/universal-testing-suite/universal-describe.d.ts +20 -0
  8. package/dist/augments/universal-testing-suite/universal-describe.js +9 -0
  9. package/dist/augments/universal-testing-suite/universal-it.d.ts +27 -0
  10. package/dist/augments/universal-testing-suite/universal-it.js +9 -0
  11. package/dist/augments/universal-testing-suite/universal-test-context.d.ts +14 -0
  12. package/dist/augments/universal-testing-suite/universal-test-context.js +24 -0
  13. package/dist/index.d.ts +5 -0
  14. package/dist/index.js +5 -0
  15. package/dist/test-web/click-element.d.ts +2 -0
  16. package/dist/test-web/click-element.js +18 -0
  17. package/dist/test-web/element-test-focus.d.ts +1 -0
  18. package/dist/test-web/element-test-focus.js +17 -0
  19. package/dist/test-web/open-wc-exports.d.ts +1 -0
  20. package/dist/test-web/open-wc-exports.js +1 -0
  21. package/dist/test-web/symlinked/animation-frame.d.ts +1 -0
  22. package/dist/test-web/symlinked/animation-frame.js +17 -0
  23. package/dist/test-web/symlinked/element-focus.d.ts +1 -0
  24. package/dist/test-web/symlinked/element-focus.js +3 -0
  25. package/dist/test-web/symlinked/element-position.d.ts +5 -0
  26. package/dist/test-web/symlinked/element-position.js +34 -0
  27. package/dist/test-web/type-into-element.d.ts +3 -0
  28. package/dist/test-web/type-into-element.js +30 -0
  29. package/package.json +55 -0
package/LICENSE-CC0 ADDED
@@ -0,0 +1,121 @@
1
+ CC0 1.0 Universal
2
+
3
+ Creative Commons Legal Code
4
+
5
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12
+ HEREUNDER.
13
+
14
+ Statement of Purpose
15
+
16
+ The laws of most jurisdictions throughout the world automatically confer
17
+ exclusive Copyright and Related Rights (defined below) upon the creator
18
+ and subsequent owner(s) (each and all, an "owner") of an original work of
19
+ authorship and/or a database (each, a "Work").
20
+
21
+ Certain owners wish to permanently relinquish those rights to a Work for
22
+ the purpose of contributing to a commons of creative, cultural and
23
+ scientific works ("Commons") that the public can reliably and without fear
24
+ of later claims of infringement build upon, modify, incorporate in other
25
+ works, reuse and redistribute as freely as possible in any form whatsoever
26
+ and for any purposes, including without limitation commercial purposes.
27
+ These owners may contribute to the Commons to promote the ideal of a free
28
+ culture and the further production of creative, cultural and scientific
29
+ works, or to gain reputation or greater distribution for their Work in
30
+ part through the use and efforts of others.
31
+
32
+ For these and/or other purposes and motivations, and without any
33
+ expectation of additional consideration or compensation, the person
34
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35
+ is an owner of Copyright and Related Rights in the Work, voluntarily
36
+ elects to apply CC0 to the Work and publicly distribute the Work under its
37
+ terms, with knowledge of his or her Copyright and Related Rights in the
38
+ Work and the meaning and intended legal effect of CC0 on those rights.
39
+
40
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
41
+ protected by copyright and related or neighboring rights ("Copyright and
42
+ Related Rights"). Copyright and Related Rights include, but are not
43
+ limited to, the following:
44
+
45
+ i. the right to reproduce, adapt, distribute, perform, display,
46
+ communicate, and translate a Work;
47
+ ii. moral rights retained by the original author(s) and/or performer(s);
48
+ iii. publicity and privacy rights pertaining to a person's image or
49
+ likeness depicted in a Work;
50
+ iv. rights protecting against unfair competition in regards to a Work,
51
+ subject to the limitations in paragraph 4(a), below;
52
+ v. rights protecting the extraction, dissemination, use and reuse of data
53
+ in a Work;
54
+ vi. database rights (such as those arising under Directive 96/9/EC of the
55
+ European Parliament and of the Council of 11 March 1996 on the legal
56
+ protection of databases, and under any national implementation
57
+ thereof, including any amended or successor version of such
58
+ directive); and
59
+ vii. other similar, equivalent or corresponding rights throughout the
60
+ world based on applicable law or treaty, and any national
61
+ implementations thereof.
62
+
63
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
64
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
65
+ irrevocably and unconditionally waives, abandons, and surrenders all of
66
+ Affirmer's Copyright and Related Rights and associated claims and causes
67
+ of action, whether now known or unknown (including existing as well as
68
+ future claims and causes of action), in the Work (i) in all territories
69
+ worldwide, (ii) for the maximum duration provided by applicable law or
70
+ treaty (including future time extensions), (iii) in any current or future
71
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
72
+ including without limitation commercial, advertising or promotional
73
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74
+ member of the public at large and to the detriment of Affirmer's heirs and
75
+ successors, fully intending that such Waiver shall not be subject to
76
+ revocation, rescission, cancellation, termination, or any other legal or
77
+ equitable action to disrupt the quiet enjoyment of the Work by the public
78
+ as contemplated by Affirmer's express Statement of Purpose.
79
+
80
+ 3. Public License Fallback. Should any part of the Waiver for any reason
81
+ be judged legally invalid or ineffective under applicable law, then the
82
+ Waiver shall be preserved to the maximum extent permitted taking into
83
+ account Affirmer's express Statement of Purpose. In addition, to the
84
+ extent the Waiver is so judged Affirmer hereby grants to each affected
85
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
86
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
87
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
88
+ maximum duration provided by applicable law or treaty (including future
89
+ time extensions), (iii) in any current or future medium and for any number
90
+ of copies, and (iv) for any purpose whatsoever, including without
91
+ limitation commercial, advertising or promotional purposes (the
92
+ "License"). The License shall be deemed effective as of the date CC0 was
93
+ applied by Affirmer to the Work. Should any part of the License for any
94
+ reason be judged legally invalid or ineffective under applicable law, such
95
+ partial invalidity or ineffectiveness shall not invalidate the remainder
96
+ of the License, and in such case Affirmer hereby affirms that he or she
97
+ will not (i) exercise any of his or her remaining Copyright and Related
98
+ Rights in the Work or (ii) assert any associated claims and causes of
99
+ action with respect to the Work, in either case contrary to Affirmer's
100
+ express Statement of Purpose.
101
+
102
+ 4. Limitations and Disclaimers.
103
+
104
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
105
+ surrendered, licensed or otherwise affected by this document.
106
+ b. Affirmer offers the Work as-is and makes no representations or
107
+ warranties of any kind concerning the Work, express, implied,
108
+ statutory or otherwise, including without limitation warranties of
109
+ title, merchantability, fitness for a particular purpose, non
110
+ infringement, or the absence of latent or other defects, accuracy, or
111
+ the present or absence of errors, whether or not discoverable, all to
112
+ the greatest extent permissible under applicable law.
113
+ c. Affirmer disclaims responsibility for clearing rights of other persons
114
+ that may apply to the Work or any use thereof, including without
115
+ limitation any person's Copyright and Related Rights in the Work.
116
+ Further, Affirmer disclaims responsibility for obtaining any necessary
117
+ consents, permissions or other rights required for any use of the
118
+ Work.
119
+ d. Affirmer understands and acknowledges that Creative Commons is not a
120
+ party to this document and has no duty or obligation with respect to
121
+ this CC0 or use of the Work.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 electrovir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ import { RuntimeEnvError } from '@augment-vir/core';
2
+ declare function importWebTestApi(): Promise<RuntimeEnvError | {
3
+ cleanupRender: typeof import("@open-wc/testing-helpers/types/src/fixtureWrapper").fixtureCleanup;
4
+ click: typeof import("../test-web/click-element").clickElement;
5
+ deleteInputText: typeof import("../test-web/type-into-element").deleteAllTextInInput;
6
+ ensureFocus: typeof import("../test-web/element-test-focus").focusElement;
7
+ moveMouseTo: typeof import("../test-web/click-element").moveToElement;
8
+ render: typeof import("@open-wc/testing-helpers/types/src/fixture-no-side-effect").fixture;
9
+ type: typeof import("../test-web/type-into-element").typeString;
10
+ typeIntoInput: typeof import("../test-web/type-into-element").typeStringIntoElement;
11
+ }>;
12
+ export declare const testWeb: Exclude<Awaited<ReturnType<typeof importWebTestApi>>, Error>;
13
+ export {};
@@ -0,0 +1,21 @@
1
+ import { isRuntimeEnv, RuntimeEnv, RuntimeEnvError } from '@augment-vir/core';
2
+ async function importWebTestApi() {
3
+ if (!isRuntimeEnv(RuntimeEnv.Web)) {
4
+ return new RuntimeEnvError('The testWeb api cannot be used outside of a browser context.');
5
+ }
6
+ const { clickElement, moveToElement } = await import('../test-web/click-element');
7
+ const { focusElement } = await import('../test-web/element-test-focus');
8
+ const { cleanupFixture, renderFixture } = await import('../test-web/open-wc-exports');
9
+ const { deleteAllTextInInput, typeString, typeStringIntoElement } = await import('../test-web/type-into-element');
10
+ return {
11
+ cleanupRender: cleanupFixture,
12
+ click: clickElement,
13
+ deleteInputText: deleteAllTextInInput,
14
+ ensureFocus: focusElement,
15
+ moveMouseTo: moveToElement,
16
+ render: renderFixture,
17
+ type: typeString,
18
+ typeIntoInput: typeStringIntoElement,
19
+ };
20
+ }
21
+ export const testWeb = (await importWebTestApi());
@@ -0,0 +1,21 @@
1
+ import { ErrorMatchOptions, type CustomOutputAsserter } from '@augment-vir/assert';
2
+ import { type AnyFunction, type TypedFunction } from '@augment-vir/core';
3
+ export type BaseTestCase<OutputGeneric> = {
4
+ it: string;
5
+ only?: boolean | undefined;
6
+ skip?: boolean | undefined;
7
+ } & ({
8
+ expect: OutputGeneric;
9
+ } | {
10
+ throws: ErrorMatchOptions | undefined;
11
+ });
12
+ export type OutputTestCaseSingleInput<FunctionToTest extends AnyFunction> = {
13
+ input: Parameters<FunctionToTest>[0];
14
+ } & BaseTestCase<Awaited<ReturnType<FunctionToTest>>>;
15
+ export type OutputTestCaseMultipleInputs<FunctionToTest extends AnyFunction> = {
16
+ inputs: Parameters<FunctionToTest>['length'] extends never ? FunctionToTest extends TypedFunction<[infer ArgumentsType], any> ? ArgumentsType[] : never : Parameters<FunctionToTest>;
17
+ } & BaseTestCase<Awaited<ReturnType<FunctionToTest>>>;
18
+ export type FunctionTestCase<FunctionToTest extends AnyFunction> = 1 extends Parameters<FunctionToTest>['length'] ? Parameters<FunctionToTest>['length'] extends 0 | 1 ? OutputTestCaseSingleInput<FunctionToTest> : OutputTestCaseMultipleInputs<FunctionToTest> : 0 extends Parameters<FunctionToTest>['length'] ? BaseTestCase<Awaited<ReturnType<FunctionToTest>>> : OutputTestCaseMultipleInputs<FunctionToTest>;
19
+ export declare function itCases<FunctionToTest extends AnyFunction>(functionToTest: FunctionToTest, testCases: ReadonlyArray<FunctionTestCase<typeof functionToTest>>): unknown[];
20
+ export declare function itCases<FunctionToTest extends AnyFunction>(functionToTest: FunctionToTest, customAsserter: CustomOutputAsserter<typeof functionToTest>, testCases: ReadonlyArray<FunctionTestCase<typeof functionToTest>>): unknown[];
21
+ export declare function itCases<FunctionToTest extends AnyFunction>(functionToTest: FunctionToTest, testCasesOrCustomAsserter: CustomOutputAsserter<typeof functionToTest> | ReadonlyArray<FunctionTestCase<typeof functionToTest>>, maybeTestCases?: ReadonlyArray<FunctionTestCase<typeof functionToTest>> | undefined): unknown[];
@@ -0,0 +1,54 @@
1
+ import { assert, check } from '@augment-vir/assert';
2
+ import { ensureErrorAndPrependMessage, } from '@augment-vir/core';
3
+ import { it } from './universal-it.js';
4
+ const unsetError = Symbol('unset-error');
5
+ export function itCases(functionToTest, testCasesOrCustomAsserter, maybeTestCases) {
6
+ const testCases = (maybeTestCases ||
7
+ testCasesOrCustomAsserter);
8
+ if (!check.isArray(testCases)) {
9
+ throw new TypeError('expected an array of test cases');
10
+ }
11
+ const asserter = maybeTestCases ? testCasesOrCustomAsserter : assert.deepEquals;
12
+ if (typeof asserter !== 'function') {
13
+ throw new TypeError('expected a function for the custom asserter');
14
+ }
15
+ return testCases.map((testCase) => {
16
+ const itFunction = testCase.only ? it.only : testCase.skip ? it.skip : it;
17
+ return itFunction(testCase.it, async () => {
18
+ const functionInputs = 'input' in testCase
19
+ ? [testCase.input]
20
+ : 'inputs' in testCase
21
+ ? testCase.inputs
22
+ : // as cast here to cover the case where the input has NO inputs
23
+ [];
24
+ if ('expect' in testCase) {
25
+ await assert.output(asserter, functionToTest, functionInputs, testCase.expect, testCase.it);
26
+ }
27
+ else {
28
+ let caughtError = unsetError;
29
+ try {
30
+ await functionToTest(...functionInputs);
31
+ }
32
+ catch (thrownError) {
33
+ caughtError = thrownError;
34
+ }
35
+ const errorThrower = () => {
36
+ if (caughtError !== unsetError) {
37
+ throw caughtError;
38
+ }
39
+ };
40
+ // give a better name if possible
41
+ Object.defineProperty(errorThrower, 'name', {
42
+ value: functionToTest.name,
43
+ });
44
+ const expectsAnError = !!(testCase.throws?.matchConstructor || testCase.throws?.matchMessage);
45
+ if (caughtError !== unsetError && !expectsAnError) {
46
+ throw ensureErrorAndPrependMessage(caughtError, `${functionToTest.name} threw an unexpected error`);
47
+ }
48
+ else if (expectsAnError) {
49
+ assert.throws(errorThrower, testCase.throws, 'Caught error did not match expectations');
50
+ }
51
+ }
52
+ });
53
+ });
54
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A minimal interface for `describe` that is compatible with both Mocha ({@link mochaDescribe}) and
3
+ * Node.js's built-in test runner ({@link nodeDescribe}). This is used for {@link describe}.
4
+ *
5
+ * @category Testing:Common
6
+ */
7
+ export type UniversalDescribe = UniversalBareDescribe & {
8
+ only: UniversalBareDescribe;
9
+ skip: UniversalBareDescribe;
10
+ };
11
+ /**
12
+ * An interface for the `describe` test function that is compatible with both Mocha
13
+ * ({@link mochaDescribe}) and Node.js's built-in test runner ({@link nodeDescribe}). This is used in
14
+ * {@link UniversalDescribe}. The only difference is that this type does not include `only` and
15
+ * `skip`.
16
+ *
17
+ * @category Testing:Common
18
+ */
19
+ export type UniversalBareDescribe = (this: void, describeThis: string, callback: (this: void) => void) => void;
20
+ export declare const describe: UniversalDescribe;
@@ -0,0 +1,9 @@
1
+ import { isRuntimeEnv, RuntimeEnv } from '@augment-vir/core';
2
+ const describes = isRuntimeEnv(RuntimeEnv.Node)
3
+ ? {
4
+ node: (await import('node:test')).describe,
5
+ }
6
+ : {
7
+ mocha: globalThis.describe,
8
+ };
9
+ export const describe = (describes.mocha || describes.node);
@@ -0,0 +1,27 @@
1
+ import { UniversalContext } from './universal-test-context.js';
2
+ /**
3
+ * An interface for an `it` callback that is compatible with both Mocha ({@link mochaIt}) and
4
+ * Node.js's built-in test runner ({@link nodeIt}) and used in {@link UniversalIt}.
5
+ *
6
+ * @category Testing:Common
7
+ */
8
+ export type UniversalItCallback = (this: void, context: UniversalContext) => Promise<void> | void;
9
+ /**
10
+ * An interface for the `it` test function that is compatible with both Mocha ({@link mochaIt}) and
11
+ * Node.js's built-in test runner ({@link nodeIt}). This is used in {@link UniversalIt}. The only
12
+ * difference is that this type does not include `only` and `skip`.
13
+ *
14
+ * @category Testing:Common
15
+ */
16
+ export type UniversalBareIt = (this: void, doesThis: string, callback: UniversalItCallback) => void;
17
+ /**
18
+ * A minimal interface for `it` that is compatible with both Mocha ({@link mochaIt}) and Node.js's
19
+ * built-in test runner ({@link nodeIt}). This is used for {@link it}.
20
+ *
21
+ * @category Testing:Common
22
+ */
23
+ export type UniversalIt = UniversalBareIt & {
24
+ only: UniversalBareIt;
25
+ skip: UniversalBareIt;
26
+ };
27
+ export declare const it: UniversalIt;
@@ -0,0 +1,9 @@
1
+ import { isRuntimeEnv, RuntimeEnv } from '@augment-vir/core';
2
+ const its = isRuntimeEnv(RuntimeEnv.Node)
3
+ ? {
4
+ node: (await import('node:test')).it,
5
+ }
6
+ : {
7
+ mocha: globalThis.it,
8
+ };
9
+ export const it = (its.mocha || its.node);
@@ -0,0 +1,14 @@
1
+ import { RuntimeEnv } from '@augment-vir/core';
2
+ import { TestContext as NodeTestContextImport } from 'node:test';
3
+ import type { Mocha } from '../../mocha.js';
4
+ export type MochaTestContext = Mocha.Context;
5
+ export type NodeTestContext = NodeTestContextImport;
6
+ export type UniversalContext = NodeTestContext | MochaTestContext;
7
+ export type ContextByEnv = {
8
+ [RuntimeEnv.Node]: NodeTestContext;
9
+ [RuntimeEnv.Web]: Mocha.Context;
10
+ };
11
+ export declare function ensureTestContext<const SpecificEnv extends RuntimeEnv>(context: UniversalContext, env: RuntimeEnv): ContextByEnv[SpecificEnv];
12
+ export declare function assertTestContext<const SpecificEnv extends RuntimeEnv>(context: UniversalContext, env: RuntimeEnv): asserts context is ContextByEnv[SpecificEnv];
13
+ export declare function isTestContext<const SpecificEnv extends RuntimeEnv>(context: UniversalContext, env: RuntimeEnv): context is ContextByEnv[SpecificEnv];
14
+ export declare function determineTestContextEnv(context: UniversalContext): RuntimeEnv;
@@ -0,0 +1,24 @@
1
+ import { RuntimeEnv } from '@augment-vir/core';
2
+ export function ensureTestContext(context, env) {
3
+ assertTestContext(context, env);
4
+ return context;
5
+ }
6
+ export function assertTestContext(context, env) {
7
+ const actualEnv = determineTestContextEnv(context);
8
+ if (actualEnv !== env) {
9
+ throw new TypeError();
10
+ }
11
+ }
12
+ export function isTestContext(context, env) {
13
+ try {
14
+ assertTestContext(context, env);
15
+ return true;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ const nodeOnlyCheckKey = 'diagnostic';
22
+ export function determineTestContextEnv(context) {
23
+ return context[nodeOnlyCheckKey] ? RuntimeEnv.Node : RuntimeEnv.Web;
24
+ }
@@ -0,0 +1,5 @@
1
+ export * from './augments/test-web.js';
2
+ export * from './augments/universal-testing-suite/it-cases.js';
3
+ export * from './augments/universal-testing-suite/universal-describe.js';
4
+ export * from './augments/universal-testing-suite/universal-it.js';
5
+ export * from './augments/universal-testing-suite/universal-test-context.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './augments/test-web.js';
2
+ export * from './augments/universal-testing-suite/it-cases.js';
3
+ export * from './augments/universal-testing-suite/universal-describe.js';
4
+ export * from './augments/universal-testing-suite/universal-it.js';
5
+ export * from './augments/universal-testing-suite/universal-test-context.js';
@@ -0,0 +1,2 @@
1
+ export declare function clickElement(element: Element): Promise<void>;
2
+ export declare function moveToElement(element: Element): Promise<void>;
@@ -0,0 +1,18 @@
1
+ import { sendMouse } from '@web/test-runner-commands';
2
+ import { getCenterOfElement } from './symlinked/element-position.js';
3
+ async function sendMouseToMiddleOfElement(element, operationType) {
4
+ const center = getCenterOfElement(element);
5
+ await sendMouse({
6
+ position: [
7
+ center.x,
8
+ center.y,
9
+ ],
10
+ type: operationType,
11
+ });
12
+ }
13
+ export async function clickElement(element) {
14
+ await sendMouseToMiddleOfElement(element, 'click');
15
+ }
16
+ export async function moveToElement(element) {
17
+ return sendMouseToMiddleOfElement(element, 'move');
18
+ }
@@ -0,0 +1 @@
1
+ export declare function focusElement(element: Element, maxAttemptCount?: number): Promise<void>;
@@ -0,0 +1,17 @@
1
+ import { assert } from '@augment-vir/assert';
2
+ import { clickElement } from './click-element.js';
3
+ import { waitForAnimationFrame } from './symlinked/animation-frame.js';
4
+ import { isElementFocused } from './symlinked/element-focus.js';
5
+ export async function focusElement(element, maxAttemptCount = 20) {
6
+ let attempts = 0;
7
+ while (!isElementFocused(element) && attempts < maxAttemptCount) {
8
+ ++attempts;
9
+ if (!isElementFocused(element)) {
10
+ await clickElement(element);
11
+ }
12
+ if (!isElementFocused(element)) {
13
+ await waitForAnimationFrame();
14
+ }
15
+ }
16
+ assert.isBelow(attempts, maxAttemptCount, `Tried ${maxAttemptCount} times to focus the given input element.`);
17
+ }
@@ -0,0 +1 @@
1
+ export { fixtureCleanup as cleanupFixture, fixture as renderFixture } from '@open-wc/testing-helpers';
@@ -0,0 +1 @@
1
+ export { fixtureCleanup as cleanupFixture, fixture as renderFixture } from '@open-wc/testing-helpers';
@@ -0,0 +1 @@
1
+ export declare function waitForAnimationFrame(frameCount?: number): Promise<void>;
@@ -0,0 +1,17 @@
1
+ import { DeferredPromise } from '@augment-vir/common';
2
+ export async function waitForAnimationFrame(frameCount = 1) {
3
+ const deferredPromise = new DeferredPromise();
4
+ function requestNextFrame() {
5
+ requestAnimationFrame(() => {
6
+ frameCount--;
7
+ if (frameCount) {
8
+ requestNextFrame();
9
+ }
10
+ else {
11
+ deferredPromise.resolve();
12
+ }
13
+ });
14
+ }
15
+ requestNextFrame();
16
+ return deferredPromise.promise;
17
+ }
@@ -0,0 +1 @@
1
+ export declare function isElementFocused(element: Element): boolean;
@@ -0,0 +1,3 @@
1
+ export function isElementFocused(element) {
2
+ return element.matches(':focus');
3
+ }
@@ -0,0 +1,5 @@
1
+ import type { Coords } from '@augment-vir/common';
2
+ export declare function checkIfEntirelyInScrollView(element: Element): Promise<unknown>;
3
+ export declare function checkIfInScrollView(element: Element, ratio: number): Promise<unknown>;
4
+ export declare function getCenterOfElement(element: Element): Coords;
5
+ export declare function appendPositionDebugDiv(position: Coords): HTMLDivElement;
@@ -0,0 +1,34 @@
1
+ import { assert } from '@augment-vir/assert';
2
+ export async function checkIfEntirelyInScrollView(element) {
3
+ return checkIfInScrollView(element, 1);
4
+ }
5
+ export async function checkIfInScrollView(element, ratio) {
6
+ return new Promise((resolve) => {
7
+ const observer = new IntersectionObserver((entries, observerItself) => {
8
+ assert.isLengthAtLeast(entries, 1);
9
+ observerItself.disconnect();
10
+ resolve(entries[0].intersectionRatio >= ratio);
11
+ });
12
+ observer.observe(element);
13
+ });
14
+ }
15
+ export function getCenterOfElement(element) {
16
+ const rect = element.getBoundingClientRect();
17
+ return {
18
+ x: Math.floor((rect.left + rect.right) / 2),
19
+ y: Math.floor((rect.bottom + rect.top) / 2),
20
+ };
21
+ }
22
+ export function appendPositionDebugDiv(position) {
23
+ const div = document.createElement('div');
24
+ div.classList.add('debug');
25
+ div.style.backgroundColor = 'blue';
26
+ div.style.height = '10px';
27
+ div.style.left = `${position.x}px`;
28
+ div.style.position = 'absolute';
29
+ div.style.top = `${position.y}px`;
30
+ div.style.width = '10px';
31
+ div.style.zIndex = '9999';
32
+ document.body.append(div);
33
+ return div;
34
+ }
@@ -0,0 +1,3 @@
1
+ export declare function typeString(input: string): Promise<void>;
2
+ export declare function typeStringIntoElement(input: string, inputElement: Readonly<HTMLInputElement>): Promise<void>;
3
+ export declare function deleteAllTextInInput(inputElement: Readonly<HTMLInputElement>): Promise<void>;
@@ -0,0 +1,30 @@
1
+ import { sendKeys } from '@web/test-runner-commands';
2
+ import { focusElement } from './element-test-focus.js';
3
+ export async function typeString(input) {
4
+ return await sendKeys({
5
+ type: input,
6
+ });
7
+ }
8
+ export async function typeStringIntoElement(input, inputElement) {
9
+ await focusElement(inputElement);
10
+ await typeString(input);
11
+ }
12
+ export async function deleteAllTextInInput(inputElement) {
13
+ const lastValue = inputElement.value;
14
+ if (lastValue) {
15
+ await focusElement(inputElement);
16
+ await sendKeys({
17
+ press: 'Delete',
18
+ });
19
+ await sendKeys({
20
+ press: 'Backspace',
21
+ });
22
+ if (inputElement.value === lastValue) {
23
+ throw new Error(`Input value was not changed at all`);
24
+ }
25
+ if (inputElement.value.length >= lastValue.length) {
26
+ throw new Error(`Input value length was not decreased.`);
27
+ }
28
+ await deleteAllTextInInput(inputElement);
29
+ }
30
+ }
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@augment-vir/test",
3
+ "version": "30.0.0",
4
+ "homepage": "https://github.com/electrovir/augment-vir",
5
+ "bugs": {
6
+ "url": "https://github.com/electrovir/augment-vir/issues"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/electrovir/augment-vir.git"
11
+ },
12
+ "license": "(MIT or CC0 1.0)",
13
+ "author": {
14
+ "name": "electrovir",
15
+ "url": "https://github.com/electrovir"
16
+ },
17
+ "type": "module",
18
+ "main": "dist/index.js",
19
+ "module": "dist/index.js",
20
+ "types": "dist/index.d.ts",
21
+ "scripts": {
22
+ "compile": "virmator compile",
23
+ "docs": "virmator docs",
24
+ "start": "tsx src/index.ts",
25
+ "test": "concurrently --colors --kill-others-on-fail -c green,blue --names node,web \"npm run test:node\" \"npm run test:web\"",
26
+ "test:coverage": "npm run test",
27
+ "test:docs": "virmator docs check",
28
+ "test:node": "virmator test --no-deps node 'src/augments/universal-testing-suite/**/*.test.ts'",
29
+ "test:update": "npm test",
30
+ "test:web": "virmator test --no-deps web 'src/test-web/**/*.test.ts'"
31
+ },
32
+ "dependencies": {
33
+ "@augment-vir/assert": "^30.0.0",
34
+ "@augment-vir/common": "^30.0.0",
35
+ "@open-wc/testing-helpers": "^3.0.1",
36
+ "type-fest": "^4.25.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^22.5.0",
40
+ "@web/dev-server-esbuild": "^1.0.2",
41
+ "@web/test-runner": "^0.18.3",
42
+ "@web/test-runner-commands": "^0.9.0",
43
+ "@web/test-runner-playwright": "^0.11.0",
44
+ "concurrently": "^8.2.2",
45
+ "element-vir": "^22.2.2",
46
+ "istanbul-smart-text-reporter": "^1.1.4",
47
+ "typescript": "^5.5.4"
48
+ },
49
+ "engines": {
50
+ "node": ">=22"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ }
55
+ }