@augment-vir/test 31.54.1 → 31.54.3
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RuntimeEnvError } from '@augment-vir/core';
|
|
2
|
-
|
|
2
|
+
export { type ElementCasesOptions, type ElementTestCase, type ElementTestCaseExpect, } from '../test-web/element-cases.js';
|
|
3
3
|
declare function importWebTestApi(this: void): Promise<RuntimeEnvError | {
|
|
4
4
|
/**
|
|
5
5
|
* Cleans up all rendered test HTML by removing the actual wrapper nodes. Common use case is
|
|
@@ -46,7 +46,7 @@ declare function importWebTestApi(this: void): Promise<RuntimeEnvError | {
|
|
|
46
46
|
*/
|
|
47
47
|
typeText: typeof import("../test-web/type-into-element").typeString;
|
|
48
48
|
/** Create multiple test cases for element testing. */
|
|
49
|
-
elementCases: typeof elementCases;
|
|
49
|
+
elementCases: typeof import("../test-web/element-cases.js").elementCases;
|
|
50
50
|
}>;
|
|
51
51
|
/**
|
|
52
52
|
* A suite of web test helpers. This is only accessible within a browser runtime. If accessed
|
|
@@ -57,4 +57,3 @@ declare function importWebTestApi(this: void): Promise<RuntimeEnvError | {
|
|
|
57
57
|
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
58
58
|
*/
|
|
59
59
|
export declare const testWeb: Exclude<Awaited<ReturnType<typeof importWebTestApi>>, Error>;
|
|
60
|
-
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isRuntimeEnv, RuntimeEnv, RuntimeEnvError } from '@augment-vir/core';
|
|
2
|
-
import { elementCases } from '../test-web/element-cases.js';
|
|
3
2
|
async function importWebTestApi() {
|
|
4
3
|
if (!isRuntimeEnv(RuntimeEnv.Web)) {
|
|
5
4
|
return new RuntimeEnvError("The 'testWeb' api cannot be used outside of a browser context.");
|
|
@@ -9,6 +8,7 @@ async function importWebTestApi() {
|
|
|
9
8
|
const { deleteAllTextInInput, typeString, typeStringIntoElement } = await import('../test-web/type-into-element');
|
|
10
9
|
const { fixtureCleanup, fixture } = await import('@open-wc/testing-helpers');
|
|
11
10
|
const { renderElement } = await import('../test-web/render-element');
|
|
11
|
+
const { elementCases } = await import('../test-web/element-cases.js');
|
|
12
12
|
return {
|
|
13
13
|
/**
|
|
14
14
|
* Cleans up all rendered test HTML by removing the actual wrapper nodes. Common use case is
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
|
|
2
|
+
import { type AnyDuration } from '@date-vir/duration';
|
|
2
3
|
import { type DeclarativeElementDefinition, type DefinedTypedEvent, type TypedEvent } from 'element-vir';
|
|
3
4
|
import { type EmptyObject, type IsAny } from 'type-fest';
|
|
4
5
|
import { type UniversalTestContext } from '../augments/universal-testing-suite/universal-test-context.js';
|
|
6
|
+
/**
|
|
7
|
+
* Expectations for `testWeb.elementCases`.
|
|
8
|
+
*
|
|
9
|
+
* @category Test : Util
|
|
10
|
+
* @category Package : @augment-vir/test
|
|
11
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
12
|
+
*/
|
|
5
13
|
export type ElementTestCaseExpect = {
|
|
6
14
|
text: string | string[];
|
|
7
15
|
events: Map<TypedEvent | DefinedTypedEvent<any, any>, unknown[]>;
|
|
8
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Individual test case for `testWeb.elementCases`.
|
|
19
|
+
*
|
|
20
|
+
* @category Test : Util
|
|
21
|
+
* @category Package : @augment-vir/test
|
|
22
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
23
|
+
*/
|
|
9
24
|
export type ElementTestCase<Definition extends Readonly<DeclarativeElementDefinition>> = {
|
|
10
25
|
it: string;
|
|
11
26
|
} & (IsAny<Definition> extends true ? {
|
|
@@ -20,4 +35,19 @@ export type ElementTestCase<Definition extends Readonly<DeclarativeElementDefini
|
|
|
20
35
|
only: boolean;
|
|
21
36
|
skip: boolean;
|
|
22
37
|
}>;
|
|
23
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Options for `testWeb.elementCases`.
|
|
40
|
+
*
|
|
41
|
+
* @category Test : Util
|
|
42
|
+
* @category Package : @augment-vir/test
|
|
43
|
+
* @package [`@augment-vir/test`](https://www.npmjs.com/package/@augment-vir/test)
|
|
44
|
+
*/
|
|
45
|
+
export type ElementCasesOptions = {
|
|
46
|
+
/**
|
|
47
|
+
* The timeout for checking an element case's expectations.
|
|
48
|
+
*
|
|
49
|
+
* @default {seconds: 10}
|
|
50
|
+
*/
|
|
51
|
+
timeout: AnyDuration;
|
|
52
|
+
};
|
|
53
|
+
export declare function elementCases<const Definition extends Readonly<DeclarativeElementDefinition>>(elementDefinition: Readonly<Definition>, testCases: ReadonlyArray<Readonly<ElementTestCase<Definition>>>, options?: Readonly<PartialWithUndefined<ElementCasesOptions>>): void;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { assert, waitUntil } from '@augment-vir/assert';
|
|
2
|
-
import { ensureArray } from '@augment-vir/common';
|
|
1
|
+
import { assert, check, waitUntil } from '@augment-vir/assert';
|
|
3
2
|
import { itCasesWithContext, } from '../augments/universal-testing-suite/it-cases-with-context.js';
|
|
4
3
|
import { renderElement } from './render-element.js';
|
|
5
4
|
import { extractElementText } from './symlinked/element-text.js';
|
|
6
|
-
export function elementCases(elementDefinition, testCases) {
|
|
5
|
+
export function elementCases(elementDefinition, testCases, options = {}) {
|
|
7
6
|
itCasesWithContext(testRenderElement, () => {
|
|
8
7
|
/** All assertions are done in the test callback. */
|
|
9
8
|
}, testCases.map((testCase) => {
|
|
@@ -12,12 +11,13 @@ export function elementCases(elementDefinition, testCases) {
|
|
|
12
11
|
inputs: [
|
|
13
12
|
elementDefinition,
|
|
14
13
|
testCase,
|
|
14
|
+
options,
|
|
15
15
|
],
|
|
16
16
|
throws: undefined,
|
|
17
17
|
};
|
|
18
18
|
}));
|
|
19
19
|
}
|
|
20
|
-
async function testRenderElement(testContext, elementDefinition, testCase) {
|
|
20
|
+
async function testRenderElement(testContext, elementDefinition, testCase, options) {
|
|
21
21
|
const eventKeys = Array.from(testCase.expect?.events?.keys() || []);
|
|
22
22
|
const events = new Map(eventKeys.map((key) => {
|
|
23
23
|
return [
|
|
@@ -35,8 +35,10 @@ async function testRenderElement(testContext, elementDefinition, testCase) {
|
|
|
35
35
|
await testCase.act?.(instance);
|
|
36
36
|
await waitUntil.isTrue(() => {
|
|
37
37
|
const text = extractElementText(instance);
|
|
38
|
-
if (testCase.expect?.text) {
|
|
39
|
-
assert.hasValues(text,
|
|
38
|
+
if (check.isArray(testCase.expect?.text)) {
|
|
39
|
+
assert.hasValues(text, testCase.expect.text);
|
|
40
|
+
}
|
|
41
|
+
else if (check.isString(testCase.expect?.text)) {
|
|
40
42
|
assert.hasValue(text, testCase.expect.text);
|
|
41
43
|
}
|
|
42
44
|
if (testCase.expect?.events) {
|
|
@@ -51,8 +53,8 @@ async function testRenderElement(testContext, elementDefinition, testCase) {
|
|
|
51
53
|
interval: {
|
|
52
54
|
milliseconds: 100,
|
|
53
55
|
},
|
|
54
|
-
timeout: {
|
|
55
|
-
|
|
56
|
+
timeout: options.timeout || {
|
|
57
|
+
seconds: 10,
|
|
56
58
|
},
|
|
57
59
|
});
|
|
58
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/test",
|
|
3
|
-
"version": "31.54.
|
|
3
|
+
"version": "31.54.3",
|
|
4
4
|
"description": "A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"test",
|
|
@@ -44,8 +44,9 @@
|
|
|
44
44
|
"test:web": "virmator test --no-deps web 'src/test-web/**/*.test.ts' 'src/augments/universal-testing-suite/**/*.test.ts'"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@augment-vir/assert": "^31.54.
|
|
48
|
-
"@augment-vir/common": "^31.54.
|
|
47
|
+
"@augment-vir/assert": "^31.54.3",
|
|
48
|
+
"@augment-vir/common": "^31.54.3",
|
|
49
|
+
"@date-vir/duration": "^8.0.0",
|
|
49
50
|
"@open-wc/testing-helpers": "^3.0.1",
|
|
50
51
|
"@virmator/test": "^14.3.0",
|
|
51
52
|
"type-fest": "^5.2.0"
|