-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
index.js
111 lines (90 loc) · 2.63 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* @jest-environment node
*/
require(`dotenv`).config({
path: `.env.test`,
})
const urling = require(`urling`)
const {
spawnGatsbyProcess,
gatsbyCleanBeforeAll,
} = require(`../test-fns/test-utils/get-gatsby-process`)
const {
mutateSchema,
resetSchema,
} = require(`../test-fns/test-utils/increment-remote-data`)
jest.setTimeout(100000)
// we run these tests twice in a row
// to make sure everything passes on a warm cache build
// we don't need to re-run some tests the second time,
// so the following allows us to do that:
const isWarmCache = process.env.WARM_CACHE
const testOnColdCacheOnly = isWarmCache ? test.skip : test
describe(`[gatsby-source-wordpress] Build default options`, () => {
beforeAll(done => {
;(async () => {
await urling({ url: `http://localhost:8001/graphql`, retry: 100 })
if (isWarmCache) {
done()
} else {
gatsbyCleanBeforeAll(done)
}
})()
})
testOnColdCacheOnly(`Default options build succeeded`, async () => {
const gatsbyProcess = spawnGatsbyProcess(`build`, {
DEFAULT_PLUGIN_OPTIONS: `1`,
})
const exitCode = await new Promise(resolve =>
gatsbyProcess.on(`exit`, resolve)
)
expect(exitCode).toEqual(0)
gatsbyProcess.kill()
})
})
describe(`[gatsby-source-wordpress] Run tests on develop build`, () => {
let gatsbyDevelopProcess
beforeAll(async () => {
if (!isWarmCache) {
await gatsbyCleanBeforeAll()
}
if (
isWarmCache &&
(!process.env.HTACCESS_USERNAME || !process.env.HTACCESS_PASSWORD)
) {
console.log(
`Please add the env var HTACCESS_USERNAME and HTACCESS_PASSWORD. It should be a string in the following pattern: base64Encode(\`\${username}:\${password}\`)`
)
await new Promise(resolve => setTimeout(resolve, 100))
process.exit(1)
}
try {
if (isWarmCache) {
const response = await mutateSchema()
console.log(response)
} else {
const response = await resetSchema()
console.log(response)
}
} catch (e) {
console.info(`Threw errors while mutating or unmutating WordPress`)
console.error(e.stack)
await new Promise(resolve => setTimeout(resolve, 1000))
process.exit(1)
}
return new Promise(resolve => {
gatsbyDevelopProcess = spawnGatsbyProcess(`develop`)
gatsbyDevelopProcess.stdout.on("data", data => {
process.stdout.write(data)
if (data.toString().includes("http://localhost:8000")) {
resolve()
}
})
})
})
require(`../test-fns/index`)
afterAll(done => {
gatsbyDevelopProcess.kill()
done()
})
})