Files
next.js/test/unit/eslint-plugin-next/google-font-preconnect.test.ts
Jiwon ChoiandGitHub e1b8c00d0f [eslint-plugin] Remove eslint-v8 testing (#84721)
ESLint plugin defaults to flat config, and we also dropped the built-in
lint check at https://github.com/vercel/next.js/pull/83136, so we can
sunset the deprecated ESLint v8 testing.
2025-10-10 22:50:42 +02:00

74 lines
1.6 KiB
TypeScript

import { RuleTester } from 'eslint'
import { rules } from '@next/eslint-plugin-next'
const NextESLintRule = rules['google-font-preconnect']
const tests = {
valid: [
`export const Test = () => (
<div>
<link rel="preconnect" href="https://fonts.gstatic.com"/>
<link
href={process.env.NEXT_PUBLIC_CANONICAL_URL}
rel="canonical"
/>
<link
href={new URL("../public/favicon.ico", import.meta.url).toString()}
rel="icon"
/>
</div>
)
`,
],
invalid: [
{
code: `
export const Test = () => (
<div>
<link href="https://fonts.gstatic.com"/>
</div>
)
`,
errors: [
{
message:
'`rel="preconnect"` is missing from Google Font. See: https://nextjs.org/docs/messages/google-font-preconnect',
type: 'JSXOpeningElement',
},
],
},
{
code: `
export const Test = () => (
<div>
<link rel="preload" href="https://fonts.gstatic.com"/>
</div>
)
`,
errors: [
{
message:
'`rel="preconnect"` is missing from Google Font. See: https://nextjs.org/docs/messages/google-font-preconnect',
type: 'JSXOpeningElement',
},
],
},
],
}
describe('google-font-preconnect', () => {
new RuleTester({
languageOptions: {
ecmaVersion: 2020,
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
modules: true,
jsx: true,
},
},
},
}).run('eslint', NextESLintRule, tests)
})