Unverified Commit 3246274d authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

fix(build): require test files be full name or extension (#20605)

Fixes #19935
parent a03f1f38
...@@ -33,7 +33,17 @@ export async function runTypeCheck( ...@@ -33,7 +33,17 @@ export async function runTypeCheck(
}) })
const result = program.emit() const result = program.emit()
const regexIgnoredFile = /[\\/]__(?:tests|mocks)__[\\/]|(?:spec|test)\.[^\\/]+$/ // Intended to match:
// - pages/test.js
// - pages/apples.test.js
// - pages/__tests__/a.js
//
// But not:
// - pages/contest.js
// - pages/other.js
// - pages/test/a.js
//
const regexIgnoredFile = /[\\/]__(?:tests|mocks)__[\\/]|(?<=[\\/.])(?:spec|test)\.[^\\/]+$/
const allDiagnostics = ts const allDiagnostics = ts
.getPreEmitDiagnostics(program) .getPreEmitDiagnostics(program)
.concat(result.diagnostics) .concat(result.diagnostics)
......
// Below type error is intentional, it helps check that we don't filter this
// file out because it's named con(test).js
export default (): boolean => 'Index page'
/* eslint-env jest */
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
jest.setTimeout(1000 * 60 * 2)
const appDir = join(__dirname, '..')
describe('TypeScript filtered files', () => {
it('should fail to build the app with a file named con*test*.js', async () => {
const output = await nextBuild(appDir, [], { stdout: true, stderr: true })
expect(output.stdout).not.toMatch(/Compiled successfully/)
expect(output.code).toBe(1)
expect(output.stderr).toMatch(/Failed to compile/)
expect(output.stderr).toMatch(/is not assignable to type 'boolean'/)
})
})
{
"compilerOptions": {
"esModuleInterop": true,
"module": "esnext",
"jsx": "preserve",
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "components", "pages"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment