Skip to content

Commit 57366a2

Browse files
committed
test: with v8 and remove path as it duplicates test
1 parent 547e6e7 commit 57366a2

File tree

1 file changed

+29
-55
lines changed

1 file changed

+29
-55
lines changed

test/unit/eslint-plugin-next/no-document-import-in-page.test.ts

Lines changed: 29 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
import path from 'path'
1+
import { RuleTester as ESLintTesterV8 } from 'eslint'
2+
import { RuleTester as ESLintTesterV9 } from 'eslint-v9'
3+
import { rules } from '@next/eslint-plugin-next'
24

3-
import rule from '@next/eslint-plugin-next/dist/rules/no-document-import-in-page'
4-
import { RuleTester } from 'eslint'
5-
;(RuleTester as any).setDefaultConfig({
6-
parserOptions: {
7-
ecmaVersion: 2018,
8-
sourceType: 'module',
9-
ecmaFeatures: {
10-
modules: true,
11-
jsx: true,
12-
},
13-
},
14-
})
15-
const ruleTester = new RuleTester()
5+
const NextESLintRule = rules['no-document-import-in-page']
166

17-
ruleTester.run('no-document-import-in-page', rule, {
7+
const tests = {
188
valid: [
199
{
2010
code: `import Document from "next/document"
@@ -33,34 +23,6 @@ ruleTester.run('no-document-import-in-page', rule, {
3323
{
3424
code: `import Document from "next/document"
3525
36-
export default class MyDocument extends Document {
37-
render() {
38-
return (
39-
<Html>
40-
</Html>
41-
);
42-
}
43-
}
44-
`,
45-
filename: `pages${path.sep}_document.js`,
46-
},
47-
{
48-
code: `import NextDocument from "next/document"
49-
50-
export default class MyDocument extends NextDocument {
51-
render() {
52-
return (
53-
<Html>
54-
</Html>
55-
);
56-
}
57-
}
58-
`,
59-
filename: `pages${path.posix.sep}_document.tsx`,
60-
},
61-
{
62-
code: `import Document from "next/document"
63-
6426
export default class MyDocument extends Document {
6527
render() {
6628
return (
@@ -144,19 +106,31 @@ ruleTester.run('no-document-import-in-page', rule, {
144106
},
145107
],
146108
},
147-
{
148-
code: `import Document from "next/document"
109+
],
110+
}
149111

150-
export const Test = () => <p>Test</p>
151-
`,
152-
filename: `pages${path.sep}test.js`,
153-
errors: [
154-
{
155-
message:
156-
'`<Document />` from `next/document` should not be imported outside of `pages/_document.js`. See: https://nextjs.org/docs/messages/no-document-import-in-page',
157-
type: 'ImportDeclaration',
112+
describe('no-document-import-in-page', () => {
113+
new ESLintTesterV8({
114+
parserOptions: {
115+
ecmaVersion: 2018,
116+
sourceType: 'module',
117+
ecmaFeatures: {
118+
modules: true,
119+
jsx: true,
120+
},
121+
},
122+
}).run('eslint-v8', NextESLintRule, tests)
123+
124+
new ESLintTesterV9({
125+
languageOptions: {
126+
ecmaVersion: 2018,
127+
sourceType: 'module',
128+
parserOptions: {
129+
ecmaFeatures: {
130+
modules: true,
131+
jsx: true,
158132
},
159-
],
133+
},
160134
},
161-
],
135+
}).run('eslint-v9', NextESLintRule, tests)
162136
})

0 commit comments

Comments
 (0)