@prosopo/procaptcha-frictionless 2.17.0 → 2.18.1
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/.turbo/turbo-build$colon$cjs.log +8 -8
- package/.turbo/turbo-build$colon$tsc.log +25 -25
- package/.turbo/turbo-build.log +15 -15
- package/CHANGELOG.md +66 -0
- package/dist/{AuthenticatedBadge.d.ts → authenticatedBadge.d.ts} +3 -3
- package/dist/authenticatedBadge.d.ts.map +1 -0
- package/dist/authenticatedBadge.js +79 -0
- package/dist/authenticatedBadge.js.map +1 -0
- package/dist/cjs/authenticatedBadge.cjs +79 -0
- package/dist/cjs/detectorPrefetch.cjs +2 -2
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/procaptchaFrictionless.cjs +269 -0
- package/dist/detectorPrefetch.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/procaptchaFrictionless.d.ts +6 -0
- package/dist/procaptchaFrictionless.d.ts.map +1 -0
- package/dist/procaptchaFrictionless.js +269 -0
- package/dist/procaptchaFrictionless.js.map +1 -0
- package/dist/tests/escalationClientSession.test.d.ts +0 -3
- package/dist/tests/escalationClientSession.test.d.ts.map +1 -1
- package/dist/tests/escalationClientSession.test.js +52 -61
- package/dist/tests/escalationClientSession.test.js.map +1 -1
- package/dist/tests/escalationHandoff.integration.test.d.ts +0 -3
- package/dist/tests/escalationHandoff.integration.test.d.ts.map +1 -1
- package/dist/tests/escalationHandoff.integration.test.js +62 -61
- package/dist/tests/escalationHandoff.integration.test.js.map +1 -1
- package/dist/tests/executeBeforeMount.test.d.ts +0 -3
- package/dist/tests/executeBeforeMount.test.d.ts.map +1 -1
- package/dist/tests/executeBeforeMount.test.js +53 -49
- package/dist/tests/executeBeforeMount.test.js.map +1 -1
- package/dist/tests/manualStart.test.d.ts +0 -3
- package/dist/tests/manualStart.test.d.ts.map +1 -1
- package/dist/tests/manualStart.test.js +55 -52
- package/dist/tests/manualStart.test.js.map +1 -1
- package/dist/tests/procaptchaFrictionless.test.d.ts +2 -0
- package/dist/tests/procaptchaFrictionless.test.d.ts.map +1 -0
- package/dist/tests/procaptchaFrictionless.test.js +244 -0
- package/dist/tests/procaptchaFrictionless.test.js.map +1 -0
- package/dist/tests/sessionInvalidatedRemint.test.d.ts +0 -3
- package/dist/tests/sessionInvalidatedRemint.test.d.ts.map +1 -1
- package/dist/tests/sessionInvalidatedRemint.test.js +49 -43
- package/dist/tests/sessionInvalidatedRemint.test.js.map +1 -1
- package/package.json +12 -14
- package/src/authenticatedBadge.ts +151 -0
- package/src/customDetectBot.ts +2 -2
- package/src/detectorPrefetch.ts +2 -2
- package/src/index.ts +1 -1
- package/src/{ProcaptchaFrictionless.tsx → procaptchaFrictionless.ts} +285 -314
- package/src/tests/{escalationClientSession.test.tsx → escalationClientSession.test.ts} +83 -92
- package/src/tests/{escalationHandoff.integration.test.tsx → escalationHandoff.integration.test.ts} +110 -108
- package/src/tests/{executeBeforeMount.test.tsx → executeBeforeMount.test.ts} +79 -77
- package/src/tests/{manualStart.test.tsx → manualStart.test.ts} +87 -83
- package/src/tests/procaptchaFrictionless.test.ts +408 -0
- package/src/tests/{sessionInvalidatedRemint.test.tsx → sessionInvalidatedRemint.test.ts} +67 -64
- package/tsconfig.cjs.json +1 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/AuthenticatedBadge.d.ts.map +0 -1
- package/dist/AuthenticatedBadge.js +0 -75
- package/dist/AuthenticatedBadge.js.map +0 -1
- package/dist/ProcaptchaFrictionless.d.ts +0 -3
- package/dist/ProcaptchaFrictionless.d.ts.map +0 -1
- package/dist/ProcaptchaFrictionless.js +0 -287
- package/dist/ProcaptchaFrictionless.js.map +0 -1
- package/dist/cjs/AuthenticatedBadge.cjs +0 -75
- package/dist/cjs/ProcaptchaFrictionless.cjs +0 -287
- package/src/AuthenticatedBadge.tsx +0 -141
|
@@ -19,69 +19,73 @@ import {
|
|
|
19
19
|
type BotDetectionFunctionResult,
|
|
20
20
|
CaptchaType,
|
|
21
21
|
ModeEnum,
|
|
22
|
-
type
|
|
22
|
+
type ProcaptchaClientConfigOutput,
|
|
23
23
|
type ProcaptchaProps,
|
|
24
24
|
type RandomProvider,
|
|
25
25
|
StartModeEnum,
|
|
26
26
|
} from "@prosopo/types";
|
|
27
|
-
import { type ReactElement, act, createElement, useEffect } from "react";
|
|
28
|
-
import { type Root, createRoot } from "react-dom/client";
|
|
29
27
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
30
28
|
|
|
31
|
-
declare global {
|
|
32
|
-
var IS_REACT_ACT_ENVIRONMENT: boolean;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
36
|
-
|
|
37
29
|
const EXECUTE_EVENT = "procaptcha:execute";
|
|
38
30
|
|
|
39
|
-
const mocks = vi.hoisted(() =>
|
|
40
|
-
executes:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
const onContainer = () => mocks.executes.push("container");
|
|
50
|
-
const onDocument = () => mocks.executes.push("document");
|
|
31
|
+
const mocks = vi.hoisted(() => {
|
|
32
|
+
const executes: ("container" | "document")[] = [];
|
|
33
|
+
// Listens the way the real inner widgets do: on the container in either
|
|
34
|
+
// mode, and on document only when invisible.
|
|
35
|
+
const listeningWidget = (host: HTMLElement, props: ProcaptchaProps) => {
|
|
36
|
+
const { container } = props;
|
|
37
|
+
const invisible = "invisible" === props.config.mode;
|
|
38
|
+
const onContainer = () => executes.push("container");
|
|
39
|
+
const onDocument = () => executes.push("document");
|
|
51
40
|
container?.addEventListener(EXECUTE_EVENT, onContainer);
|
|
52
41
|
if (invisible) document.addEventListener(EXECUTE_EVENT, onDocument);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
const element = host.ownerDocument.createElement("div");
|
|
43
|
+
element.setAttribute("data-widget", "image");
|
|
44
|
+
host.appendChild(element);
|
|
45
|
+
return {
|
|
46
|
+
destroy: () => {
|
|
47
|
+
container?.removeEventListener(EXECUTE_EVENT, onContainer);
|
|
48
|
+
if (invisible) document.removeEventListener(EXECUTE_EVENT, onDocument);
|
|
49
|
+
element.remove();
|
|
50
|
+
},
|
|
56
51
|
};
|
|
57
|
-
}
|
|
58
|
-
return
|
|
59
|
-
};
|
|
52
|
+
};
|
|
53
|
+
return { executes, listeningWidget };
|
|
54
|
+
});
|
|
60
55
|
|
|
61
|
-
vi.mock("@prosopo/procaptcha-react", () => ({
|
|
62
|
-
|
|
56
|
+
vi.mock("@prosopo/procaptcha-react", () => ({
|
|
57
|
+
mountProcaptchaImageWidget: mocks.listeningWidget,
|
|
58
|
+
}));
|
|
59
|
+
vi.mock("@prosopo/procaptcha-pow", () => ({
|
|
60
|
+
mountProcaptchaPowWidget: mocks.listeningWidget,
|
|
61
|
+
}));
|
|
63
62
|
vi.mock("@prosopo/procaptcha-puzzle", () => ({
|
|
64
|
-
|
|
63
|
+
mountProcaptchaPuzzleWidget: mocks.listeningWidget,
|
|
65
64
|
}));
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
// jsdom serves the suite over http, so the widget's own HTTPS guard would
|
|
67
|
+
// short-circuit every test before detection ran.
|
|
68
|
+
vi.mock("@prosopo/procaptcha-common", async (importOriginal) => ({
|
|
69
|
+
...(await importOriginal<typeof import("@prosopo/procaptcha-common")>()),
|
|
70
|
+
isSecureBrowserContext: () => true,
|
|
71
|
+
}));
|
|
72
72
|
|
|
73
|
-
const {
|
|
73
|
+
const { mountProcaptchaFrictionless } = await import(
|
|
74
|
+
"../procaptchaFrictionless.js"
|
|
75
|
+
);
|
|
74
76
|
|
|
75
77
|
const config = (
|
|
76
|
-
overrides: Partial<
|
|
77
|
-
):
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
overrides: Partial<ProcaptchaClientConfigOutput> = {},
|
|
79
|
+
): ProcaptchaClientConfigOutput =>
|
|
80
|
+
({
|
|
81
|
+
account: { address: "5siteKey" },
|
|
82
|
+
userAccountAddress: "",
|
|
83
|
+
web2: true,
|
|
84
|
+
theme: "light",
|
|
85
|
+
mode: ModeEnum.invisible,
|
|
86
|
+
startMode: StartModeEnum.auto,
|
|
87
|
+
...overrides,
|
|
88
|
+
}) as unknown as ProcaptchaClientConfigOutput;
|
|
85
89
|
|
|
86
90
|
const i18nStub = {
|
|
87
91
|
isInitialized: true,
|
|
@@ -90,13 +94,19 @@ const i18nStub = {
|
|
|
90
94
|
changeLanguage: vi.fn(),
|
|
91
95
|
} as unknown as Ti18n;
|
|
92
96
|
|
|
93
|
-
const detectionResult = (): BotDetectionFunctionResult =>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
97
|
+
const detectionResult = (): BotDetectionFunctionResult =>
|
|
98
|
+
({
|
|
99
|
+
status: "ok",
|
|
100
|
+
captchaType: CaptchaType.image,
|
|
101
|
+
sessionId: "provider-session",
|
|
102
|
+
provider: { provider: { url: "https://provider.test" } } as RandomProvider,
|
|
103
|
+
userAccount: { account: { address: "5FakeUserAccountAddress" } } as Account,
|
|
104
|
+
}) as unknown as BotDetectionFunctionResult;
|
|
105
|
+
|
|
106
|
+
const settle = async (): Promise<void> => {
|
|
107
|
+
await new Promise<void>((resolve: () => void) => setTimeout(resolve, 0));
|
|
108
|
+
await Promise.resolve();
|
|
109
|
+
};
|
|
100
110
|
|
|
101
111
|
interface HeldDetection {
|
|
102
112
|
detectBot: ReturnType<typeof vi.fn<BotDetectionFunction>>;
|
|
@@ -112,55 +122,47 @@ const heldDetection = (): HeldDetection => {
|
|
|
112
122
|
}),
|
|
113
123
|
);
|
|
114
124
|
const finish = async () => {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
});
|
|
125
|
+
resolve?.(detectionResult());
|
|
126
|
+
await settle();
|
|
118
127
|
};
|
|
119
128
|
return { detectBot, finish };
|
|
120
129
|
};
|
|
121
130
|
|
|
122
131
|
let host: HTMLDivElement;
|
|
123
132
|
let container: HTMLDivElement;
|
|
124
|
-
let
|
|
133
|
+
let widget: { destroy: () => void } | undefined;
|
|
125
134
|
|
|
126
135
|
const mountWrapper = async (
|
|
127
136
|
detectBot: BotDetectionFunction,
|
|
128
|
-
overrides: Partial<
|
|
137
|
+
overrides: Partial<ProcaptchaClientConfigOutput> = {},
|
|
129
138
|
): Promise<void> => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
detectBot,
|
|
138
|
-
container,
|
|
139
|
-
}) as ReactElement,
|
|
140
|
-
);
|
|
139
|
+
widget = mountProcaptchaFrictionless(host, {
|
|
140
|
+
config: config(overrides),
|
|
141
|
+
callbacks: {},
|
|
142
|
+
restart: vi.fn(),
|
|
143
|
+
i18n: i18nStub,
|
|
144
|
+
detectBot,
|
|
145
|
+
container,
|
|
141
146
|
});
|
|
147
|
+
await settle();
|
|
142
148
|
};
|
|
143
149
|
|
|
144
150
|
const dispatch = async (target: EventTarget): Promise<void> => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
});
|
|
151
|
+
target.dispatchEvent(new CustomEvent(EXECUTE_EVENT));
|
|
152
|
+
await settle();
|
|
148
153
|
};
|
|
149
154
|
|
|
150
155
|
beforeEach(() => {
|
|
151
156
|
mocks.executes.length = 0;
|
|
157
|
+
widget = undefined;
|
|
152
158
|
host = document.createElement("div");
|
|
153
159
|
container = document.createElement("div");
|
|
154
160
|
document.body.append(host, container);
|
|
155
|
-
act(() => {
|
|
156
|
-
root = createRoot(host);
|
|
157
|
-
});
|
|
158
161
|
});
|
|
159
162
|
|
|
160
163
|
afterEach(() => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
});
|
|
164
|
+
widget?.destroy();
|
|
165
|
+
widget = undefined;
|
|
164
166
|
host.remove();
|
|
165
167
|
container.remove();
|
|
166
168
|
vi.clearAllMocks();
|
|
@@ -20,63 +20,70 @@ import {
|
|
|
20
20
|
CaptchaType,
|
|
21
21
|
ModeEnum,
|
|
22
22
|
PROCAPTCHA_START_EVENT,
|
|
23
|
-
type
|
|
23
|
+
type ProcaptchaClientConfigOutput,
|
|
24
|
+
type ProcaptchaFrictionlessProps,
|
|
24
25
|
type ProcaptchaProps,
|
|
25
26
|
type ProcaptchaStartEventDetail,
|
|
26
27
|
type RandomProvider,
|
|
27
28
|
StartModeEnum,
|
|
28
29
|
} from "@prosopo/types";
|
|
29
|
-
import { type ReactElement, act, createElement } from "react";
|
|
30
|
-
import { type Root, createRoot } from "react-dom/client";
|
|
31
30
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
32
31
|
|
|
33
|
-
declare global {
|
|
34
|
-
var IS_REACT_ACT_ENVIRONMENT: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
38
|
-
|
|
39
32
|
type InnerWidget = "pow" | "image" | "puzzle";
|
|
40
33
|
|
|
41
|
-
const mocks = vi.hoisted(() =>
|
|
42
|
-
mounts:
|
|
34
|
+
const mocks = vi.hoisted(() => {
|
|
35
|
+
const mounts: {
|
|
43
36
|
widget: "pow" | "image" | "puzzle";
|
|
44
37
|
props: ProcaptchaProps;
|
|
45
|
-
}[]
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
}[] = [];
|
|
39
|
+
const stub =
|
|
40
|
+
(widget: "pow" | "image" | "puzzle") =>
|
|
41
|
+
(container: HTMLElement, props: ProcaptchaProps) => {
|
|
42
|
+
mounts.push({ widget, props });
|
|
43
|
+
const element = container.ownerDocument.createElement("div");
|
|
44
|
+
element.setAttribute("data-widget", widget);
|
|
45
|
+
container.appendChild(element);
|
|
46
|
+
return { destroy: () => element.remove() };
|
|
47
|
+
};
|
|
48
|
+
return { mounts, stub };
|
|
49
|
+
});
|
|
52
50
|
|
|
53
|
-
vi.mock("@prosopo/procaptcha-pow", () => ({
|
|
54
|
-
|
|
51
|
+
vi.mock("@prosopo/procaptcha-pow", () => ({
|
|
52
|
+
mountProcaptchaPowWidget: mocks.stub("pow"),
|
|
53
|
+
}));
|
|
54
|
+
vi.mock("@prosopo/procaptcha-react", () => ({
|
|
55
|
+
mountProcaptchaImageWidget: mocks.stub("image"),
|
|
56
|
+
}));
|
|
55
57
|
vi.mock("@prosopo/procaptcha-puzzle", () => ({
|
|
56
|
-
|
|
58
|
+
mountProcaptchaPuzzleWidget: mocks.stub("puzzle"),
|
|
57
59
|
}));
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
// jsdom serves the suite over http, so the widget's own HTTPS guard would
|
|
62
|
+
// short-circuit every test before detection ran.
|
|
63
|
+
vi.mock("@prosopo/procaptcha-common", async (importOriginal) => ({
|
|
64
|
+
...(await importOriginal<typeof import("@prosopo/procaptcha-common")>()),
|
|
65
|
+
isSecureBrowserContext: () => true,
|
|
66
|
+
}));
|
|
64
67
|
|
|
65
|
-
const {
|
|
68
|
+
const { mountProcaptchaFrictionless } = await import(
|
|
69
|
+
"../procaptchaFrictionless.js"
|
|
70
|
+
);
|
|
66
71
|
|
|
67
72
|
const SITE_KEY = "5siteKey";
|
|
68
73
|
const SESSION_ID = "provider-session";
|
|
69
74
|
|
|
70
75
|
const config = (
|
|
71
|
-
overrides: Partial<
|
|
72
|
-
):
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
overrides: Partial<ProcaptchaClientConfigOutput> = {},
|
|
77
|
+
): ProcaptchaClientConfigOutput =>
|
|
78
|
+
({
|
|
79
|
+
account: { address: SITE_KEY },
|
|
80
|
+
userAccountAddress: "",
|
|
81
|
+
web2: true,
|
|
82
|
+
theme: "light",
|
|
83
|
+
mode: ModeEnum.visible,
|
|
84
|
+
startMode: StartModeEnum.manual,
|
|
85
|
+
...overrides,
|
|
86
|
+
}) as unknown as ProcaptchaClientConfigOutput;
|
|
80
87
|
|
|
81
88
|
const i18nStub = {
|
|
82
89
|
isInitialized: true,
|
|
@@ -85,22 +92,28 @@ const i18nStub = {
|
|
|
85
92
|
changeLanguage: vi.fn(),
|
|
86
93
|
} as unknown as Ti18n;
|
|
87
94
|
|
|
88
|
-
const detectionResult = (): BotDetectionFunctionResult =>
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
+
const detectionResult = (): BotDetectionFunctionResult =>
|
|
96
|
+
({
|
|
97
|
+
status: "ok",
|
|
98
|
+
captchaType: CaptchaType.image,
|
|
99
|
+
sessionId: SESSION_ID,
|
|
100
|
+
provider: { provider: { url: "https://provider.test" } } as RandomProvider,
|
|
101
|
+
userAccount: { account: { address: "5FakeUserAccountAddress" } } as Account,
|
|
102
|
+
}) as unknown as BotDetectionFunctionResult;
|
|
95
103
|
|
|
96
104
|
const detectBotResolving = () =>
|
|
97
105
|
vi.fn<BotDetectionFunction>().mockResolvedValue(detectionResult());
|
|
98
106
|
|
|
99
107
|
let host: HTMLDivElement;
|
|
100
|
-
let
|
|
108
|
+
let widget: { destroy: () => void } | undefined;
|
|
109
|
+
|
|
110
|
+
const settle = async (): Promise<void> => {
|
|
111
|
+
await new Promise<void>((resolve: () => void) => setTimeout(resolve, 0));
|
|
112
|
+
await Promise.resolve();
|
|
113
|
+
};
|
|
101
114
|
|
|
102
115
|
interface MountOptions {
|
|
103
|
-
config?:
|
|
116
|
+
config?: ProcaptchaClientConfigOutput;
|
|
104
117
|
detectBot?: ReturnType<typeof detectBotResolving>;
|
|
105
118
|
container?: HTMLElement;
|
|
106
119
|
}
|
|
@@ -109,18 +122,16 @@ const mountWrapper = async (
|
|
|
109
122
|
options: MountOptions = {},
|
|
110
123
|
): Promise<ReturnType<typeof detectBotResolving>> => {
|
|
111
124
|
const detectBot = options.detectBot ?? detectBotResolving();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
);
|
|
123
|
-
});
|
|
125
|
+
const props: ProcaptchaFrictionlessProps = {
|
|
126
|
+
config: options.config ?? config(),
|
|
127
|
+
callbacks: {},
|
|
128
|
+
restart: vi.fn(),
|
|
129
|
+
i18n: i18nStub,
|
|
130
|
+
detectBot,
|
|
131
|
+
container: options.container,
|
|
132
|
+
};
|
|
133
|
+
widget = mountProcaptchaFrictionless(host, props);
|
|
134
|
+
await settle();
|
|
124
135
|
return detectBot;
|
|
125
136
|
};
|
|
126
137
|
|
|
@@ -134,9 +145,9 @@ const checkbox = (): HTMLInputElement => {
|
|
|
134
145
|
|
|
135
146
|
const spinner = (): Element | null => host.querySelector('[role="status"]');
|
|
136
147
|
|
|
137
|
-
const lastMountOf = (
|
|
138
|
-
const mount = mocks.mounts.filter((m) => m.widget ===
|
|
139
|
-
if (!mount) throw new Error(`expected the ${
|
|
148
|
+
const lastMountOf = (target: InnerWidget) => {
|
|
149
|
+
const mount = mocks.mounts.filter((m) => m.widget === target).at(-1);
|
|
150
|
+
if (!mount) throw new Error(`expected the ${target} widget to have mounted`);
|
|
140
151
|
return mount;
|
|
141
152
|
};
|
|
142
153
|
|
|
@@ -174,43 +185,37 @@ const click = async (
|
|
|
174
185
|
clientY: options.clientY ?? 0,
|
|
175
186
|
});
|
|
176
187
|
setTrusted(event, options.trusted ?? true);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
188
|
+
element.dispatchEvent(event);
|
|
189
|
+
await settle();
|
|
180
190
|
};
|
|
181
191
|
|
|
182
192
|
const dispatchStart = async (
|
|
183
193
|
detail?: ProcaptchaStartEventDetail,
|
|
184
194
|
): Promise<void> => {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
});
|
|
195
|
+
document.dispatchEvent(
|
|
196
|
+
new CustomEvent<ProcaptchaStartEventDetail>(PROCAPTCHA_START_EVENT, {
|
|
197
|
+
detail,
|
|
198
|
+
bubbles: true,
|
|
199
|
+
}),
|
|
200
|
+
);
|
|
201
|
+
await settle();
|
|
193
202
|
};
|
|
194
203
|
|
|
195
204
|
const dispatchExecute = async (): Promise<void> => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
});
|
|
205
|
+
document.dispatchEvent(new CustomEvent("procaptcha:execute"));
|
|
206
|
+
await settle();
|
|
199
207
|
};
|
|
200
208
|
|
|
201
209
|
beforeEach(() => {
|
|
202
210
|
mocks.mounts.length = 0;
|
|
211
|
+
widget = undefined;
|
|
203
212
|
host = document.createElement("div");
|
|
204
213
|
document.body.appendChild(host);
|
|
205
|
-
act(() => {
|
|
206
|
-
root = createRoot(host);
|
|
207
|
-
});
|
|
208
214
|
});
|
|
209
215
|
|
|
210
216
|
afterEach(() => {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
});
|
|
217
|
+
widget?.destroy();
|
|
218
|
+
widget = undefined;
|
|
214
219
|
host.remove();
|
|
215
220
|
vi.clearAllMocks();
|
|
216
221
|
});
|
|
@@ -357,9 +362,8 @@ describe("manual start mode", () => {
|
|
|
357
362
|
expect(spinner()).not.toBeNull();
|
|
358
363
|
expect(mocks.mounts).toHaveLength(0);
|
|
359
364
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
});
|
|
365
|
+
finish?.(detectionResult());
|
|
366
|
+
await settle();
|
|
363
367
|
|
|
364
368
|
expect(spinner()).toBeNull();
|
|
365
369
|
expect(lastMountOf("image").props.autoStart).toBe(true);
|