Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Mar 31, 2022
1 parent 92fb65a commit 2478fcb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions test/integration/telemetry/pages/data.json
@@ -0,0 +1 @@
{ "hello": "world" }
10 changes: 10 additions & 0 deletions test/integration/telemetry/pages/gssp-again.js
@@ -0,0 +1,10 @@
import http from 'http'
import config from './data.json'

export default () => 'Hello World'

export function getServerSideProps() {
console.log(http)
console.log(config)
return { props: {} }
}
6 changes: 6 additions & 0 deletions test/integration/telemetry/pages/gssp.js
@@ -1,5 +1,11 @@
import fs from 'fs'
import path from 'path'

export default () => 'Hello World'

export function getServerSideProps() {
try {
fs.readyFile(path.join(process.cwd(), 'public/small.jpg'))
} catch (_) {}
return { props: {} }
}
10 changes: 8 additions & 2 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -71,6 +71,8 @@ describe('Telemetry CLI', () => {
})

it('detects isSrcDir dir correctly for `next build`', async () => {
// must clear cache for GSSP imports to be detected correctly
await fs.remove(path.join(appDir, '.next'))
const { stderr } = await runNextCommand(['build', appDir], {
stderr: true,
env: {
Expand All @@ -79,6 +81,10 @@ describe('Telemetry CLI', () => {
})

expect(stderr).toMatch(/isSrcDir.*?false/)
expect(stderr).toMatch(/package.*?"fs"/)
expect(stderr).toMatch(/package.*?"path"/)
expect(stderr).toMatch(/package.*?"http"/)
expect(stderr).toMatch(/NEXT_PACKAGE_USED_IN_GET_SERVER_SIDE_PROPS/)

await fs.move(path.join(appDir, 'pages'), path.join(appDir, 'src/pages'))
const { stderr: stderr2 } = await runNextCommand(['build', appDir], {
Expand Down Expand Up @@ -329,10 +335,10 @@ describe('Telemetry CLI', () => {

const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/.exec(stderr).pop()
expect(event1).toMatch(/"staticPropsPageCount": 2/)
expect(event1).toMatch(/"serverPropsPageCount": 1/)
expect(event1).toMatch(/"serverPropsPageCount": 2/)
expect(event1).toMatch(/"ssrPageCount": 1/)
expect(event1).toMatch(/"staticPageCount": 4/)
expect(event1).toMatch(/"totalPageCount": 8/)
expect(event1).toMatch(/"totalPageCount": 9/)
})

it('detects isSrcDir dir correctly for `next dev`', async () => {
Expand Down

0 comments on commit 2478fcb

Please sign in to comment.