@pezkuwi/dev-test 0.85.3 → 0.85.7
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/LICENSE +201 -0
- package/browser.d.ts +1 -0
- package/browser.js +2 -0
- package/cjs/browser.d.ts +1 -0
- package/cjs/browser.js +4 -0
- package/cjs/env/browser.d.ts +313 -0
- package/cjs/env/browser.js +98 -0
- package/cjs/env/expect.d.ts +297 -0
- package/cjs/env/expect.js +213 -0
- package/cjs/env/index.d.ts +4 -0
- package/cjs/env/index.js +20 -0
- package/cjs/env/jest.d.ts +127 -0
- package/cjs/env/jest.js +56 -0
- package/cjs/env/lifecycle.d.ts +12 -0
- package/cjs/env/lifecycle.js +17 -0
- package/cjs/env/suite.d.ts +20 -0
- package/cjs/env/suite.js +35 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +1 -0
- package/cjs/node.d.ts +1 -0
- package/cjs/node.js +4 -0
- package/cjs/package.json +3 -0
- package/cjs/packageInfo.d.ts +6 -0
- package/cjs/packageInfo.js +4 -0
- package/cjs/types.d.ts +15 -0
- package/cjs/types.js +2 -0
- package/cjs/util.d.ts +20 -0
- package/cjs/util.js +51 -0
- package/env/browser.d.ts +313 -0
- package/env/browser.js +95 -0
- package/env/expect.d.ts +297 -0
- package/env/expect.js +210 -0
- package/env/index.d.ts +4 -0
- package/env/index.js +17 -0
- package/env/jest.d.ts +127 -0
- package/env/jest.js +53 -0
- package/env/lifecycle.d.ts +12 -0
- package/env/lifecycle.js +14 -0
- package/env/suite.d.ts +20 -0
- package/env/suite.js +32 -0
- package/globals.cjs +4 -0
- package/globals.d.ts +30 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/node.d.ts +1 -0
- package/node.js +2 -0
- package/package.json +196 -7
- package/packageInfo.d.ts +6 -0
- package/packageInfo.js +1 -0
- package/types.d.ts +15 -0
- package/types.js +1 -0
- package/util.d.ts +20 -0
- package/util.js +46 -0
- package/.skip-deno +0 -0
- package/tsconfig.build.json +0 -16
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.spec.json +0 -16
- package/tsconfig.spec.tsbuildinfo +0 -1
package/cjs/env/jest.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jest = jest;
|
|
4
|
+
const node_test_1 = require("node:test");
|
|
5
|
+
const util_js_1 = require("../util.js");
|
|
6
|
+
const JEST_KEYS_STUB = ['advanceTimersByTime', 'advanceTimersToNextTimer', 'autoMockOff', 'autoMockOn', 'clearAllMocks', 'clearAllTimers', 'createMockFromModule', 'deepUnmock', 'disableAutomock', 'doMock', 'dontMock', 'enableAutomock', 'fn', 'genMockFromModule', 'getRealSystemTime', 'getSeed', 'getTimerCount', 'isEnvironmentTornDown', 'isMockFunction', 'isolateModules', 'isolateModulesAsync', 'mock', 'mocked', 'now', 'replaceProperty', 'requireActual', 'requireMock', 'resetAllMocks', 'resetModules', 'restoreAllMocks', 'retryTimes', 'runAllImmediates', 'runAllTicks', 'runAllTimers', 'runOnlyPendingTimers', 'setMock', 'setSystemTime', 'setTimeout', 'spyOn', 'unmock', 'unstable_mockModule', 'useFakeTimers', 'useRealTimers'];
|
|
7
|
+
const JEST_KEYS_WARN = ['setTimeout'];
|
|
8
|
+
const MOCK_KEYS_STUB = ['_isMockFunction', 'getMockImplementation', 'getMockName', 'mock', 'mockClear', 'mockImplementation', 'mockImplementationOnce', 'mockName', 'mockRejectedValue', 'mockRejectedValueOnce', 'mockReset', 'mockResolvedValue', 'mockResolvedValueOnce', 'mockRestore', 'mockReturnThis', 'mockReturnValue', 'mockReturnValueOnce', 'withImplementation'];
|
|
9
|
+
const jestStub = (0, util_js_1.stubObj)('jest', JEST_KEYS_STUB);
|
|
10
|
+
const jestWarn = (0, util_js_1.warnObj)('jest', JEST_KEYS_WARN);
|
|
11
|
+
const mockStub = (0, util_js_1.stubObj)('jest.fn()', MOCK_KEYS_STUB);
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*
|
|
15
|
+
* This adds the mockReset and mockRestore functionality to any
|
|
16
|
+
* spy or mock function
|
|
17
|
+
**/
|
|
18
|
+
function extendMock(mocked) {
|
|
19
|
+
// We use the node:test mock here for casting below - however we
|
|
20
|
+
// don't want this in any method signature since this is a private
|
|
21
|
+
// types export, which could get us in "some" trouble
|
|
22
|
+
//
|
|
23
|
+
// Effectively the casts below ensure that our WithMock<*> aligns
|
|
24
|
+
// on a high-level to what we use via private type...
|
|
25
|
+
const spy = mocked;
|
|
26
|
+
return (0, util_js_1.enhanceObj)((0, util_js_1.enhanceObj)(mocked, {
|
|
27
|
+
mockImplementation: (fn) => {
|
|
28
|
+
spy.mock.mockImplementation(fn);
|
|
29
|
+
},
|
|
30
|
+
mockImplementationOnce: (fn) => {
|
|
31
|
+
spy.mock.mockImplementationOnce(fn);
|
|
32
|
+
},
|
|
33
|
+
mockReset: () => {
|
|
34
|
+
spy.mock.resetCalls();
|
|
35
|
+
},
|
|
36
|
+
mockRestore: () => {
|
|
37
|
+
spy.mock.restore();
|
|
38
|
+
}
|
|
39
|
+
}), mockStub);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Sets up the jest object. This is certainly not extensive, and probably
|
|
43
|
+
* not quite meant to be (never say never). Rather this adds the functionality
|
|
44
|
+
* that we use in the pezkuwi-js projects.
|
|
45
|
+
**/
|
|
46
|
+
function jest() {
|
|
47
|
+
return {
|
|
48
|
+
jest: (0, util_js_1.enhanceObj)((0, util_js_1.enhanceObj)({
|
|
49
|
+
fn: (fn) => extendMock(node_test_1.mock.fn(fn)),
|
|
50
|
+
restoreAllMocks: () => {
|
|
51
|
+
node_test_1.mock.reset();
|
|
52
|
+
},
|
|
53
|
+
spyOn: (obj, key) => extendMock(node_test_1.mock.method(obj, key))
|
|
54
|
+
}, jestWarn), jestStub)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { after, afterEach, before, beforeEach } from 'node:test';
|
|
2
|
+
/**
|
|
3
|
+
* This ensures that the before/after functions are exposed
|
|
4
|
+
**/
|
|
5
|
+
export declare function lifecycle(): {
|
|
6
|
+
after: typeof after;
|
|
7
|
+
afterAll: typeof after;
|
|
8
|
+
afterEach: typeof afterEach;
|
|
9
|
+
before: typeof before;
|
|
10
|
+
beforeAll: typeof before;
|
|
11
|
+
beforeEach: typeof beforeEach;
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lifecycle = lifecycle;
|
|
4
|
+
const node_test_1 = require("node:test");
|
|
5
|
+
/**
|
|
6
|
+
* This ensures that the before/after functions are exposed
|
|
7
|
+
**/
|
|
8
|
+
function lifecycle() {
|
|
9
|
+
return {
|
|
10
|
+
after: node_test_1.after,
|
|
11
|
+
afterAll: node_test_1.after,
|
|
12
|
+
afterEach: node_test_1.afterEach,
|
|
13
|
+
before: node_test_1.before,
|
|
14
|
+
beforeAll: node_test_1.before,
|
|
15
|
+
beforeEach: node_test_1.beforeEach
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type TestFn = (name: string, exec: () => void | Promise<void>, timeout?: number) => void;
|
|
2
|
+
export interface Describe extends TestFn {
|
|
3
|
+
only: TestFn;
|
|
4
|
+
skip: TestFn;
|
|
5
|
+
todo: TestFn;
|
|
6
|
+
}
|
|
7
|
+
export interface It extends TestFn {
|
|
8
|
+
only: TestFn;
|
|
9
|
+
skip: TestFn;
|
|
10
|
+
todo: TestFn;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* This ensures that the describe and it functions match our actual usages.
|
|
14
|
+
* This includes .only, .skip and .todo helpers (.each is not applied)
|
|
15
|
+
**/
|
|
16
|
+
export declare function suite(): {
|
|
17
|
+
describe: Describe;
|
|
18
|
+
it: It;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
package/cjs/env/suite.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.suite = suite;
|
|
4
|
+
const node_test_1 = require("node:test");
|
|
5
|
+
const util_js_1 = require("../util.js");
|
|
6
|
+
const MINUTE = 60 * 1000;
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*
|
|
10
|
+
* Wraps either describe or it with relevant .only, .skip, .todo & .each helpers,
|
|
11
|
+
* shimming it into a Jest-compatible environment.
|
|
12
|
+
*
|
|
13
|
+
* @param {} fn
|
|
14
|
+
*/
|
|
15
|
+
function createWrapper(fn, defaultTimeout) {
|
|
16
|
+
const wrap = (opts) => (name, exec, timeout) => fn(name, { ...opts, timeout: (timeout || defaultTimeout) }, exec);
|
|
17
|
+
// Ensure that we have consistent helpers on the function. These are not consistently
|
|
18
|
+
// applied accross all node:test versions, latest has all, so always apply ours.
|
|
19
|
+
// Instead of node:test options for e.g. timeout, we provide a Jest-compatible signature
|
|
20
|
+
return (0, util_js_1.enhanceObj)(wrap({}), {
|
|
21
|
+
only: wrap({ only: true }),
|
|
22
|
+
skip: wrap({ skip: true }),
|
|
23
|
+
todo: wrap({ todo: true })
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* This ensures that the describe and it functions match our actual usages.
|
|
28
|
+
* This includes .only, .skip and .todo helpers (.each is not applied)
|
|
29
|
+
**/
|
|
30
|
+
function suite() {
|
|
31
|
+
return {
|
|
32
|
+
describe: createWrapper(node_test_1.describe, 60 * MINUTE),
|
|
33
|
+
it: createWrapper(node_test_1.it, 2 * MINUTE)
|
|
34
|
+
};
|
|
35
|
+
}
|
package/cjs/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
throw new Error('Use node --require @pezkuwi/dev-test/{node, browser} depending on the required environment');
|
package/cjs/node.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/cjs/node.js
ADDED
package/cjs/package.json
ADDED
package/cjs/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type AnyFn = (...args: any[]) => any;
|
|
2
|
+
export type BaseObj = Record<string, unknown>;
|
|
3
|
+
export type BaseFn = Function;
|
|
4
|
+
export type StubFn = (...args: unknown[]) => unknown;
|
|
5
|
+
export type WithMock<F extends AnyFn> = F & {
|
|
6
|
+
mock: {
|
|
7
|
+
calls: {
|
|
8
|
+
arguments: unknown[];
|
|
9
|
+
}[];
|
|
10
|
+
mockImplementation: (fn: AnyFn) => void;
|
|
11
|
+
mockImplementationOnce: (fn: AnyFn) => void;
|
|
12
|
+
resetCalls: () => void;
|
|
13
|
+
restore: () => void;
|
|
14
|
+
};
|
|
15
|
+
};
|
package/cjs/types.js
ADDED
package/cjs/util.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BaseFn, BaseObj, StubFn } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extends an existing object with the additional function if they
|
|
4
|
+
* are not already existing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function enhanceObj<T extends BaseObj | BaseFn, X>(obj: T, extra: X): T & Omit<X, keyof T>;
|
|
7
|
+
/**
|
|
8
|
+
* Extends a given object with the named functions if they do not
|
|
9
|
+
* already exist on the object.
|
|
10
|
+
*
|
|
11
|
+
* @type {StubObjFn}
|
|
12
|
+
*/
|
|
13
|
+
export declare function stubObj<N extends readonly string[]>(objName: string, keys: N, alts?: Record<string, string>): { [K in N[number]]: StubFn; };
|
|
14
|
+
/**
|
|
15
|
+
* Extends a given object with the named functions if they do not
|
|
16
|
+
* already exist on the object.
|
|
17
|
+
*
|
|
18
|
+
* @type {StubObjFn}
|
|
19
|
+
*/
|
|
20
|
+
export declare function warnObj<N extends readonly string[]>(objName: string, keys: N): { [K in N[number]]: StubFn; };
|
package/cjs/util.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enhanceObj = enhanceObj;
|
|
4
|
+
exports.stubObj = stubObj;
|
|
5
|
+
exports.warnObj = warnObj;
|
|
6
|
+
/**
|
|
7
|
+
* Extends an existing object with the additional function if they
|
|
8
|
+
* are not already existing.
|
|
9
|
+
*/
|
|
10
|
+
function enhanceObj(obj, extra) {
|
|
11
|
+
Object
|
|
12
|
+
.entries(extra)
|
|
13
|
+
.forEach(([key, value]) => {
|
|
14
|
+
obj[key] ??= value;
|
|
15
|
+
});
|
|
16
|
+
return obj;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*
|
|
21
|
+
* A helper to create a stub object based wite the stub creator supplied
|
|
22
|
+
*/
|
|
23
|
+
function createStub(keys, creator) {
|
|
24
|
+
return keys.reduce((obj, key) => {
|
|
25
|
+
obj[key] ??= creator(key);
|
|
26
|
+
return obj;
|
|
27
|
+
}, {});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extends a given object with the named functions if they do not
|
|
31
|
+
* already exist on the object.
|
|
32
|
+
*
|
|
33
|
+
* @type {StubObjFn}
|
|
34
|
+
*/
|
|
35
|
+
function stubObj(objName, keys, alts) {
|
|
36
|
+
return createStub(keys, (key) => () => {
|
|
37
|
+
const alt = alts?.[key];
|
|
38
|
+
throw new Error(`${objName}.${key} has not been implemented${alt ? ` (Use ${alt} instead)` : ''}`);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Extends a given object with the named functions if they do not
|
|
43
|
+
* already exist on the object.
|
|
44
|
+
*
|
|
45
|
+
* @type {StubObjFn}
|
|
46
|
+
*/
|
|
47
|
+
function warnObj(objName, keys) {
|
|
48
|
+
return createStub(keys, (key) => () => {
|
|
49
|
+
console.warn(`${objName}.${key} has been implemented as a noop`);
|
|
50
|
+
});
|
|
51
|
+
}
|
package/env/browser.d.ts
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Export a very basic JSDom environment - this is just enough so we have
|
|
3
|
+
* @testing-environment/react tests passing in this repo
|
|
4
|
+
*
|
|
5
|
+
* FIXME: This approach is actually _explicitly_ discouraged by JSDOM - when
|
|
6
|
+
* using window you should run the tests inside that context, instead of just
|
|
7
|
+
* blindly relying on the globals as we do here
|
|
8
|
+
*/
|
|
9
|
+
export declare function browser(): {
|
|
10
|
+
HTMLAnchorElement: {
|
|
11
|
+
new (): HTMLAnchorElement;
|
|
12
|
+
prototype: HTMLAnchorElement;
|
|
13
|
+
};
|
|
14
|
+
HTMLAreaElement: {
|
|
15
|
+
new (): HTMLAreaElement;
|
|
16
|
+
prototype: HTMLAreaElement;
|
|
17
|
+
};
|
|
18
|
+
HTMLAudioElement: {
|
|
19
|
+
new (): HTMLAudioElement;
|
|
20
|
+
prototype: HTMLAudioElement;
|
|
21
|
+
};
|
|
22
|
+
HTMLBRElement: {
|
|
23
|
+
new (): HTMLBRElement;
|
|
24
|
+
prototype: HTMLBRElement;
|
|
25
|
+
};
|
|
26
|
+
HTMLBaseElement: {
|
|
27
|
+
new (): HTMLBaseElement;
|
|
28
|
+
prototype: HTMLBaseElement;
|
|
29
|
+
};
|
|
30
|
+
HTMLBodyElement: {
|
|
31
|
+
new (): HTMLBodyElement;
|
|
32
|
+
prototype: HTMLBodyElement;
|
|
33
|
+
};
|
|
34
|
+
HTMLButtonElement: {
|
|
35
|
+
new (): HTMLButtonElement;
|
|
36
|
+
prototype: HTMLButtonElement;
|
|
37
|
+
};
|
|
38
|
+
HTMLCanvasElement: {
|
|
39
|
+
new (): HTMLCanvasElement;
|
|
40
|
+
prototype: HTMLCanvasElement;
|
|
41
|
+
};
|
|
42
|
+
HTMLDListElement: {
|
|
43
|
+
new (): HTMLDListElement;
|
|
44
|
+
prototype: HTMLDListElement;
|
|
45
|
+
};
|
|
46
|
+
HTMLDataElement: {
|
|
47
|
+
new (): HTMLDataElement;
|
|
48
|
+
prototype: HTMLDataElement;
|
|
49
|
+
};
|
|
50
|
+
HTMLDataListElement: {
|
|
51
|
+
new (): HTMLDataListElement;
|
|
52
|
+
prototype: HTMLDataListElement;
|
|
53
|
+
};
|
|
54
|
+
HTMLDetailsElement: {
|
|
55
|
+
new (): HTMLDetailsElement;
|
|
56
|
+
prototype: HTMLDetailsElement;
|
|
57
|
+
};
|
|
58
|
+
HTMLDialogElement: {
|
|
59
|
+
new (): HTMLDialogElement;
|
|
60
|
+
readonly prototype: HTMLDialogElement;
|
|
61
|
+
};
|
|
62
|
+
HTMLDirectoryElement: {
|
|
63
|
+
new (): HTMLDirectoryElement;
|
|
64
|
+
prototype: HTMLDirectoryElement;
|
|
65
|
+
};
|
|
66
|
+
HTMLDivElement: {
|
|
67
|
+
new (): HTMLDivElement;
|
|
68
|
+
prototype: HTMLDivElement;
|
|
69
|
+
};
|
|
70
|
+
HTMLElement: {
|
|
71
|
+
new (): HTMLElement;
|
|
72
|
+
prototype: HTMLElement;
|
|
73
|
+
};
|
|
74
|
+
HTMLEmbedElement: {
|
|
75
|
+
new (): HTMLEmbedElement;
|
|
76
|
+
prototype: HTMLEmbedElement;
|
|
77
|
+
};
|
|
78
|
+
HTMLFieldSetElement: {
|
|
79
|
+
new (): HTMLFieldSetElement;
|
|
80
|
+
prototype: HTMLFieldSetElement;
|
|
81
|
+
};
|
|
82
|
+
HTMLFontElement: {
|
|
83
|
+
new (): HTMLFontElement;
|
|
84
|
+
prototype: HTMLFontElement;
|
|
85
|
+
};
|
|
86
|
+
HTMLFormElement: {
|
|
87
|
+
new (): HTMLFormElement;
|
|
88
|
+
prototype: HTMLFormElement;
|
|
89
|
+
};
|
|
90
|
+
HTMLFrameElement: {
|
|
91
|
+
new (): HTMLFrameElement;
|
|
92
|
+
prototype: HTMLFrameElement;
|
|
93
|
+
};
|
|
94
|
+
HTMLFrameSetElement: {
|
|
95
|
+
new (): HTMLFrameSetElement;
|
|
96
|
+
prototype: HTMLFrameSetElement;
|
|
97
|
+
};
|
|
98
|
+
HTMLHRElement: {
|
|
99
|
+
new (): HTMLHRElement;
|
|
100
|
+
prototype: HTMLHRElement;
|
|
101
|
+
};
|
|
102
|
+
HTMLHeadElement: {
|
|
103
|
+
new (): HTMLHeadElement;
|
|
104
|
+
prototype: HTMLHeadElement;
|
|
105
|
+
};
|
|
106
|
+
HTMLHeadingElement: {
|
|
107
|
+
new (): HTMLHeadingElement;
|
|
108
|
+
prototype: HTMLHeadingElement;
|
|
109
|
+
};
|
|
110
|
+
HTMLHtmlElement: {
|
|
111
|
+
new (): HTMLHtmlElement;
|
|
112
|
+
prototype: HTMLHtmlElement;
|
|
113
|
+
};
|
|
114
|
+
HTMLIFrameElement: {
|
|
115
|
+
new (): HTMLIFrameElement;
|
|
116
|
+
prototype: HTMLIFrameElement;
|
|
117
|
+
};
|
|
118
|
+
HTMLImageElement: {
|
|
119
|
+
new (): HTMLImageElement;
|
|
120
|
+
prototype: HTMLImageElement;
|
|
121
|
+
};
|
|
122
|
+
HTMLInputElement: {
|
|
123
|
+
new (): HTMLInputElement;
|
|
124
|
+
prototype: HTMLInputElement;
|
|
125
|
+
};
|
|
126
|
+
HTMLLIElement: {
|
|
127
|
+
new (): HTMLLIElement;
|
|
128
|
+
prototype: HTMLLIElement;
|
|
129
|
+
};
|
|
130
|
+
HTMLLabelElement: {
|
|
131
|
+
new (): HTMLLabelElement;
|
|
132
|
+
prototype: HTMLLabelElement;
|
|
133
|
+
};
|
|
134
|
+
HTMLLegendElement: {
|
|
135
|
+
new (): HTMLLegendElement;
|
|
136
|
+
prototype: HTMLLegendElement;
|
|
137
|
+
};
|
|
138
|
+
HTMLLinkElement: {
|
|
139
|
+
new (): HTMLLinkElement;
|
|
140
|
+
prototype: HTMLLinkElement;
|
|
141
|
+
};
|
|
142
|
+
HTMLMapElement: {
|
|
143
|
+
new (): HTMLMapElement;
|
|
144
|
+
prototype: HTMLMapElement;
|
|
145
|
+
};
|
|
146
|
+
HTMLMarqueeElement: {
|
|
147
|
+
new (): HTMLMarqueeElement;
|
|
148
|
+
prototype: HTMLMarqueeElement;
|
|
149
|
+
};
|
|
150
|
+
HTMLMediaElement: {
|
|
151
|
+
new (): HTMLMediaElement;
|
|
152
|
+
prototype: HTMLMediaElement;
|
|
153
|
+
readonly NETWORK_EMPTY: 0;
|
|
154
|
+
readonly NETWORK_IDLE: 1;
|
|
155
|
+
readonly NETWORK_LOADING: 2;
|
|
156
|
+
readonly NETWORK_NO_SOURCE: 3;
|
|
157
|
+
readonly HAVE_NOTHING: 0;
|
|
158
|
+
readonly HAVE_METADATA: 1;
|
|
159
|
+
readonly HAVE_CURRENT_DATA: 2;
|
|
160
|
+
readonly HAVE_FUTURE_DATA: 3;
|
|
161
|
+
readonly HAVE_ENOUGH_DATA: 4;
|
|
162
|
+
};
|
|
163
|
+
HTMLMenuElement: {
|
|
164
|
+
new (): HTMLMenuElement;
|
|
165
|
+
prototype: HTMLMenuElement;
|
|
166
|
+
};
|
|
167
|
+
HTMLMetaElement: {
|
|
168
|
+
new (): HTMLMetaElement;
|
|
169
|
+
prototype: HTMLMetaElement;
|
|
170
|
+
};
|
|
171
|
+
HTMLMeterElement: {
|
|
172
|
+
new (): HTMLMeterElement;
|
|
173
|
+
prototype: HTMLMeterElement;
|
|
174
|
+
};
|
|
175
|
+
HTMLModElement: {
|
|
176
|
+
new (): HTMLModElement;
|
|
177
|
+
prototype: HTMLModElement;
|
|
178
|
+
};
|
|
179
|
+
HTMLOListElement: {
|
|
180
|
+
new (): HTMLOListElement;
|
|
181
|
+
prototype: HTMLOListElement;
|
|
182
|
+
};
|
|
183
|
+
HTMLObjectElement: {
|
|
184
|
+
new (): HTMLObjectElement;
|
|
185
|
+
prototype: HTMLObjectElement;
|
|
186
|
+
};
|
|
187
|
+
HTMLOptGroupElement: {
|
|
188
|
+
new (): HTMLOptGroupElement;
|
|
189
|
+
prototype: HTMLOptGroupElement;
|
|
190
|
+
};
|
|
191
|
+
HTMLOptionElement: {
|
|
192
|
+
new (): HTMLOptionElement;
|
|
193
|
+
prototype: HTMLOptionElement;
|
|
194
|
+
};
|
|
195
|
+
HTMLOutputElement: {
|
|
196
|
+
new (): HTMLOutputElement;
|
|
197
|
+
prototype: HTMLOutputElement;
|
|
198
|
+
};
|
|
199
|
+
HTMLParagraphElement: {
|
|
200
|
+
new (): HTMLParagraphElement;
|
|
201
|
+
prototype: HTMLParagraphElement;
|
|
202
|
+
};
|
|
203
|
+
HTMLParamElement: {
|
|
204
|
+
new (): HTMLParamElement;
|
|
205
|
+
prototype: HTMLParamElement;
|
|
206
|
+
};
|
|
207
|
+
HTMLPictureElement: {
|
|
208
|
+
new (): HTMLPictureElement;
|
|
209
|
+
prototype: HTMLPictureElement;
|
|
210
|
+
};
|
|
211
|
+
HTMLPreElement: {
|
|
212
|
+
new (): HTMLPreElement;
|
|
213
|
+
prototype: HTMLPreElement;
|
|
214
|
+
};
|
|
215
|
+
HTMLProgressElement: {
|
|
216
|
+
new (): HTMLProgressElement;
|
|
217
|
+
prototype: HTMLProgressElement;
|
|
218
|
+
};
|
|
219
|
+
HTMLQuoteElement: {
|
|
220
|
+
new (): HTMLQuoteElement;
|
|
221
|
+
prototype: HTMLQuoteElement;
|
|
222
|
+
};
|
|
223
|
+
HTMLScriptElement: {
|
|
224
|
+
new (): HTMLScriptElement;
|
|
225
|
+
prototype: HTMLScriptElement;
|
|
226
|
+
supports(type: string): boolean;
|
|
227
|
+
};
|
|
228
|
+
HTMLSelectElement: {
|
|
229
|
+
new (): HTMLSelectElement;
|
|
230
|
+
prototype: HTMLSelectElement;
|
|
231
|
+
};
|
|
232
|
+
HTMLSlotElement: {
|
|
233
|
+
new (): HTMLSlotElement;
|
|
234
|
+
prototype: HTMLSlotElement;
|
|
235
|
+
};
|
|
236
|
+
HTMLSourceElement: {
|
|
237
|
+
new (): HTMLSourceElement;
|
|
238
|
+
prototype: HTMLSourceElement;
|
|
239
|
+
};
|
|
240
|
+
HTMLSpanElement: {
|
|
241
|
+
new (): HTMLSpanElement;
|
|
242
|
+
prototype: HTMLSpanElement;
|
|
243
|
+
};
|
|
244
|
+
HTMLStyleElement: {
|
|
245
|
+
new (): HTMLStyleElement;
|
|
246
|
+
prototype: HTMLStyleElement;
|
|
247
|
+
};
|
|
248
|
+
HTMLTableCaptionElement: {
|
|
249
|
+
new (): HTMLTableCaptionElement;
|
|
250
|
+
prototype: HTMLTableCaptionElement;
|
|
251
|
+
};
|
|
252
|
+
HTMLTableCellElement: {
|
|
253
|
+
new (): HTMLTableCellElement;
|
|
254
|
+
prototype: HTMLTableCellElement;
|
|
255
|
+
};
|
|
256
|
+
HTMLTableColElement: {
|
|
257
|
+
new (): HTMLTableColElement;
|
|
258
|
+
prototype: HTMLTableColElement;
|
|
259
|
+
};
|
|
260
|
+
HTMLTableElement: {
|
|
261
|
+
new (): HTMLTableElement;
|
|
262
|
+
prototype: HTMLTableElement;
|
|
263
|
+
};
|
|
264
|
+
HTMLTableRowElement: {
|
|
265
|
+
new (): HTMLTableRowElement;
|
|
266
|
+
prototype: HTMLTableRowElement;
|
|
267
|
+
};
|
|
268
|
+
HTMLTableSectionElement: {
|
|
269
|
+
new (): HTMLTableSectionElement;
|
|
270
|
+
prototype: HTMLTableSectionElement;
|
|
271
|
+
};
|
|
272
|
+
HTMLTemplateElement: {
|
|
273
|
+
new (): HTMLTemplateElement;
|
|
274
|
+
prototype: HTMLTemplateElement;
|
|
275
|
+
};
|
|
276
|
+
HTMLTextAreaElement: {
|
|
277
|
+
new (): HTMLTextAreaElement;
|
|
278
|
+
prototype: HTMLTextAreaElement;
|
|
279
|
+
};
|
|
280
|
+
HTMLTimeElement: {
|
|
281
|
+
new (): HTMLTimeElement;
|
|
282
|
+
prototype: HTMLTimeElement;
|
|
283
|
+
};
|
|
284
|
+
HTMLTitleElement: {
|
|
285
|
+
new (): HTMLTitleElement;
|
|
286
|
+
prototype: HTMLTitleElement;
|
|
287
|
+
};
|
|
288
|
+
HTMLTrackElement: {
|
|
289
|
+
new (): HTMLTrackElement;
|
|
290
|
+
prototype: HTMLTrackElement;
|
|
291
|
+
readonly NONE: 0;
|
|
292
|
+
readonly LOADING: 1;
|
|
293
|
+
readonly LOADED: 2;
|
|
294
|
+
readonly ERROR: 3;
|
|
295
|
+
};
|
|
296
|
+
HTMLUListElement: {
|
|
297
|
+
new (): HTMLUListElement;
|
|
298
|
+
prototype: HTMLUListElement;
|
|
299
|
+
};
|
|
300
|
+
HTMLUnknownElement: {
|
|
301
|
+
new (): HTMLUnknownElement;
|
|
302
|
+
prototype: HTMLUnknownElement;
|
|
303
|
+
};
|
|
304
|
+
HTMLVideoElement: {
|
|
305
|
+
new (): HTMLVideoElement;
|
|
306
|
+
prototype: HTMLVideoElement;
|
|
307
|
+
};
|
|
308
|
+
crypto: Crypto;
|
|
309
|
+
document: Document;
|
|
310
|
+
localStorage: Storage;
|
|
311
|
+
navigator: Navigator;
|
|
312
|
+
window: import("jsdom").DOMWindow;
|
|
313
|
+
};
|
package/env/browser.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { JSDOM } from 'jsdom';
|
|
2
|
+
/**
|
|
3
|
+
* Export a very basic JSDom environment - this is just enough so we have
|
|
4
|
+
* @testing-environment/react tests passing in this repo
|
|
5
|
+
*
|
|
6
|
+
* FIXME: This approach is actually _explicitly_ discouraged by JSDOM - when
|
|
7
|
+
* using window you should run the tests inside that context, instead of just
|
|
8
|
+
* blindly relying on the globals as we do here
|
|
9
|
+
*/
|
|
10
|
+
export function browser() {
|
|
11
|
+
const { window } = new JSDOM('', { url: 'http://localhost' });
|
|
12
|
+
return {
|
|
13
|
+
// All HTML Elements that are defined on the JSDOM window object.
|
|
14
|
+
// (we copied as-is from the types definition). We cannot get this
|
|
15
|
+
// via Object.keys(window).filter(...) so we have to specify explicitly
|
|
16
|
+
HTMLAnchorElement: window.HTMLAnchorElement,
|
|
17
|
+
HTMLAreaElement: window.HTMLAreaElement,
|
|
18
|
+
HTMLAudioElement: window.HTMLAudioElement,
|
|
19
|
+
HTMLBRElement: window.HTMLBRElement,
|
|
20
|
+
HTMLBaseElement: window.HTMLBaseElement,
|
|
21
|
+
HTMLBodyElement: window.HTMLBodyElement,
|
|
22
|
+
HTMLButtonElement: window.HTMLButtonElement,
|
|
23
|
+
HTMLCanvasElement: window.HTMLCanvasElement,
|
|
24
|
+
HTMLDListElement: window.HTMLDListElement,
|
|
25
|
+
HTMLDataElement: window.HTMLDataElement,
|
|
26
|
+
HTMLDataListElement: window.HTMLDataListElement,
|
|
27
|
+
HTMLDetailsElement: window.HTMLDetailsElement,
|
|
28
|
+
HTMLDialogElement: window.HTMLDialogElement,
|
|
29
|
+
HTMLDirectoryElement: window.HTMLDirectoryElement,
|
|
30
|
+
HTMLDivElement: window.HTMLDivElement,
|
|
31
|
+
HTMLElement: window.HTMLElement,
|
|
32
|
+
HTMLEmbedElement: window.HTMLEmbedElement,
|
|
33
|
+
HTMLFieldSetElement: window.HTMLFieldSetElement,
|
|
34
|
+
HTMLFontElement: window.HTMLFontElement,
|
|
35
|
+
HTMLFormElement: window.HTMLFormElement,
|
|
36
|
+
HTMLFrameElement: window.HTMLFrameElement,
|
|
37
|
+
HTMLFrameSetElement: window.HTMLFrameSetElement,
|
|
38
|
+
HTMLHRElement: window.HTMLHRElement,
|
|
39
|
+
HTMLHeadElement: window.HTMLHeadElement,
|
|
40
|
+
HTMLHeadingElement: window.HTMLHeadingElement,
|
|
41
|
+
HTMLHtmlElement: window.HTMLHtmlElement,
|
|
42
|
+
HTMLIFrameElement: window.HTMLIFrameElement,
|
|
43
|
+
HTMLImageElement: window.HTMLImageElement,
|
|
44
|
+
HTMLInputElement: window.HTMLInputElement,
|
|
45
|
+
HTMLLIElement: window.HTMLLIElement,
|
|
46
|
+
HTMLLabelElement: window.HTMLLabelElement,
|
|
47
|
+
HTMLLegendElement: window.HTMLLegendElement,
|
|
48
|
+
HTMLLinkElement: window.HTMLLinkElement,
|
|
49
|
+
HTMLMapElement: window.HTMLMapElement,
|
|
50
|
+
HTMLMarqueeElement: window.HTMLMarqueeElement,
|
|
51
|
+
HTMLMediaElement: window.HTMLMediaElement,
|
|
52
|
+
HTMLMenuElement: window.HTMLMenuElement,
|
|
53
|
+
HTMLMetaElement: window.HTMLMetaElement,
|
|
54
|
+
HTMLMeterElement: window.HTMLMeterElement,
|
|
55
|
+
HTMLModElement: window.HTMLModElement,
|
|
56
|
+
HTMLOListElement: window.HTMLOListElement,
|
|
57
|
+
HTMLObjectElement: window.HTMLObjectElement,
|
|
58
|
+
HTMLOptGroupElement: window.HTMLOptGroupElement,
|
|
59
|
+
HTMLOptionElement: window.HTMLOptionElement,
|
|
60
|
+
HTMLOutputElement: window.HTMLOutputElement,
|
|
61
|
+
HTMLParagraphElement: window.HTMLParagraphElement,
|
|
62
|
+
HTMLParamElement: window.HTMLParamElement,
|
|
63
|
+
HTMLPictureElement: window.HTMLPictureElement,
|
|
64
|
+
HTMLPreElement: window.HTMLPreElement,
|
|
65
|
+
HTMLProgressElement: window.HTMLProgressElement,
|
|
66
|
+
HTMLQuoteElement: window.HTMLQuoteElement,
|
|
67
|
+
HTMLScriptElement: window.HTMLScriptElement,
|
|
68
|
+
HTMLSelectElement: window.HTMLSelectElement,
|
|
69
|
+
HTMLSlotElement: window.HTMLSlotElement,
|
|
70
|
+
HTMLSourceElement: window.HTMLSourceElement,
|
|
71
|
+
HTMLSpanElement: window.HTMLSpanElement,
|
|
72
|
+
HTMLStyleElement: window.HTMLStyleElement,
|
|
73
|
+
HTMLTableCaptionElement: window.HTMLTableCaptionElement,
|
|
74
|
+
HTMLTableCellElement: window.HTMLTableCellElement,
|
|
75
|
+
HTMLTableColElement: window.HTMLTableColElement,
|
|
76
|
+
HTMLTableElement: window.HTMLTableElement,
|
|
77
|
+
HTMLTableRowElement: window.HTMLTableRowElement,
|
|
78
|
+
HTMLTableSectionElement: window.HTMLTableSectionElement,
|
|
79
|
+
HTMLTemplateElement: window.HTMLTemplateElement,
|
|
80
|
+
HTMLTextAreaElement: window.HTMLTextAreaElement,
|
|
81
|
+
HTMLTimeElement: window.HTMLTimeElement,
|
|
82
|
+
HTMLTitleElement: window.HTMLTitleElement,
|
|
83
|
+
HTMLTrackElement: window.HTMLTrackElement,
|
|
84
|
+
HTMLUListElement: window.HTMLUListElement,
|
|
85
|
+
HTMLUnknownElement: window.HTMLUnknownElement,
|
|
86
|
+
HTMLVideoElement: window.HTMLVideoElement,
|
|
87
|
+
// normal service resumes, the base top-level names
|
|
88
|
+
crypto: window.crypto,
|
|
89
|
+
document: window.document,
|
|
90
|
+
localStorage: window.localStorage,
|
|
91
|
+
navigator: window.navigator,
|
|
92
|
+
// window...
|
|
93
|
+
window
|
|
94
|
+
};
|
|
95
|
+
}
|