Lint: fix all ESLint errors (391 -> 0), lint and typecheck tests
Mostly perfectionist import/key sorting and curly braces from --fix, plus: - spread instead of .apply() in the Meta Pixel stub - non-capturing group in the locale-code pattern - React 19 use(Context) / <Context value> in TurnstileProvider - email regex rewritten without super-linear backtracking (covered by a test) - console.warn/error allowed (deliberate server diagnostics) - test/tsconfig.json so the project service and tsc see test files Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+18
-4
@@ -1,17 +1,20 @@
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
import type { I18nConfig } from '../src/modules/i18n/types.js'
|
||||
|
||||
import { isHoneypotTripped } from '../src/modules/forms/honeypot.js'
|
||||
import { isEmail } from '../src/modules/forms/validators.js'
|
||||
import { buildLocalizedPath, switchLocalePath } from '../src/modules/i18n/localizedPath.js'
|
||||
import { matchAcceptLanguage, negotiateLocale } from '../src/modules/i18n/negotiateLocale.js'
|
||||
import { isHoneypotTripped } from '../src/modules/forms/honeypot.js'
|
||||
|
||||
const config = {
|
||||
const config: I18nConfig = {
|
||||
defaultLocale: 'pl',
|
||||
locales: [
|
||||
{ code: 'pl', label: 'Polski' },
|
||||
{ code: 'en', label: 'English' },
|
||||
],
|
||||
}
|
||||
const single = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] }
|
||||
const single: I18nConfig = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] }
|
||||
|
||||
describe('negotiateLocale', () => {
|
||||
test('cookie → Accept-Language → default', () => {
|
||||
@@ -58,7 +61,7 @@ describe('buildLocalizedPath', () => {
|
||||
|
||||
describe('switchLocalePath', () => {
|
||||
test('never dead-ends: falls back to archive, then locale root', () => {
|
||||
expect(switchLocalePath({ config, slugs: { pl: 'post' }, targetLocale: 'en', prefix: { en: 'articles', pl: 'artykuly' } })).toBe(
|
||||
expect(switchLocalePath({ config, prefix: { en: 'articles', pl: 'artykuly' }, slugs: { pl: 'post' }, targetLocale: 'en' })).toBe(
|
||||
'/en/articles',
|
||||
)
|
||||
expect(switchLocalePath({ config, slugs: { pl: 'o-nas' }, targetLocale: 'en' })).toBe('/en')
|
||||
@@ -72,3 +75,14 @@ describe('honeypot', () => {
|
||||
expect(isHoneypotTripped({})).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isEmail', () => {
|
||||
test('accepts real addresses, rejects malformed ones', () => {
|
||||
for (const ok of ['[email protected]', '[email protected]', '[email protected]']) {
|
||||
expect(isEmail(ok)).toBe(true)
|
||||
}
|
||||
for (const bad of ['', 'a', 'a@b', 'a [email protected]', 'a@b c.pl', '@b.pl', '[email protected]', 'a@@b.pl']) {
|
||||
expect(isEmail(bad)).toBe(false)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
+3
-1
@@ -2,9 +2,11 @@ import type { Config } from 'payload'
|
||||
|
||||
import { describe, expect, test, vi } from 'vitest'
|
||||
|
||||
import type { I18nConfig } from '../src/modules/i18n/types.js'
|
||||
|
||||
import { ipalKit } from '../src/plugin.js'
|
||||
|
||||
const i18n = {
|
||||
const i18n: I18nConfig = {
|
||||
defaultLocale: 'pl',
|
||||
locales: [
|
||||
{ code: 'pl', label: 'Polski' },
|
||||
|
||||
@@ -14,7 +14,7 @@ const forms = {
|
||||
],
|
||||
},
|
||||
}
|
||||
const data = { consent: true, name: 'Ala' }
|
||||
const data = { name: 'Ala', consent: true }
|
||||
const keys = { turnstileSecretKey: 'secret', turnstileSiteKey: 'site' }
|
||||
|
||||
let ipCounter = 0
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"composite": false,
|
||||
"incremental": false,
|
||||
"noEmit": true,
|
||||
"emitDeclarationOnly": false,
|
||||
"rootDir": ".."
|
||||
},
|
||||
"include": ["./**/*.ts", "../src/**/*.ts", "../src/**/*.tsx"]
|
||||
}
|
||||
Reference in New Issue
Block a user