Skip to content

Commit

Permalink
feat: support custom prop (#92)
Browse files Browse the repository at this point in the history
Co-authored-by: Brad Peters <[email protected]>
  • Loading branch information
DSergiu and brdlyptrs authored Jul 29, 2023
1 parent 676b1c0 commit 411f1c9
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
cache: 'yarn'

- name: Install Lerna
run: yarn global add lerna@6

- run: yarn setup
- run: yarn lint --stream
- run: yarn build --stream
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.13
16.14
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 1.3.0

- Feat: support `custom` prop

# 1.2.1

- Fix: Missing `index.d.ts` for `@hcaptcha/vue3-hcaptcha`
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ The component will automatically load the hCaptcha API library and append it to
| `challengeContainer` | String | No | `-` | A custom element ID to render the hCaptcha challenge. |
| `rqdata` | String | No | - | See Enterprise docs. |
| `sentry` | Boolean | No | - | See Enterprise docs. |
| `custom` | Boolean | No | - | See Enterprise docs. |
| `apiEndpoint` | String | No | - | See Enterprise docs. |
| `endpoint` | String | No | - | See Enterprise docs. |
| `reportapi` | String | No | - | See Enterprise docs. |
Expand Down
2 changes: 1 addition & 1 deletion packages/vue2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hcaptcha/vue-hcaptcha",
"version": "1.2.1",
"version": "1.3.0",
"types": "types/index.d.ts",
"main": "./dist/@hcaptcha/vue-hcaptcha.umd.min.js",
"module": "./dist/@hcaptcha/vue-hcaptcha.common.js",
Expand Down
5 changes: 3 additions & 2 deletions packages/vue2/src/__tests__/hcaptcha-script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config = {
language: 'ro',
reCaptchaCompat: true,
sentry: true,
custom: true,
apiEndpoint: 'https://hcaptcha.com/1/api.js',
endpoint: 'https://endpoint',
reportapi: 'https://reportapi',
Expand Down Expand Up @@ -52,14 +53,14 @@ describe('hcaptcha-script', () => {

test('script src with custom endpoint', () => {
expect(getScriptSrc(config))
.toBe('https://hcaptcha.com/1/api.js?render=explicit&onload=_hcaptchaOnLoad&hl=ro&sentry=true&endpoint=https%3A%2F%2Fendpoint&assethost=https%3A%2F%2Fassethost&imghost=https%3A%2F%2Fimghost&reportapi=https%3A%2F%2Freportapi');
.toBe('https://hcaptcha.com/1/api.js?render=explicit&onload=_hcaptchaOnLoad&hl=ro&sentry=true&custom=true&endpoint=https%3A%2F%2Fendpoint&assethost=https%3A%2F%2Fassethost&imghost=https%3A%2F%2Fimghost&reportapi=https%3A%2F%2Freportapi');
});

test('script src with reCaptchaCompat off', () => {
const cfg = Object.assign({}, config);
cfg.reCaptchaCompat = false;
expect(getScriptSrc(cfg))
.toBe('https://hcaptcha.com/1/api.js?render=explicit&onload=_hcaptchaOnLoad&recaptchacompat=off&hl=ro&sentry=true&endpoint=https%3A%2F%2Fendpoint&assethost=https%3A%2F%2Fassethost&imghost=https%3A%2F%2Fimghost&reportapi=https%3A%2F%2Freportapi');
.toBe('https://hcaptcha.com/1/api.js?render=explicit&onload=_hcaptchaOnLoad&recaptchacompat=off&hl=ro&sentry=true&custom=true&endpoint=https%3A%2F%2Fendpoint&assethost=https%3A%2F%2Fassethost&imghost=https%3A%2F%2Fimghost&reportapi=https%3A%2F%2Freportapi');

});

Expand Down
1 change: 1 addition & 0 deletions packages/vue2/src/hcaptcha-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export function getScriptSrc(config) {
scriptSrc = addQueryParamIfDefined(scriptSrc, 'recaptchacompat', config.reCaptchaCompat === false ? 'off' : null);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'hl', config.language);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'sentry', config.sentry);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'custom', config.custom);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'endpoint', config.endpoint);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'assethost', config.assethost);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'imghost', config.imghost);
Expand Down
4 changes: 4 additions & 0 deletions packages/vue2/src/hcaptcha.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export default {
type: Boolean,
default: true
},
custom: {
type: Boolean,
default: undefined
},
apiEndpoint: {
type: String,
default: 'https://hcaptcha.com/1/api.js'
Expand Down
1 change: 1 addition & 0 deletions packages/vue2/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare class VueHcaptcha extends Vue {
challengeContainer?: string;
rqdata?: string;
sentry?: boolean;
custom?: boolean;
endpoint?: string;
reportapi?: string;
assethost?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hcaptcha/vue3-hcaptcha",
"version": "1.2.1",
"version": "1.3.0",
"author": "hCaptcha team and contributors",
"homepage": "https://github.com/hCaptcha/vue-hcaptcha",
"organization": "hCaptcha",
Expand Down
15 changes: 12 additions & 3 deletions packages/vue3/test/e2e/hcaptcha.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ async function waitForFrame(ownerFrame, name, hcaptchaId) {
{ state: "attached" }
);
const frame = await elem.contentFrame();
await frame.waitForLoadState();
await frame.waitForLoadState("networkidle");

return { elem, frame };
}

Expand All @@ -72,10 +73,14 @@ describe("hCaptcha vue3", () => {

beforeEach(async () => {
page = await browser.newPage({ bypassCSP: true });

setupPage(page);

await page.setViewportSize({ width: 1280, height: 720 });
await page.route(/https:\/\/hcaptcha\.local/, route => route.fulfill({ body: HTML }));
await page.goto("https://hcaptcha.local");

await page.waitForLoadState("networkidle");
});

afterEach(async () => {
Expand All @@ -85,18 +90,22 @@ describe("hCaptcha vue3", () => {
it("should render anchor", async () => {
const { frame } = await waitForFrame(page, "checkbox");
const anchor = await frame.$("#anchor");

expect(await anchor.screenshot()).toMatchImageSnapshot({ failureThreshold: 0.01 });
});

it("should get token", async () => {
const onVerifyMock = jest.fn();
await page.exposeBinding("onVerify", onVerifyMock);
const getRequestPromise = page.waitForRequest("**/getcaptcha?*");

const { frame } = await waitForFrame(page, "checkbox");
const anchor = await frame.$("#anchor");

await anchor.click();
await getRequestPromise;
await page.waitForRequest("**/getcaptcha?*");

await frame.waitForSelector(".check");

expect(onVerifyMock).toHaveBeenCalledTimes(1);
expect(onVerifyMock).toHaveBeenCalledWith(expect.anything(), { token: "10000000-aaaa-bbbb-cccc-000000000001", eKey: "" });
expect(await anchor.screenshot()).toMatchImageSnapshot({ failureThreshold: 0.01 });
Expand Down

0 comments on commit 411f1c9

Please sign in to comment.