/
index.test.js
82 lines (68 loc) · 2.47 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// /* eslint-env jest */
import { join } from 'path'
import { nextBuild } from 'next-test-utils'
const nextdir = join(__dirname, '../app')
const outdir = join(nextdir, 'out')
const appdir = join(outdir, 'main.js')
let app = null
if (process.env.TEST_ELECTRON) {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
const electron = require(join(nextdir, 'node_modules/electron'))
const { Application } = require(join(nextdir, 'node_modules/spectron'))
describe('Parse Relative Url', () => {
describe('File Protocol via Electron', () => {
beforeAll(async () => {
await nextBuild(nextdir)
app = new Application({
path: electron,
args: [
'--no-sandbox',
'--disable-dev-shm-usage',
'--disable-gpu',
appdir,
],
chromeDriverArgs: [
'--no-sandbox',
'--disable-dev-shm-usage',
'--disable-gpu',
],
})
await app.start()
})
afterAll(async () => {
if (app && app.isRunning()) {
await app.stop()
}
})
it('app init', async () => {
const count = await app.client.getWindowCount()
expect(count).toEqual(1)
})
it('should render the home page', async () => {
const text = await app.client.$('#home-page p').getText()
expect(text).toBe('This is the home page')
})
it('should do navigations via Link', async () => {
await app.client.$('#about-via-link').click()
const text = await app.client.$('#about-page p').getText()
expect(text).toBe('This is the about page')
})
it('should do back to home page via Link', async () => {
await app.client.$('#about-page a').click()
const text = await app.client.$('#home-page p').getText()
expect(text).toBe('This is the home page')
})
it('should do navigations via Router', async () => {
await app.client.$('#about-via-router').click()
const text = await app.client.$('#about-page p').getText()
expect(text).toBe('This is the about page')
})
})
})
}
)
} else {
it('Should skip testing electron without process.env.TEST_ELECTRON set', () => {})
}