Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for invalid pages #10403

Merged
merged 8 commits into from Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/next/build/index.ts
Expand Up @@ -770,9 +770,8 @@ export default async function build(dir: string, conf = null): Promise<void> {

const analysisEnd = process.hrtime(analysisBegin)
telemetry.record(
eventBuildOptimize({
eventBuildOptimize(pagePaths, {
durationInSeconds: analysisEnd[0],
totalPageCount: pagePaths.length,
staticPageCount: staticPages.size,
ssrPageCount: pagePaths.length - staticPages.size,
})
Expand Down
23 changes: 21 additions & 2 deletions packages/next/telemetry/events/build.ts
Expand Up @@ -19,13 +19,32 @@ type EventBuildOptimized = {
totalPageCount: number
staticPageCount: number
ssrPageCount: number
hasDunderPages: boolean
hasTestPages: boolean
}

const REGEXP_DIRECTORY_DUNDER = /[\\/]__[^\\/]+(?<![\\/]__(?:tests|mocks))__[\\/]/i
const REGEXP_DIRECTORY_TESTS = /[\\/]__(tests|mocks)__[\\/]/i
const REGEXP_FILE_TEST = /\.(?:spec|test)\.[^.]+$/i

export function eventBuildOptimize(
event: EventBuildOptimized
pagePaths: string[],
event: Omit<
EventBuildOptimized,
'totalPageCount' | 'hasDunderPages' | 'hasTestPages'
>
): { eventName: string; payload: EventBuildOptimized } {
return {
eventName: EVENT_BUILD_OPTIMIZE,
payload: event,
payload: {
...event,
totalPageCount: pagePaths.length,
hasDunderPages: pagePaths.some(path =>
REGEXP_DIRECTORY_DUNDER.test(path)
),
hasTestPages: pagePaths.some(
path => REGEXP_DIRECTORY_TESTS.test(path) || REGEXP_FILE_TEST.test(path)
),
},
}
}
3 changes: 3 additions & 0 deletions test/integration/telemetry/pages/__ytho__/lel.js
@@ -0,0 +1,3 @@
export default () => {
return 'oops, I happen to look like a React component'
}
1 change: 1 addition & 0 deletions test/integration/telemetry/pages/hello.test.js
@@ -0,0 +1 @@
export default () => 'Hello Test'
13 changes: 13 additions & 0 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -92,6 +92,19 @@ describe('Telemetry CLI', () => {
expect(stderr2).toMatch(/isSrcDir.*?true/)
})

fit('detects tests correctly for `next build`', async () => {
const { stderr } = await runNextCommand(['build', appDir], {
stderr: true,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
})

console.log(stderr)
expect(stderr).toMatch(/hasDunderPages.*?true/)
expect(stderr).toMatch(/hasTestPages.*?true/)
})

it('detects isSrcDir dir correctly for `next dev`', async () => {
let port = await findPort()
let stderr = ''
Expand Down