rsnext/test/e2e/no-eslint-warn-with-no-eslint-config/index.test.ts
Balázs Orbán 2de7b43b78
fix: detect ESLint config in package.json (#40158)
Fixes #40133

Fixes a small regression introduced in #39872. We should be able to detect if a non-empty `package.json#eslintConfig` property is present.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-09-01 16:23:03 +00:00

87 lines
2.5 KiB
TypeScript

import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'
describe('no-eslint-warn-with-no-eslint-config', () => {
let next: NextInstance
if ((global as any).isNextDeploy) {
it('should skip for deploy', () => {})
return
}
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
export default function Page() {
return <p>hello world</p>
}
`,
},
dependencies: {},
})
})
afterAll(() => next.destroy())
it('should render', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('hello world')
})
it('should not have eslint warnings when no eslint config', async () => {
expect(next.cliOutput).not.toContain(
'No ESLint configuration detected. Run next lint to begin setup'
)
expect(next.cliOutput).not.toBe('warn')
})
if (!(global as any).isNextDev) {
it('should warn with empty eslintrc', async () => {
await next.stop()
await next.patchFile('.eslintrc.json', '{}')
await next.start()
expect(next.cliOutput).toContain(
'No ESLint configuration detected. Run next lint to begin setup'
)
})
it('should warn with empty eslint config in package.json', async () => {
await next.stop()
await next.deleteFile('.eslintrc.json')
const origPkgJson = await next.readFile('package.json')
const pkgJson = JSON.parse(origPkgJson)
pkgJson.eslintConfig = {}
try {
await next.patchFile('package.json', JSON.stringify(pkgJson))
await next.start()
expect(next.cliOutput).toContain(
'No ESLint configuration detected. Run next lint to begin setup'
)
} finally {
await next.patchFile('package.json', origPkgJson)
}
})
it('should not warn with eslint config in package.json', async () => {
await next.stop()
const origPkgJson = await next.readFile('package.json')
const pkgJson = JSON.parse(origPkgJson)
pkgJson.eslintConfig = { rules: { semi: 'off' } }
try {
await next.patchFile('package.json', JSON.stringify(pkgJson))
await next.start()
expect(next.cliOutput).not.toContain(
'No ESLint configuration detected. Run next lint to begin setup'
)
} finally {
await next.patchFile('package.json', origPkgJson)
}
})
}
})