Skip to content

Commit

Permalink
Patch promise constructor fix (#25)
Browse files Browse the repository at this point in the history
* Patch `Promise.constructor` differently

* Patch `Promise.constructor` differently

* Add changelog entry, extend comment
  • Loading branch information
gzuidhof authored Dec 10, 2024
1 parent 94bffa1 commit f2ea673
Show file tree
Hide file tree
Showing 7 changed files with 3,105 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# changelog

## 0.1.12

* Change how we patch Promise to avoid issues with libraries that extend/overwrite it (Angular with zones in particular).

## 0.1.11

* Fix wrapping of Promise constructor, which lead to issues in Chrome <= 45 (released September 2015) and Firefox <= 40.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@friendlycaptcha/sdk",
"version": "0.1.11",
"version": "0.1.12",
"description": "In-browser SDK for Friendly Captcha v2 (currently in preview only)",
"main": "dist/sdk.js",
"type": "module",
Expand Down
13 changes: 13 additions & 0 deletions sdktest/test/zone/body.tmpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<main>
<form>
<p>A Friendly Captcha widget on the same page as Zone.js (used in Angular).</p>

<input type="textarea"/>
<div class="frc-captcha" data-sitekey="{{ .Config.Sitekey }}"></div>
<input type="submit"/>
</form>
</main>

<script defer src="{{ .SiteJSPath }}"></script>
<script defer src="main.tmpl.ts"></script>

37 changes: 37 additions & 0 deletions sdktest/test/zone/main.tmpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*!
* Copyright (c) Friendly Captcha GmbH 2023.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { sdktest } from "../../sdktestlib/sdk.js";

import "./zone.umd.js"

sdktest.description("Together with zone.js");

sdktest.test({ name: "one widget present" }, async (t) => {
t.require.numberOfWidgets(1);
});

sdktest.test({ name: "promises resolve" }, async (t) => {

const p = new Promise((resolve) => {
setTimeout(() => {
resolve("OK");
}, 10);
})

const result = await p;

t.assert.equal(result, "OK");

let didResolve = false;

await Promise.resolve("abc").then((result) => {
t.assert.equal(result, "abc");
didResolve = true;
});

t.assert.truthy(didResolve);
});
Loading

0 comments on commit f2ea673

Please sign in to comment.