Skip to content

Commit

Permalink
Merge branch 'canary' into deploy-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
chibicode committed Feb 4, 2020
2 parents e83c9c9 + 909ab3b commit 069adbd
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
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.skip
@@ -0,0 +1 @@
export default () => 'Hello Test'
20 changes: 20 additions & 0 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -92,6 +92,26 @@ describe('Telemetry CLI', () => {
expect(stderr2).toMatch(/isSrcDir.*?true/)
})

it('detects tests correctly for `next build`', async () => {
await fs.rename(
path.join(appDir, 'pages', 'hello.test.skip'),
path.join(appDir, 'pages', 'hello.test.js')
)
const { stderr } = await runNextCommand(['build', appDir], {
stderr: true,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
})
await fs.rename(
path.join(appDir, 'pages', 'hello.test.js'),
path.join(appDir, 'pages', 'hello.test.skip')
)

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

0 comments on commit 069adbd

Please sign in to comment.