Skip to content

Commit

Permalink
Add test for isSrcDir telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Oct 23, 2019
1 parent 25a985f commit eb5fe67
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
telemetry.record(
eventVersion({
cliCommand: 'build',
isSrcDir: pagesDir.startsWith('src'),
isSrcDir: path.relative(dir, pagesDir!).startsWith('src'),
})
),
eventNextPlugins(path.resolve(dir)).then(events => telemetry.record(events))
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default class DevServer extends Server {
telemetry.record(
eventVersion({
cliCommand: 'dev',
isSrcDir: this.pagesDir!.startsWith('src'),
isSrcDir: relative(this.dir, this.pagesDir!).startsWith('src'),
})
)
}
Expand Down
26 changes: 26 additions & 0 deletions test/integration/telemetry/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* eslint-env jest */
/* global jasmine */
import path from 'path'
import fs from 'fs-extra'
import { runNextCommand } from 'next-test-utils'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2

const appDir = path.join(__dirname, '..')

describe('Telemetry CLI', () => {
it('can print telemetry status', async () => {
const { stdout } = await runNextCommand(['telemetry'], {
Expand Down Expand Up @@ -59,4 +63,26 @@ describe('Telemetry CLI', () => {
expect(stdout).toMatch(/already disabled/)
expect(stdout).toMatch(/Status: Disabled/)
})

it('detects isSrcDir dir correctly', async () => {
const { stderr } = await runNextCommand(['build', appDir], {
stderr: true,
env: {
NEXT_TELEMETRY_DEBUG: 1
}
})

expect(stderr).toMatch(/isSrcDir.*?false/)

await fs.move(path.join(appDir, 'pages'), path.join(appDir, 'src/pages'))
const { stderr: stderr2 } = await runNextCommand(['build', appDir], {
stderr: true,
env: {
NEXT_TELEMETRY_DEBUG: 1
}
})
await fs.move(path.join(appDir, 'src/pages'), path.join(appDir, 'pages'))

expect(stderr2).toMatch(/isSrcDir.*?true/)
})
})

0 comments on commit eb5fe67

Please sign in to comment.