import { RuleTester as ESLintTesterV8 } from 'eslint-v8' import { RuleTester as ESLintTesterV9 } from 'eslint' import { rules } from '@next/eslint-plugin-next' const NextESLintRule = rules['no-unwanted-polyfillio'] const tests = { valid: [ `import {Head} from 'next/document'; export class Blah extends Head { render() { return (

Hello title

); } }`, `import {Head} from 'next/document'; export class Blah extends Head { render() { return (

Hello title

); } }`, `import Script from 'next/script'; export function MyApp({ Component, pageProps }) { return (
); } }`, errors: [ { message: 'No duplicate polyfills from Polyfill.io are allowed. WeakSet, Promise, Promise.prototype.finally, es2015, es5, es6 are already shipped with Next.js. See: https://nextjs.org/docs/messages/no-unwanted-polyfillio', type: 'JSXOpeningElement', }, ], }, { code: ` export class Blah { render() { return (

Hello title

); } }`, errors: [ { message: 'No duplicate polyfills from Polyfill.io are allowed. Array.prototype.copyWithin is already shipped with Next.js. See: https://nextjs.org/docs/messages/no-unwanted-polyfillio', type: 'JSXOpeningElement', }, ], }, { code: `import NextScript from 'next/script'; export function MyApp({ Component, pageProps }) { return (
); }`, errors: [ { message: 'No duplicate polyfills from Polyfill.io are allowed. Array.prototype.copyWithin is already shipped with Next.js. See: https://nextjs.org/docs/messages/no-unwanted-polyfillio', type: 'JSXOpeningElement', }, ], }, { code: `import {Head} from 'next/document'; export class ES2019Features extends Head { render() { return (

Hello title

); } }`, errors: [ { message: 'No duplicate polyfills from Polyfill.io are allowed. Object.fromEntries is already shipped with Next.js. See: https://nextjs.org/docs/messages/no-unwanted-polyfillio', }, ], }, ], } describe('no-unwanted-polyfillio', () => { new ESLintTesterV8({ parserOptions: { ecmaVersion: 2018, sourceType: 'module', ecmaFeatures: { modules: true, jsx: true, }, }, }).run('eslint-v8', NextESLintRule, tests) new ESLintTesterV9({ languageOptions: { ecmaVersion: 2018, sourceType: 'module', parserOptions: { ecmaFeatures: { modules: true, jsx: true, }, }, }, }).run('eslint-v9', NextESLintRule, tests) })