@augment-vir/test 30.0.0 → 30.0.2
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.
- package/README.md +10 -0
- package/dist/augments/test-web.d.ts +42 -3
- package/dist/augments/test-web.js +44 -5
- package/dist/augments/universal-testing-suite/it-cases.d.ts +33 -6
- package/dist/augments/universal-testing-suite/it-cases.js +10 -0
- package/dist/augments/universal-testing-suite/universal-describe.d.ts +44 -9
- package/dist/augments/universal-testing-suite/universal-describe.js +28 -1
- package/dist/augments/universal-testing-suite/universal-it.d.ts +52 -10
- package/dist/augments/universal-testing-suite/universal-it.js +29 -1
- package/dist/augments/universal-testing-suite/universal-test-context.d.ts +66 -3
- package/dist/augments/universal-testing-suite/universal-test-context.js +29 -1
- package/dist/mocha-types.d.ts +73 -0
- package/dist/mocha-types.js +26 -0
- package/dist/test-web/symlinked/animation-frame.d.ts +8 -0
- package/dist/test-web/symlinked/animation-frame.js +8 -0
- package/dist/test-web/symlinked/element-focus.d.ts +7 -0
- package/dist/test-web/symlinked/element-focus.js +7 -0
- package/dist/test-web/symlinked/element-position.d.ts +34 -1
- package/dist/test-web/symlinked/element-position.js +34 -1
- package/dist/test-web/type-into-element.d.ts +2 -2
- package/dist/test-web/type-into-element.js +4 -4
- package/package.json +22 -10
- package/dist/test-web/open-wc-exports.d.ts +0 -1
- package/dist/test-web/open-wc-exports.js +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @augment-vir/test
|
|
2
|
+
|
|
3
|
+
A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner with the following main exports:
|
|
4
|
+
|
|
5
|
+
- [`describe`](https://electrovir.github.io/augment-vir/functions/describe.html): the normal describe test suite function, automatically imported based on the current environment.
|
|
6
|
+
- [`it`](https://electrovir.github.io/augment-vir/functions/it.html): the normal it test function, automatically imported based on the current environment.
|
|
7
|
+
- [`itCases`](https://electrovir.github.io/augment-vir/functions/itCases.html): a succinct way to test lots of inputs and outputs to a single function.
|
|
8
|
+
- [`testWeb`](https://electrovir.github.io/augment-vir/variables/testWeb.html): a API of web-testing utilities, only available in browser environments.
|
|
9
|
+
|
|
10
|
+
See the docs under `Test`, or `Package: @augment-vir/test` here: https://electrovir.github.io/augment-vir
|
|
@@ -1,13 +1,52 @@
|
|
|
1
1
|
import { RuntimeEnvError } from '@augment-vir/core';
|
|
2
2
|
declare function importWebTestApi(): Promise<RuntimeEnvError | {
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Cleans up all rendered test HTML by removing the actual wrapper nodes. Common use case is
|
|
5
|
+
* at the end of each test.
|
|
6
|
+
*/
|
|
7
|
+
cleanupRender: typeof import("@open-wc/testing-helpers").fixtureCleanup;
|
|
8
|
+
/** Clicks the center of the given element. */
|
|
4
9
|
click: typeof import("../test-web/click-element").clickElement;
|
|
10
|
+
/** Deletes all text that has been typed into the given `<input>` element. */
|
|
5
11
|
deleteInputText: typeof import("../test-web/type-into-element").deleteAllTextInInput;
|
|
12
|
+
/** Repeatedly tries to focus the given element until it is focused. */
|
|
6
13
|
ensureFocus: typeof import("../test-web/element-test-focus").focusElement;
|
|
14
|
+
/** Moves the mouse to the center of the given element. */
|
|
7
15
|
moveMouseTo: typeof import("../test-web/click-element").moveToElement;
|
|
8
|
-
|
|
9
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Renders a string or TemplateResult and puts it in the DOM via a fixtureWrapper.
|
|
18
|
+
*
|
|
19
|
+
* Uses `fixture` from `@open-wc/testing-helpers`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import {testWeb} from '@augment-vir/test';
|
|
25
|
+
* import {html} from 'element-vir';
|
|
26
|
+
*
|
|
27
|
+
* const rendered = await testWeb.render(html`
|
|
28
|
+
* <${MyElement}><span></span></${MyElement}>
|
|
29
|
+
* `);
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @returns A Promise that will resolve to the first child of the rendered HTML.
|
|
33
|
+
*/
|
|
34
|
+
render: typeof import("@open-wc/testing-helpers").fixture;
|
|
35
|
+
/** Focus the given element and then type the given string. */
|
|
10
36
|
typeIntoInput: typeof import("../test-web/type-into-element").typeStringIntoElement;
|
|
37
|
+
/**
|
|
38
|
+
* Types the given string as if it were input by a keyboard. This doesn't try to type into
|
|
39
|
+
* any element in particular, it'll go wherever the current focus is, if any.
|
|
40
|
+
*/
|
|
41
|
+
typeText: typeof import("../test-web/type-into-element").typeString;
|
|
11
42
|
}>;
|
|
43
|
+
/**
|
|
44
|
+
* A suite of web test helpers. This is only accessible within a browser runtime. If accessed
|
|
45
|
+
* outside of a browser runtime, it'll be an Error instead of a collection of test helpers.
|
|
46
|
+
*
|
|
47
|
+
* @category Test
|
|
48
|
+
* @category Package : @augment-vir/test
|
|
49
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
50
|
+
*/
|
|
12
51
|
export declare const testWeb: Exclude<Awaited<ReturnType<typeof importWebTestApi>>, Error>;
|
|
13
52
|
export {};
|
|
@@ -1,21 +1,60 @@
|
|
|
1
1
|
import { isRuntimeEnv, RuntimeEnv, RuntimeEnvError } from '@augment-vir/core';
|
|
2
2
|
async function importWebTestApi() {
|
|
3
3
|
if (!isRuntimeEnv(RuntimeEnv.Web)) {
|
|
4
|
-
return new RuntimeEnvError(
|
|
4
|
+
return new RuntimeEnvError("The 'testWeb' api cannot be used outside of a browser context.");
|
|
5
5
|
}
|
|
6
6
|
const { clickElement, moveToElement } = await import('../test-web/click-element');
|
|
7
7
|
const { focusElement } = await import('../test-web/element-test-focus');
|
|
8
|
-
const { cleanupFixture, renderFixture } = await import('../test-web/open-wc-exports');
|
|
9
8
|
const { deleteAllTextInInput, typeString, typeStringIntoElement } = await import('../test-web/type-into-element');
|
|
9
|
+
const { fixtureCleanup, fixture } = await import('@open-wc/testing-helpers');
|
|
10
10
|
return {
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Cleans up all rendered test HTML by removing the actual wrapper nodes. Common use case is
|
|
13
|
+
* at the end of each test.
|
|
14
|
+
*/
|
|
15
|
+
cleanupRender: fixtureCleanup,
|
|
16
|
+
/** Clicks the center of the given element. */
|
|
12
17
|
click: clickElement,
|
|
18
|
+
/** Deletes all text that has been typed into the given `<input>` element. */
|
|
13
19
|
deleteInputText: deleteAllTextInInput,
|
|
20
|
+
/** Repeatedly tries to focus the given element until it is focused. */
|
|
14
21
|
ensureFocus: focusElement,
|
|
22
|
+
/** Moves the mouse to the center of the given element. */
|
|
15
23
|
moveMouseTo: moveToElement,
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Renders a string or TemplateResult and puts it in the DOM via a fixtureWrapper.
|
|
26
|
+
*
|
|
27
|
+
* Uses `fixture` from `@open-wc/testing-helpers`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* import {testWeb} from '@augment-vir/test';
|
|
33
|
+
* import {html} from 'element-vir';
|
|
34
|
+
*
|
|
35
|
+
* const rendered = await testWeb.render(html`
|
|
36
|
+
* <${MyElement}><span></span></${MyElement}>
|
|
37
|
+
* `);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @returns A Promise that will resolve to the first child of the rendered HTML.
|
|
41
|
+
*/
|
|
42
|
+
render: fixture,
|
|
43
|
+
/** Focus the given element and then type the given string. */
|
|
18
44
|
typeIntoInput: typeStringIntoElement,
|
|
45
|
+
/**
|
|
46
|
+
* Types the given string as if it were input by a keyboard. This doesn't try to type into
|
|
47
|
+
* any element in particular, it'll go wherever the current focus is, if any.
|
|
48
|
+
*/
|
|
49
|
+
typeText: typeString,
|
|
19
50
|
};
|
|
20
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* A suite of web test helpers. This is only accessible within a browser runtime. If accessed
|
|
54
|
+
* outside of a browser runtime, it'll be an Error instead of a collection of test helpers.
|
|
55
|
+
*
|
|
56
|
+
* @category Test
|
|
57
|
+
* @category Package : @augment-vir/test
|
|
58
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
59
|
+
*/
|
|
21
60
|
export const testWeb = (await importWebTestApi());
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { ErrorMatchOptions, type CustomOutputAsserter } from '@augment-vir/assert';
|
|
2
2
|
import { type AnyFunction, type TypedFunction } from '@augment-vir/core';
|
|
3
|
+
/**
|
|
4
|
+
* Base test case for {@link itCases}.
|
|
5
|
+
*
|
|
6
|
+
* @category Test : Util
|
|
7
|
+
* @category Package : @augment-vir/test
|
|
8
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
9
|
+
*/
|
|
3
10
|
export type BaseTestCase<OutputGeneric> = {
|
|
4
11
|
it: string;
|
|
5
12
|
only?: boolean | undefined;
|
|
@@ -9,13 +16,33 @@ export type BaseTestCase<OutputGeneric> = {
|
|
|
9
16
|
} | {
|
|
10
17
|
throws: ErrorMatchOptions | undefined;
|
|
11
18
|
});
|
|
12
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Input for a function test that only has a single input.
|
|
21
|
+
*
|
|
22
|
+
* @category Test : Util
|
|
23
|
+
* @category Package : @augment-vir/test
|
|
24
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
25
|
+
*/
|
|
26
|
+
export type FunctionTestCaseSingleInput<FunctionToTest extends AnyFunction> = {
|
|
13
27
|
input: Parameters<FunctionToTest>[0];
|
|
14
28
|
} & BaseTestCase<Awaited<ReturnType<FunctionToTest>>>;
|
|
15
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Input for a function test that has multiple inputs.
|
|
31
|
+
*
|
|
32
|
+
* @category Test : Util
|
|
33
|
+
* @category Package : @augment-vir/test
|
|
34
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
35
|
+
*/
|
|
36
|
+
export type FunctionTestCaseMultipleInputs<FunctionToTest extends AnyFunction> = {
|
|
16
37
|
inputs: Parameters<FunctionToTest>['length'] extends never ? FunctionToTest extends TypedFunction<[infer ArgumentsType], any> ? ArgumentsType[] : never : Parameters<FunctionToTest>;
|
|
17
38
|
} & BaseTestCase<Awaited<ReturnType<FunctionToTest>>>;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
39
|
+
/**
|
|
40
|
+
* A function test case used for {@link itCases}.
|
|
41
|
+
*
|
|
42
|
+
* @category Test : Util
|
|
43
|
+
* @category Package : @augment-vir/test
|
|
44
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
45
|
+
*/
|
|
46
|
+
export type FunctionTestCase<FunctionToTest extends AnyFunction> = 1 extends Parameters<FunctionToTest>['length'] ? Parameters<FunctionToTest>['length'] extends 0 | 1 ? FunctionTestCaseSingleInput<FunctionToTest> : FunctionTestCaseMultipleInputs<FunctionToTest> : 0 extends Parameters<FunctionToTest>['length'] ? BaseTestCase<Awaited<ReturnType<FunctionToTest>>> : FunctionTestCaseMultipleInputs<FunctionToTest>;
|
|
47
|
+
export declare function itCases<const FunctionToTest extends AnyFunction>(functionToTest: FunctionToTest, customAsserter: CustomOutputAsserter<NoInfer<FunctionToTest>>, testCases: ReadonlyArray<FunctionTestCase<NoInfer<FunctionToTest>>>): unknown[];
|
|
48
|
+
export declare function itCases<const FunctionToTest extends AnyFunction>(functionToTest: FunctionToTest, testCases: ReadonlyArray<FunctionTestCase<NoInfer<FunctionToTest>>>): unknown[];
|
|
@@ -2,6 +2,16 @@ import { assert, check } from '@augment-vir/assert';
|
|
|
2
2
|
import { ensureErrorAndPrependMessage, } from '@augment-vir/core';
|
|
3
3
|
import { it } from './universal-it.js';
|
|
4
4
|
const unsetError = Symbol('unset-error');
|
|
5
|
+
/**
|
|
6
|
+
* Succinctly run many input / output tests for a pure function without repeating `it` boilerplate.
|
|
7
|
+
* Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and
|
|
8
|
+
* [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test
|
|
9
|
+
* runners.
|
|
10
|
+
*
|
|
11
|
+
* @category Test
|
|
12
|
+
* @category Package : @augment-vir/test
|
|
13
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
14
|
+
*/
|
|
5
15
|
export function itCases(functionToTest, testCasesOrCustomAsserter, maybeTestCases) {
|
|
6
16
|
const testCases = (maybeTestCases ||
|
|
7
17
|
testCasesOrCustomAsserter);
|
|
@@ -1,20 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A minimal interface for
|
|
3
|
-
* Node.js's built-in test runner ({@link nodeDescribe}). This is used for {@link describe}.
|
|
2
|
+
* A minimal interface for {@link describe}. This is used in {@link UniversalDescribe}.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
4
|
+
* Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and
|
|
5
|
+
* [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test
|
|
6
|
+
* runners.
|
|
7
|
+
*
|
|
8
|
+
* @category Test : Util
|
|
9
|
+
* @category Package : @augment-vir/test
|
|
10
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
11
|
+
*/
|
|
12
|
+
export type UniversalBareDescribe = (this: void, describeThis: string, callback: (this: void) => void) => void;
|
|
13
|
+
/**
|
|
14
|
+
* The type for {@link describe}.
|
|
15
|
+
*
|
|
16
|
+
* Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and
|
|
17
|
+
* [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test
|
|
18
|
+
* runners.
|
|
19
|
+
*
|
|
20
|
+
* @category Test : Util
|
|
21
|
+
* @category Package : @augment-vir/test
|
|
22
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
6
23
|
*/
|
|
7
24
|
export type UniversalDescribe = UniversalBareDescribe & {
|
|
8
25
|
only: UniversalBareDescribe;
|
|
9
26
|
skip: UniversalBareDescribe;
|
|
10
27
|
};
|
|
11
28
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* {@link UniversalDescribe}. The only difference is that this type does not include `only` and
|
|
15
|
-
* `skip`.
|
|
29
|
+
* A test suite declaration. This can be used in both web tests _and_ node tests, so you only have
|
|
30
|
+
* import from a single place and learn a single interface.
|
|
16
31
|
*
|
|
17
|
-
*
|
|
32
|
+
* This should be passed a _noun_ (preferably a single word, when possible) of what is going to be
|
|
33
|
+
* tested inside the test suite. Its callback should call `it` from this same package.
|
|
34
|
+
*
|
|
35
|
+
* Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and
|
|
36
|
+
* [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test
|
|
37
|
+
* runners.
|
|
38
|
+
*
|
|
39
|
+
* @category Test
|
|
40
|
+
* @category Package : @augment-vir/test
|
|
41
|
+
* @example
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* import {describe, it} from '@augment-vir/test';
|
|
45
|
+
*
|
|
46
|
+
* describe(myFunction.name, () => {
|
|
47
|
+
* it('does a thing', () => {
|
|
48
|
+
* myFunction();
|
|
49
|
+
* });
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
18
54
|
*/
|
|
19
|
-
export type UniversalBareDescribe = (this: void, describeThis: string, callback: (this: void) => void) => void;
|
|
20
55
|
export declare const describe: UniversalDescribe;
|
|
@@ -6,4 +6,31 @@ const describes = isRuntimeEnv(RuntimeEnv.Node)
|
|
|
6
6
|
: {
|
|
7
7
|
mocha: globalThis.describe,
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A test suite declaration. This can be used in both web tests _and_ node tests, so you only have
|
|
11
|
+
* import from a single place and learn a single interface.
|
|
12
|
+
*
|
|
13
|
+
* This should be passed a _noun_ (preferably a single word, when possible) of what is going to be
|
|
14
|
+
* tested inside the test suite. Its callback should call `it` from this same package.
|
|
15
|
+
*
|
|
16
|
+
* Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and
|
|
17
|
+
* [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test
|
|
18
|
+
* runners.
|
|
19
|
+
*
|
|
20
|
+
* @category Test
|
|
21
|
+
* @category Package : @augment-vir/test
|
|
22
|
+
* @example
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import {describe, it} from '@augment-vir/test';
|
|
26
|
+
*
|
|
27
|
+
* describe(myFunction.name, () => {
|
|
28
|
+
* it('does a thing', () => {
|
|
29
|
+
* myFunction();
|
|
30
|
+
* });
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
35
|
+
*/
|
|
36
|
+
export const describe = describes.mocha || describes.node;
|
|
@@ -1,27 +1,69 @@
|
|
|
1
1
|
import { UniversalContext } from './universal-test-context.js';
|
|
2
2
|
/**
|
|
3
|
-
* An interface for an
|
|
4
|
-
* Node.js's built-in test runner ({@link nodeIt}) and used in {@link UniversalIt}.
|
|
3
|
+
* An interface for an {@link it} callback. Used in {@link UniversalBareIt}.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
5
|
+
* Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and
|
|
6
|
+
* [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test
|
|
7
|
+
* runners.
|
|
8
|
+
*
|
|
9
|
+
* @category Test : Util
|
|
10
|
+
* @category Package : @augment-vir/test
|
|
11
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
7
12
|
*/
|
|
8
13
|
export type UniversalItCallback = (this: void, context: UniversalContext) => Promise<void> | void;
|
|
9
14
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
15
|
+
* A minimal interface for {@link it}. This is used in {@link UniversalIt}.
|
|
16
|
+
*
|
|
17
|
+
* Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and
|
|
18
|
+
* [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test
|
|
19
|
+
* runners.
|
|
13
20
|
*
|
|
14
|
-
* @category
|
|
21
|
+
* @category Test : Util
|
|
22
|
+
* @category Package : @augment-vir/test
|
|
23
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
15
24
|
*/
|
|
16
25
|
export type UniversalBareIt = (this: void, doesThis: string, callback: UniversalItCallback) => void;
|
|
17
26
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
27
|
+
* The type for {@link it}.
|
|
28
|
+
*
|
|
29
|
+
* Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and
|
|
30
|
+
* [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test
|
|
31
|
+
* runners.
|
|
20
32
|
*
|
|
21
|
-
* @category
|
|
33
|
+
* @category Test : Util
|
|
34
|
+
* @category Package : @augment-vir/test
|
|
35
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
22
36
|
*/
|
|
23
37
|
export type UniversalIt = UniversalBareIt & {
|
|
24
38
|
only: UniversalBareIt;
|
|
25
39
|
skip: UniversalBareIt;
|
|
26
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* A single test declaration. This can be used in both web tests _and_ node tests, so you only have
|
|
43
|
+
* import from a single place and learn a single interface.
|
|
44
|
+
*
|
|
45
|
+
* This should be nested within a `describe` call. The `it` name should form a sentence fragment
|
|
46
|
+
* that is attached to the parent `describe`'s input. The sentence should ultimately read like this:
|
|
47
|
+
* "myFunction, it does a thing" (as shown in the example below).
|
|
48
|
+
*
|
|
49
|
+
* Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and
|
|
50
|
+
* [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test
|
|
51
|
+
* runners.
|
|
52
|
+
*
|
|
53
|
+
* @category Test
|
|
54
|
+
* @category Package : @augment-vir/test
|
|
55
|
+
* @example
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* import {describe, it} from '@augment-vir/test';
|
|
59
|
+
*
|
|
60
|
+
* describe(myFunction.name, () => {
|
|
61
|
+
* it('does a thing', () => {
|
|
62
|
+
* myFunction();
|
|
63
|
+
* });
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
68
|
+
*/
|
|
27
69
|
export declare const it: UniversalIt;
|
|
@@ -6,4 +6,32 @@ const its = isRuntimeEnv(RuntimeEnv.Node)
|
|
|
6
6
|
: {
|
|
7
7
|
mocha: globalThis.it,
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A single test declaration. This can be used in both web tests _and_ node tests, so you only have
|
|
11
|
+
* import from a single place and learn a single interface.
|
|
12
|
+
*
|
|
13
|
+
* This should be nested within a `describe` call. The `it` name should form a sentence fragment
|
|
14
|
+
* that is attached to the parent `describe`'s input. The sentence should ultimately read like this:
|
|
15
|
+
* "myFunction, it does a thing" (as shown in the example below).
|
|
16
|
+
*
|
|
17
|
+
* Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and
|
|
18
|
+
* [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test
|
|
19
|
+
* runners.
|
|
20
|
+
*
|
|
21
|
+
* @category Test
|
|
22
|
+
* @category Package : @augment-vir/test
|
|
23
|
+
* @example
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* import {describe, it} from '@augment-vir/test';
|
|
27
|
+
*
|
|
28
|
+
* describe(myFunction.name, () => {
|
|
29
|
+
* it('does a thing', () => {
|
|
30
|
+
* myFunction();
|
|
31
|
+
* });
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
36
|
+
*/
|
|
37
|
+
export const it = its.mocha || its.node;
|
|
@@ -1,14 +1,77 @@
|
|
|
1
1
|
import { RuntimeEnv } from '@augment-vir/core';
|
|
2
2
|
import { TestContext as NodeTestContextImport } from 'node:test';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type { MochaContext } from '../../mocha-types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The test context for [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or
|
|
6
|
+
* other Mocha-style test runners.
|
|
7
|
+
*
|
|
8
|
+
* @category Test : Util
|
|
9
|
+
* @category Package : @augment-vir/test
|
|
10
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
11
|
+
*/
|
|
12
|
+
export type MochaTestContext = MochaContext;
|
|
13
|
+
/**
|
|
14
|
+
* The test context for [Node.js's test runner](https://nodejs.org/api/test.html).
|
|
15
|
+
*
|
|
16
|
+
* @category Test : Util
|
|
17
|
+
* @category Package : @augment-vir/test
|
|
18
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
19
|
+
*/
|
|
5
20
|
export type NodeTestContext = NodeTestContextImport;
|
|
21
|
+
/**
|
|
22
|
+
* Test context provided by `it`'s callback.
|
|
23
|
+
*
|
|
24
|
+
* Compatible with both [Node.js's test runner](https://nodejs.org/api/test.html) and
|
|
25
|
+
* [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) or other Mocha-style test
|
|
26
|
+
* runners.
|
|
27
|
+
*
|
|
28
|
+
* @category Test : Util
|
|
29
|
+
* @category Package : @augment-vir/test
|
|
30
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
31
|
+
*/
|
|
6
32
|
export type UniversalContext = NodeTestContext | MochaTestContext;
|
|
33
|
+
/**
|
|
34
|
+
* Test context by runtime env when [Node.js's test runner](https://nodejs.org/api/test.html) is
|
|
35
|
+
* used for Node tests and [web-test-runner](https://modern-web.dev/docs/test-runner/overview/) is
|
|
36
|
+
* used for web tests.
|
|
37
|
+
*
|
|
38
|
+
* @category Test : Util
|
|
39
|
+
* @category Package : @augment-vir/test
|
|
40
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
41
|
+
*/
|
|
7
42
|
export type ContextByEnv = {
|
|
8
43
|
[RuntimeEnv.Node]: NodeTestContext;
|
|
9
|
-
[RuntimeEnv.Web]:
|
|
44
|
+
[RuntimeEnv.Web]: MochaContext;
|
|
10
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Ensures that the given context is for the given env, otherwise throws an Error.
|
|
48
|
+
*
|
|
49
|
+
* @category Test : Util
|
|
50
|
+
* @category Package : @augment-vir/test
|
|
51
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
52
|
+
*/
|
|
11
53
|
export declare function ensureTestContext<const SpecificEnv extends RuntimeEnv>(context: UniversalContext, env: RuntimeEnv): ContextByEnv[SpecificEnv];
|
|
54
|
+
/**
|
|
55
|
+
* Asserts that the given context is for the given env, otherwise throws an Error.
|
|
56
|
+
*
|
|
57
|
+
* @category Test : Util
|
|
58
|
+
* @category Package : @augment-vir/test
|
|
59
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
60
|
+
*/
|
|
12
61
|
export declare function assertTestContext<const SpecificEnv extends RuntimeEnv>(context: UniversalContext, env: RuntimeEnv): asserts context is ContextByEnv[SpecificEnv];
|
|
62
|
+
/**
|
|
63
|
+
* Checks that the given context is for the given env.
|
|
64
|
+
*
|
|
65
|
+
* @category Test : Util
|
|
66
|
+
* @category Package : @augment-vir/test
|
|
67
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
68
|
+
*/
|
|
13
69
|
export declare function isTestContext<const SpecificEnv extends RuntimeEnv>(context: UniversalContext, env: RuntimeEnv): context is ContextByEnv[SpecificEnv];
|
|
70
|
+
/**
|
|
71
|
+
* Determine the env for the given test context.
|
|
72
|
+
*
|
|
73
|
+
* @category Test : Util
|
|
74
|
+
* @category Package : @augment-vir/test
|
|
75
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
76
|
+
*/
|
|
14
77
|
export declare function determineTestContextEnv(context: UniversalContext): RuntimeEnv;
|
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import { RuntimeEnv } from '@augment-vir/core';
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that the given context is for the given env, otherwise throws an Error.
|
|
4
|
+
*
|
|
5
|
+
* @category Test : Util
|
|
6
|
+
* @category Package : @augment-vir/test
|
|
7
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
8
|
+
*/
|
|
2
9
|
export function ensureTestContext(context, env) {
|
|
3
10
|
assertTestContext(context, env);
|
|
4
11
|
return context;
|
|
5
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Asserts that the given context is for the given env, otherwise throws an Error.
|
|
15
|
+
*
|
|
16
|
+
* @category Test : Util
|
|
17
|
+
* @category Package : @augment-vir/test
|
|
18
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
19
|
+
*/
|
|
6
20
|
export function assertTestContext(context, env) {
|
|
7
21
|
const actualEnv = determineTestContextEnv(context);
|
|
8
22
|
if (actualEnv !== env) {
|
|
9
|
-
throw new TypeError();
|
|
23
|
+
throw new TypeError(`Provided test context is not for the expected env '${env}'.`);
|
|
10
24
|
}
|
|
11
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks that the given context is for the given env.
|
|
28
|
+
*
|
|
29
|
+
* @category Test : Util
|
|
30
|
+
* @category Package : @augment-vir/test
|
|
31
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
32
|
+
*/
|
|
12
33
|
export function isTestContext(context, env) {
|
|
13
34
|
try {
|
|
14
35
|
assertTestContext(context, env);
|
|
@@ -19,6 +40,13 @@ export function isTestContext(context, env) {
|
|
|
19
40
|
}
|
|
20
41
|
}
|
|
21
42
|
const nodeOnlyCheckKey = 'diagnostic';
|
|
43
|
+
/**
|
|
44
|
+
* Determine the env for the given test context.
|
|
45
|
+
*
|
|
46
|
+
* @category Test : Util
|
|
47
|
+
* @category Package : @augment-vir/test
|
|
48
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
49
|
+
*/
|
|
22
50
|
export function determineTestContextEnv(context) {
|
|
23
51
|
return context[nodeOnlyCheckKey] ? RuntimeEnv.Node : RuntimeEnv.Web;
|
|
24
52
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracted from https://www.npmjs.com/package/@types/mocha/v/10.0.7 with modifications to prevent
|
|
3
|
+
* leakage of global types.
|
|
4
|
+
*
|
|
5
|
+
* The original code has the following license:
|
|
6
|
+
*
|
|
7
|
+
* MIT License
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) Microsoft Corporation.
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
12
|
+
* associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
13
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
14
|
+
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
* furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or
|
|
18
|
+
* substantial portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
21
|
+
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
22
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
23
|
+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
|
25
|
+
*/
|
|
26
|
+
interface Runnable extends NodeJS.EventEmitter {
|
|
27
|
+
on(event: 'error', listener: (error: any) => void): this;
|
|
28
|
+
once(event: 'error', listener: (error: any) => void): this;
|
|
29
|
+
addListener(event: 'error', listener: (error: any) => void): this;
|
|
30
|
+
removeListener(event: 'error', listener: (error: any) => void): this;
|
|
31
|
+
prependListener(event: 'error', listener: (error: any) => void): this;
|
|
32
|
+
prependOnceListener(event: 'error', listener: (error: any) => void): this;
|
|
33
|
+
emit(name: 'error', error: any): boolean;
|
|
34
|
+
}
|
|
35
|
+
interface Runnable extends NodeJS.EventEmitter {
|
|
36
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
37
|
+
once(event: string, listener: (...args: any[]) => void): this;
|
|
38
|
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
|
39
|
+
removeListener(event: string, listener: (...args: any[]) => void): this;
|
|
40
|
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
41
|
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
|
42
|
+
emit(name: string, ...args: any[]): boolean;
|
|
43
|
+
}
|
|
44
|
+
interface Test extends Runnable {
|
|
45
|
+
type: 'test';
|
|
46
|
+
speed?: 'slow' | 'medium' | 'fast' | undefined;
|
|
47
|
+
err?: Error | undefined;
|
|
48
|
+
clone(): Test;
|
|
49
|
+
}
|
|
50
|
+
export interface MochaContext {
|
|
51
|
+
test?: Runnable | undefined;
|
|
52
|
+
currentTest?: Test | undefined;
|
|
53
|
+
/** Get the context `Runnable`. */
|
|
54
|
+
runnable(): Runnable;
|
|
55
|
+
/** Set the context `Runnable`. */
|
|
56
|
+
runnable(runnable: Runnable): MochaContext;
|
|
57
|
+
/** Get test timeout. */
|
|
58
|
+
timeout(): number;
|
|
59
|
+
/** Set test timeout. */
|
|
60
|
+
timeout(ms: string | number): MochaContext;
|
|
61
|
+
/** Get test slowness threshold. */
|
|
62
|
+
slow(): number;
|
|
63
|
+
/** Set test slowness threshold. */
|
|
64
|
+
slow(ms: string | number): MochaContext;
|
|
65
|
+
/** Mark a test as skipped. */
|
|
66
|
+
skip(): never;
|
|
67
|
+
/** Get the number of allowed retries on failed tests. */
|
|
68
|
+
retries(): number;
|
|
69
|
+
/** Set the number of allowed retries on failed tests. */
|
|
70
|
+
retries(n: number): MochaContext;
|
|
71
|
+
[key: string]: any;
|
|
72
|
+
}
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracted from https://www.npmjs.com/package/@types/mocha/v/10.0.7 with modifications to prevent
|
|
3
|
+
* leakage of global types.
|
|
4
|
+
*
|
|
5
|
+
* The original code has the following license:
|
|
6
|
+
*
|
|
7
|
+
* MIT License
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) Microsoft Corporation.
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
12
|
+
* associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
13
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
14
|
+
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
* furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or
|
|
18
|
+
* substantial portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
21
|
+
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
22
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
23
|
+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
|
25
|
+
*/
|
|
26
|
+
export {};
|
|
@@ -1 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wait for an animation frame's duration. Optionally, wait for multiple frames by providing a
|
|
3
|
+
* `frameCount` input.
|
|
4
|
+
*
|
|
5
|
+
* @category Web
|
|
6
|
+
* @category Package : @augment-vir/web
|
|
7
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
8
|
+
*/
|
|
1
9
|
export declare function waitForAnimationFrame(frameCount?: number): Promise<void>;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { DeferredPromise } from '@augment-vir/common';
|
|
2
|
+
/**
|
|
3
|
+
* Wait for an animation frame's duration. Optionally, wait for multiple frames by providing a
|
|
4
|
+
* `frameCount` input.
|
|
5
|
+
*
|
|
6
|
+
* @category Web
|
|
7
|
+
* @category Package : @augment-vir/web
|
|
8
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
9
|
+
*/
|
|
2
10
|
export async function waitForAnimationFrame(frameCount = 1) {
|
|
3
11
|
const deferredPromise = new DeferredPromise();
|
|
4
12
|
function requestNextFrame() {
|
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects whether the given element is currently focused.
|
|
3
|
+
*
|
|
4
|
+
* @category Web : Elements
|
|
5
|
+
* @category Package : @augment-vir/web
|
|
6
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
7
|
+
*/
|
|
1
8
|
export declare function isElementFocused(element: Element): boolean;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects whether the given element is currently focused.
|
|
3
|
+
*
|
|
4
|
+
* @category Web : Elements
|
|
5
|
+
* @category Package : @augment-vir/web
|
|
6
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
7
|
+
*/
|
|
1
8
|
export function isElementFocused(element) {
|
|
2
9
|
return element.matches(':focus');
|
|
3
10
|
}
|
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
import type { Coords } from '@augment-vir/common';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the current element is completely visible in its scroll view.
|
|
4
|
+
*
|
|
5
|
+
* @category Web : Elements
|
|
6
|
+
* @category Package : @augment-vir/web
|
|
7
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
8
|
+
*/
|
|
2
9
|
export declare function checkIfEntirelyInScrollView(element: Element): Promise<unknown>;
|
|
3
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Check if the given element is visible in its scroll container to the degree of the given ratio.
|
|
12
|
+
*
|
|
13
|
+
* @category Web : Elements
|
|
14
|
+
* @category Package : @augment-vir/web
|
|
15
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkIfInScrollView(element: Element,
|
|
18
|
+
/** A number from 0-1, representing 0% to 100%. */
|
|
19
|
+
ratio: number): Promise<unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Get the center of the current element. This is a relatively expensive operation as it uses
|
|
22
|
+
* [`.getBoundingClientRect()`](https://developer.mozilla.org/docs/Web/API/Element/getBoundingClientRect)
|
|
23
|
+
* so this should not be called excessively.
|
|
24
|
+
*
|
|
25
|
+
* @category Web : Elements
|
|
26
|
+
* @category Package : @augment-vir/web
|
|
27
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
28
|
+
*/
|
|
4
29
|
export declare function getCenterOfElement(element: Element): Coords;
|
|
30
|
+
/**
|
|
31
|
+
* Useful for debugging purposes, this sticks an absolutely positioned and brightly colored div at
|
|
32
|
+
* the given position.
|
|
33
|
+
*
|
|
34
|
+
* @category Web : Elements
|
|
35
|
+
* @category Package : @augment-vir/web
|
|
36
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
37
|
+
*/
|
|
5
38
|
export declare function appendPositionDebugDiv(position: Coords): HTMLDivElement;
|
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import { assert } from '@augment-vir/assert';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the current element is completely visible in its scroll view.
|
|
4
|
+
*
|
|
5
|
+
* @category Web : Elements
|
|
6
|
+
* @category Package : @augment-vir/web
|
|
7
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
8
|
+
*/
|
|
2
9
|
export async function checkIfEntirelyInScrollView(element) {
|
|
3
10
|
return checkIfInScrollView(element, 1);
|
|
4
11
|
}
|
|
5
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Check if the given element is visible in its scroll container to the degree of the given ratio.
|
|
14
|
+
*
|
|
15
|
+
* @category Web : Elements
|
|
16
|
+
* @category Package : @augment-vir/web
|
|
17
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
18
|
+
*/
|
|
19
|
+
export async function checkIfInScrollView(element,
|
|
20
|
+
/** A number from 0-1, representing 0% to 100%. */
|
|
21
|
+
ratio) {
|
|
6
22
|
return new Promise((resolve) => {
|
|
7
23
|
const observer = new IntersectionObserver((entries, observerItself) => {
|
|
8
24
|
assert.isLengthAtLeast(entries, 1);
|
|
@@ -12,6 +28,15 @@ export async function checkIfInScrollView(element, ratio) {
|
|
|
12
28
|
observer.observe(element);
|
|
13
29
|
});
|
|
14
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the center of the current element. This is a relatively expensive operation as it uses
|
|
33
|
+
* [`.getBoundingClientRect()`](https://developer.mozilla.org/docs/Web/API/Element/getBoundingClientRect)
|
|
34
|
+
* so this should not be called excessively.
|
|
35
|
+
*
|
|
36
|
+
* @category Web : Elements
|
|
37
|
+
* @category Package : @augment-vir/web
|
|
38
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
39
|
+
*/
|
|
15
40
|
export function getCenterOfElement(element) {
|
|
16
41
|
const rect = element.getBoundingClientRect();
|
|
17
42
|
return {
|
|
@@ -19,6 +44,14 @@ export function getCenterOfElement(element) {
|
|
|
19
44
|
y: Math.floor((rect.bottom + rect.top) / 2),
|
|
20
45
|
};
|
|
21
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Useful for debugging purposes, this sticks an absolutely positioned and brightly colored div at
|
|
49
|
+
* the given position.
|
|
50
|
+
*
|
|
51
|
+
* @category Web : Elements
|
|
52
|
+
* @category Package : @augment-vir/web
|
|
53
|
+
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
|
|
54
|
+
*/
|
|
22
55
|
export function appendPositionDebugDiv(position) {
|
|
23
56
|
const div = document.createElement('div');
|
|
24
57
|
div.classList.add('debug');
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function typeString(
|
|
2
|
-
export declare function typeStringIntoElement(
|
|
1
|
+
export declare function typeString(text: string): Promise<void>;
|
|
2
|
+
export declare function typeStringIntoElement(text: string, inputElement: Readonly<HTMLInputElement>): Promise<void>;
|
|
3
3
|
export declare function deleteAllTextInInput(inputElement: Readonly<HTMLInputElement>): Promise<void>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { sendKeys } from '@web/test-runner-commands';
|
|
2
2
|
import { focusElement } from './element-test-focus.js';
|
|
3
|
-
export async function typeString(
|
|
3
|
+
export async function typeString(text) {
|
|
4
4
|
return await sendKeys({
|
|
5
|
-
type:
|
|
5
|
+
type: text,
|
|
6
6
|
});
|
|
7
7
|
}
|
|
8
|
-
export async function typeStringIntoElement(
|
|
8
|
+
export async function typeStringIntoElement(text, inputElement) {
|
|
9
9
|
await focusElement(inputElement);
|
|
10
|
-
await typeString(
|
|
10
|
+
await typeString(text);
|
|
11
11
|
}
|
|
12
12
|
export async function deleteAllTextInInput(inputElement) {
|
|
13
13
|
const lastValue = inputElement.value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/test",
|
|
3
|
-
"version": "30.0.
|
|
3
|
+
"version": "30.0.2",
|
|
4
|
+
"description": "A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"test",
|
|
7
|
+
"suite",
|
|
8
|
+
"augment",
|
|
9
|
+
"helper",
|
|
10
|
+
"util",
|
|
11
|
+
"node",
|
|
12
|
+
"browser",
|
|
13
|
+
"backend",
|
|
14
|
+
"frontend",
|
|
15
|
+
"vir",
|
|
16
|
+
"augment-vir"
|
|
17
|
+
],
|
|
4
18
|
"homepage": "https://github.com/electrovir/augment-vir",
|
|
5
19
|
"bugs": {
|
|
6
20
|
"url": "https://github.com/electrovir/augment-vir/issues"
|
|
@@ -20,31 +34,29 @@
|
|
|
20
34
|
"types": "dist/index.d.ts",
|
|
21
35
|
"scripts": {
|
|
22
36
|
"compile": "virmator compile",
|
|
23
|
-
"docs": "virmator docs",
|
|
24
37
|
"start": "tsx src/index.ts",
|
|
25
38
|
"test": "concurrently --colors --kill-others-on-fail -c green,blue --names node,web \"npm run test:node\" \"npm run test:web\"",
|
|
26
39
|
"test:coverage": "npm run test",
|
|
27
|
-
"test:docs": "virmator docs check",
|
|
28
40
|
"test:node": "virmator test --no-deps node 'src/augments/universal-testing-suite/**/*.test.ts'",
|
|
29
41
|
"test:update": "npm test",
|
|
30
42
|
"test:web": "virmator test --no-deps web 'src/test-web/**/*.test.ts'"
|
|
31
43
|
},
|
|
32
44
|
"dependencies": {
|
|
33
|
-
"@augment-vir/assert": "^30.0.
|
|
34
|
-
"@augment-vir/common": "^30.0.
|
|
45
|
+
"@augment-vir/assert": "^30.0.2",
|
|
46
|
+
"@augment-vir/common": "^30.0.2",
|
|
35
47
|
"@open-wc/testing-helpers": "^3.0.1",
|
|
36
|
-
"type-fest": "^4.
|
|
48
|
+
"type-fest": "^4.26.1"
|
|
37
49
|
},
|
|
38
50
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^22.5.
|
|
51
|
+
"@types/node": "^22.5.4",
|
|
40
52
|
"@web/dev-server-esbuild": "^1.0.2",
|
|
41
|
-
"@web/test-runner": "^0.
|
|
53
|
+
"@web/test-runner": "^0.19.0",
|
|
42
54
|
"@web/test-runner-commands": "^0.9.0",
|
|
43
55
|
"@web/test-runner-playwright": "^0.11.0",
|
|
44
|
-
"concurrently": "^
|
|
56
|
+
"concurrently": "^9.0.0",
|
|
45
57
|
"element-vir": "^22.2.2",
|
|
46
58
|
"istanbul-smart-text-reporter": "^1.1.4",
|
|
47
|
-
"typescript": "^5.
|
|
59
|
+
"typescript": "^5.6.2"
|
|
48
60
|
},
|
|
49
61
|
"engines": {
|
|
50
62
|
"node": ">=22"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { fixtureCleanup as cleanupFixture, fixture as renderFixture } from '@open-wc/testing-helpers';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { fixtureCleanup as cleanupFixture, fixture as renderFixture } from '@open-wc/testing-helpers';
|