This commit is contained in:
Daniel Regeci
2024-02-22 19:01:55 +01:00
parent f8e15857ce
commit 37cffa5d72
10 changed files with 1959 additions and 691 deletions

4
.gitignore vendored
View File

@@ -24,3 +24,7 @@ dist-ssr
# app
.TODO
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/

2
dist/altcha.iife.js vendored

File diff suppressed because one or more lines are too long

694
dist/altcha.js vendored

File diff suppressed because it is too large Load Diff

2
dist/altcha.umd.cjs vendored

File diff suppressed because one or more lines are too long

26
e2e/altcha.spec.ts Normal file
View File

@@ -0,0 +1,26 @@
import { test, expect } from '@playwright/test';
test('should be rendered', async ({ page }) => {
await page.goto('./e2e/index.html');
const cmp = page.locator('#test-render .altcha').first();
await expect(cmp).toContainText(/Protected by/);
});
test('should be with a custom label', async ({ page }) => {
await page.goto('./e2e/index.html');
const cmp = page.locator('#test-label .altcha').first();
await expect(cmp).toContainText(/custom label/);
});
test('should be without the logo', async ({ page }) => {
await page.goto('./e2e/index.html');
expect(await page.locator('#test-hidelogo .altcha-logo').first().count()).toBe(0);
});
test('should be without the footer', async ({ page }) => {
await page.goto('./e2e/index.html');
expect(await page.locator('#test-hidefooter .altcha-footer').first().count()).toBe(0);
});

38
e2e/index.html Normal file
View File

@@ -0,0 +1,38 @@
<html>
<head>
<script async defer src="./dist/altcha.js" type="module"></script>
</head>
<body>
<main>
<div id="test-render">
<altcha-widget
challengeurl=""
></altcha-widget>
</div>
<div id="test-label">
<altcha-widget
challengeurl=""
strings="{&quot;label&quot;:&quot;custom label&quot;}"
></altcha-widget>
</div>
<div id="test-hidelogo">
<altcha-widget
challengeurl=""
hidelogo
></altcha-widget>
</div>
<div id="test-hidefooter">
<altcha-widget
challengeurl=""
hidefooter
></altcha-widget>
</div>
</main>
</body>
</html>

1787
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "altcha",
"version": "0.1.6",
"version": "0.1.7",
"license": "MIT",
"author": {
"name": "Daniel Regeci"
@@ -39,19 +39,23 @@
"build": "rimraf dist && vite build && echo \"declare module 'altcha';\" > dist/altcha.d.ts",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json",
"test": "vitest"
"test": "vitest",
"test:e2e": "playwright test"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.4.2",
"@playwright/test": "^1.41.2",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@tsconfig/svelte": "^5.0.0",
"@types/node": "^20.11.19",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"svelte": "^4.0.5",
"sass": "^1.71.1",
"svelte": "^4.2.11",
"svelte-check": "^3.4.6",
"tslib": "^2.6.0",
"typescript": "^5.0.2",
"vite": "^4.4.5",
"vite": "^5.1.4",
"vitest": "^0.34.6"
}
}

77
playwright.config.ts Normal file
View File

@@ -0,0 +1,77 @@
import { defineConfig, devices } from '@playwright/test';
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './e2e',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'line',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://127.0.0.1:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },
/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],
/* Run your local dev server before starting the tests */
webServer: {
command: 'npx serve . -l 3000',
url: 'http://127.0.0.1:3000/',
reuseExistingServer: !process.env.CI,
},
});

View File

@@ -315,12 +315,12 @@
<style global>
.altcha {
background: var(--altcha-color-base, transparent);
border: 1px solid var(--altcha-color-border, #a0a0a0);
border-radius: 3px;
border: var(--altcha-border-width, 3px) solid var(--altcha-color-border, #a0a0a0);
border-radius: var(--altcha-border-radius, 3px);
color: var(--altcha-color-text, currentColor);
display: flex;
flex-direction: column;
max-width: 260px;
max-width: var(--altcha-max-width, 260px);
overflow: hidden;
position: relative;
text-align: left;