Skip to content

Commit 46799c9

Browse files
committed
refactor: simplify test cases for app router
1 parent 95dcee9 commit 46799c9

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

test/integration/eslint/test/next-lint.test.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ const dirMaxWarnings = join(__dirname, '../max-warnings')
2929
const dirEmptyDirectory = join(__dirname, '../empty-directory')
3030
const dirEslintIgnore = join(__dirname, '../eslint-ignore')
3131
const dirNoEslintPlugin = join(__dirname, '../no-eslint-plugin')
32-
const dirPageDirNoConfig = join(__dirname, '../no-config')
33-
const dirAppDirNoConfig = join(__dirname, '../app-dir/no-config')
32+
const dirNoConfig = join(__dirname, '../no-config')
3433
const dirEslintCache = join(__dirname, '../eslint-cache')
3534
const dirEslintCacheCustomDir = join(__dirname, '../eslint-cache-custom-dir')
3635
const dirFileLinting = join(__dirname, '../file-linting')
@@ -42,7 +41,7 @@ describe('Next Lint', () => {
4241
async function nextLintTemp(setupCallback, isApp = false) {
4342
const folder = join(os.tmpdir(), Math.random().toString(36).substring(2))
4443
await fs.mkdirp(folder)
45-
await fs.copy(isApp ? dirAppDirNoConfig : dirPageDirNoConfig, folder)
44+
await fs.copy(join(dirNoConfig, isApp ? 'app' : ''), folder)
4645
await setupCallback?.(folder)
4746

4847
try {
@@ -89,7 +88,7 @@ describe('Next Lint', () => {
8988
{ packageManger: 'pnpm', lockFile: 'pnpm-lock.yaml' },
9089
{ packageManger: 'npm', lockFile: 'package-lock.json' },
9190
]) {
92-
test(`Page Router - installs eslint and eslint-config-next as devDependencies if missing with ${packageManger}`, async () => {
91+
test(`installs eslint and eslint-config-next as devDependencies if missing with ${packageManger}`, async () => {
9392
const { stdout, pkgJson } = await nextLintTemp(async (folder) => {
9493
await fs.writeFile(join(folder, lockFile), '')
9594
})
@@ -102,54 +101,54 @@ describe('Next Lint', () => {
102101
expect(stdout).toContain(packageManger)
103102
expect(pkgJson.devDependencies).toHaveProperty('eslint')
104103
expect(pkgJson.devDependencies).toHaveProperty('eslint-config-next')
105-
})
106104

107-
test(`App Router - installs eslint and eslint-config-next as devDependencies if missing with ${packageManger}`, async () => {
108-
const { stdout, pkgJson } = await nextLintTemp(async (folder) => {
109-
await fs.writeFile(join(folder, lockFile), '')
110-
}, true)
105+
// App Router
106+
const { stdout: appStdout, pkgJson: appPkgJson } = await nextLintTemp(
107+
async (folder) => {
108+
await fs.writeFile(join(folder, lockFile), '')
109+
},
110+
true
111+
)
111112

112-
expect(stdout).toContain(
113+
expect(appStdout).toContain(
113114
`Installing devDependencies (${packageManger}):`
114115
)
115-
expect(stdout).toContain('eslint')
116-
expect(stdout).toContain('eslint-config-next')
117-
expect(stdout).toContain(packageManger)
118-
expect(pkgJson.devDependencies).toHaveProperty('eslint')
119-
expect(pkgJson.devDependencies).toHaveProperty('eslint-config-next')
116+
expect(appStdout).toContain('eslint')
117+
expect(appStdout).toContain('eslint-config-next')
118+
expect(appStdout).toContain(packageManger)
119+
expect(appPkgJson.devDependencies).toHaveProperty('eslint')
120+
expect(appPkgJson.devDependencies).toHaveProperty('eslint-config-next')
120121
})
121122
}
122123

123-
test('Page Router - creates .eslintrc.json file with a default configuration', async () => {
124+
test('creates .eslintrc.json file with a default configuration', async () => {
124125
const { stdout, eslintrcJson } = await nextLintTemp()
125126

126127
expect(stdout).toContain(
127128
'We created the .eslintrc.json file for you and included your selected configuration'
128129
)
129130
expect(eslintrcJson).toMatchObject({ extends: 'next/core-web-vitals' })
130-
})
131131

132-
test('App Router - creates .eslintrc.json file with a default configuration', async () => {
133-
const { stdout, eslintrcJson } = await nextLintTemp(undefined, true)
132+
// App Router
133+
const { stdout: appStdout, eslintrcJson: appEslintrcJson } =
134+
await nextLintTemp(null, true)
134135

135-
expect(stdout).toContain(
136+
expect(appStdout).toContain(
136137
'We created the .eslintrc.json file for you and included your selected configuration'
137138
)
138-
expect(eslintrcJson).toMatchObject({ extends: 'next/core-web-vitals' })
139+
expect(appEslintrcJson).toMatchObject({ extends: 'next/core-web-vitals' })
139140
})
140141

141-
test('Page Router - shows a successful message when completed', async () => {
142+
test('shows a successful message when completed', async () => {
142143
const { stdout } = await nextLintTemp()
143144

144145
expect(stdout).toContain(
145146
'ESLint has successfully been configured. Run next lint again to view warnings and errors'
146147
)
147-
})
148148

149-
test('App Router - shows a successful message when completed', async () => {
150-
const { stdout } = await nextLintTemp(undefined, true)
151-
152-
expect(stdout).toContain(
149+
// App Router
150+
const { stdout: appStdout } = await nextLintTemp(null, true)
151+
expect(appStdout).toContain(
153152
'ESLint has successfully been configured. Run next lint again to view warnings and errors'
154153
)
155154
})

0 commit comments

Comments
 (0)