Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e52126

Browse files
authored
Migrate prerender tests to new set-up (vercel#29245)
1 parent 371ca58 commit 8e52126

File tree

44 files changed

+2724
-2197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2724
-2197
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@
132132
"seedrandom": "3.0.5",
133133
"selenium-webdriver": "4.0.0-beta.4",
134134
"shell-quote": "1.7.2",
135-
"sqlite": "4.0.22",
136-
"sqlite3": "5.0.2",
137135
"styled-jsx-plugin-postcss": "3.0.2",
138136
"tailwindcss": "1.1.3",
139137
"taskr": "1.1.0",

packages/next/compiled/@vercel/nft/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/basepath.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe('basePath', () => {
136136
})
137137

138138
if (!dev) {
139-
if (!(global as any).isDeploy) {
139+
if (!(global as any).isNextDeploy) {
140140
it('should add basePath to routes-manifest', async () => {
141141
const routesManifest = JSON.parse(
142142
await next.readFile('.next/routes-manifest.json')
@@ -487,7 +487,7 @@ describe('basePath', () => {
487487
)
488488
})
489489

490-
if (!(global as any).isDeploy) {
490+
if (!(global as any).isNextDeploy) {
491491
it('should navigate an absolute local url with basePath', async () => {
492492
const browser = await webdriver(
493493
next.url,
@@ -843,5 +843,5 @@ describe('basePath', () => {
843843
}
844844
})
845845
}
846-
runTests((global as any).isDev)
846+
runTests((global as any).isNextDev)
847847
})
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
1-
/* eslint-env jest */
2-
3-
import fs from 'fs-extra'
4-
import { join, sep } from 'path'
1+
import path from 'path'
2+
import { createNext, FileRef } from 'e2e-utils'
3+
import { NextInstance } from 'test/lib/next-modes/base'
54
import webdriver from 'next-webdriver'
6-
import {
7-
findPort,
8-
killApp,
9-
launchApp,
10-
nextBuild,
11-
nextStart,
12-
} from 'next-test-utils'
135

14-
let app
15-
let appPort
16-
const appDir = join(__dirname, '..')
6+
describe('prerender native module', () => {
7+
let next: NextInstance
8+
9+
beforeAll(async () => {
10+
next = await createNext({
11+
files: {
12+
pages: new FileRef(
13+
path.join(__dirname, 'prerender-native-module/pages')
14+
),
15+
'data.sqlite': new FileRef(
16+
path.join(__dirname, 'prerender-native-module/data.sqlite')
17+
),
18+
},
19+
dependencies: {
20+
sqlite: '4.0.22',
21+
sqlite3: '5.0.2',
22+
},
23+
nextConfig: {
24+
experimental: {
25+
nftTracing: true,
26+
},
27+
},
28+
})
29+
})
30+
afterAll(() => next.destroy())
1731

18-
const runTests = () => {
1932
it('should render index correctly', async () => {
20-
const browser = await webdriver(appPort, '/')
33+
const browser = await webdriver(next.url, '/')
2134
expect(await browser.elementByCss('#index').text()).toBe('index page')
2235
expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({
2336
index: true,
2437
})
2538
})
2639

2740
it('should render /blog/first correctly', async () => {
28-
const browser = await webdriver(appPort, '/blog/first')
41+
const browser = await webdriver(next.url, '/blog/first')
2942

3043
expect(await browser.elementByCss('#blog').text()).toBe('blog page')
3144
expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({
@@ -39,7 +52,7 @@ const runTests = () => {
3952
})
4053

4154
it('should render /blog/second correctly', async () => {
42-
const browser = await webdriver(appPort, '/blog/second')
55+
const browser = await webdriver(next.url, '/blog/second')
4356
await browser.waitForElementByCss('#blog')
4457

4558
expect(await browser.elementByCss('#blog').text()).toBe('blog page')
@@ -52,26 +65,8 @@ const runTests = () => {
5265
],
5366
})
5467
})
55-
}
56-
57-
describe('Prerender native module', () => {
58-
describe('production', () => {
59-
beforeAll(async () => {
60-
const result = await nextBuild(appDir, undefined, {
61-
cwd: appDir,
62-
stderr: true,
63-
stdout: true,
64-
})
65-
66-
if (result.code !== 0) {
67-
console.error(result)
68-
throw new Error(`Failed to build, exited with code ${result.code}`)
69-
}
70-
appPort = await findPort()
71-
app = await nextStart(appDir, appPort, { cwd: appDir })
72-
})
73-
afterAll(() => killApp(app))
7468

69+
if ((global as any).isNextStart) {
7570
it('should output traces', async () => {
7671
const checks = [
7772
{
@@ -101,9 +96,8 @@ describe('Prerender native module', () => {
10196
]
10297

10398
for (const check of checks) {
104-
const contents = await fs.readFile(
105-
join(appDir, '.next/server/pages/', check.page + '.js.nft.json'),
106-
'utf8'
99+
const contents = await next.readFile(
100+
path.join('.next/server/pages/', check.page + '.js.nft.json')
107101
)
108102
const { version, files } = JSON.parse(contents)
109103
expect(version).toBe(1)
@@ -112,24 +106,12 @@ describe('Prerender native module', () => {
112106
check.tests.every((item) => files.some((file) => item.test(file)))
113107
).toBe(true)
114108

115-
if (sep === '/') {
109+
if (path.sep === '/') {
116110
expect(
117111
check.notTests.some((item) => files.some((file) => item.test(file)))
118112
).toBe(false)
119113
}
120114
}
121115
})
122-
123-
runTests()
124-
})
125-
126-
describe('dev', () => {
127-
beforeAll(async () => {
128-
appPort = await findPort()
129-
app = await launchApp(appDir, appPort, { cwd: appDir })
130-
})
131-
afterAll(() => killApp(app))
132-
133-
runTests()
134-
})
116+
}
135117
})

0 commit comments

Comments
 (0)