import { RuleTester as ESLintTesterV8 } from 'eslint-v8' import { RuleTester as ESLintTesterV9 } from 'eslint' import { rules } from '@next/eslint-plugin-next' const NextESLintRule = rules['google-font-display'] const tests = { valid: [ `import Head from "next/head"; export default Test = () => { return (
); }; `, `import Document, { Html, Head } from "next/document"; class MyDocument extends Document { render() { return ( ); } } export default MyDocument; `, `import Document, { Html, Head } from "next/document"; class MyDocument extends Document { render() { return ( ); } } export default MyDocument; `, ], invalid: [ { code: `import Head from "next/head"; export default Test = () => { return ( ); }; `, errors: [ { message: 'A font-display parameter is missing (adding `&display=optional` is recommended). See: https://nextjs.org/docs/messages/google-font-display', type: 'JSXOpeningElement', }, ], }, { code: `import Head from "next/head"; export default Test = () => { return ( ); }; `, errors: [ { message: 'Block is not recommended. See: https://nextjs.org/docs/messages/google-font-display', type: 'JSXOpeningElement', }, ], }, { code: `import Head from "next/head"; export default Test = () => { return ( ); }; `, errors: [ { message: 'Auto is not recommended. See: https://nextjs.org/docs/messages/google-font-display', type: 'JSXOpeningElement', }, ], }, { code: `import Head from "next/head"; export default Test = () => { return ( ); }; `, errors: [ { message: 'Fallback is not recommended. See: https://nextjs.org/docs/messages/google-font-display', type: 'JSXOpeningElement', }, ], }, ], } describe('google-font-display', () => { new ESLintTesterV8({ parserOptions: { ecmaVersion: 2020, sourceType: 'module', ecmaFeatures: { modules: true, jsx: true, }, }, }).run('eslint-v8', NextESLintRule, tests) new ESLintTesterV9({ languageOptions: { ecmaVersion: 2020, sourceType: 'module', parserOptions: { ecmaFeatures: { modules: true, jsx: true, }, }, }, }).run('eslint-v9', NextESLintRule, tests) })