Skip to content

Commit c0e5241

Browse files
committed
Fix Node 14 compatibility
1 parent ea98a34 commit c0e5241

File tree

9 files changed

+53
-113
lines changed

9 files changed

+53
-113
lines changed
Lines changed: 32 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
import { spawn } from 'child_process'
2-
import puppeteer from 'puppeteer'
3-
4-
let browser: puppeteer.Browser
5-
let page: puppeteer.Page
6-
let bunProcess: ReturnType<typeof spawn>
7-
8-
const timings = {
9-
waitForSelector: 999,
10-
waitForResponse: 1999,
11-
}
12-
13-
jest.setTimeout(30000)
14-
15-
let toSkip = true
2+
import { getIntrospectionQuery } from 'graphql'
163

174
describe('Bun integration', () => {
5+
let bunProcess: ReturnType<typeof spawn>
186
let serverUrl: string
7+
198
beforeAll(async () => {
20-
if (process.versions.node.startsWith('18')) {
21-
toSkip = false
22-
return
23-
}
249
// Start Bun
2510
bunProcess = spawn('yarn', ['workspace', 'example-bun', 'start'])
2611

@@ -37,83 +22,44 @@ describe('Bun integration', () => {
3722
const chunkString = chunk.toString('utf-8')
3823
console.log(chunk.toString('utf-8'))
3924
if (chunkString.includes('Server is running on')) {
40-
setTimeout(() => {
41-
resolve(chunkString.split('Server is running on ')[1])
42-
}, 5000)
25+
resolve(chunkString.split('Server is running on ')[1])
4326
}
4427
})
4528
})
46-
47-
// Launch puppeteer
48-
browser = await puppeteer.launch({
49-
// If you wanna run tests with open browser
50-
// set your PUPPETEER_HEADLESS env to "false"
51-
headless: process.env.PUPPETEER_HEADLESS !== 'false',
52-
args: ['--incognito'],
53-
})
54-
})
55-
56-
beforeEach(async () => {
57-
if (toSkip) {
58-
return
59-
}
60-
if (page !== undefined) {
61-
await page.close()
62-
}
63-
const context = await browser.createIncognitoBrowserContext()
64-
page = await context.newPage()
6529
})
6630

67-
afterAll(async () => {
68-
if (toSkip) {
69-
return
70-
}
71-
await browser.close()
31+
afterAll(() => {
7232
bunProcess.kill()
7333
})
7434

75-
it('go to GraphiQL page', async () => {
76-
if (toSkip) {
77-
return
78-
}
79-
// Go the the right route
80-
const body = await page.goto(
81-
`${serverUrl}?query=query+Hello+%7B%0A%09greetings%0A%7D`,
82-
)
83-
84-
let strIntro = ''
85-
try {
86-
// A-1/ Wait for the introspection query result getting our type "greetings"
87-
const resIntro = await page.waitForResponse(
88-
(res) => res.url().endsWith('/graphql'),
89-
{
90-
timeout: timings.waitForResponse,
91-
},
92-
)
93-
const jsonIntro = await resIntro.json()
94-
strIntro = JSON.stringify(jsonIntro, null, 0)
95-
} catch (error) {
96-
// We had an issue grabbing the introspection query result!
97-
// let's see what is in the html with the finafinally
98-
} finally {
99-
const bodyContent = await body?.text()
100-
// B/ Check that GraphiQL is showing
101-
expect(bodyContent).toContain(`Yoga GraphiQL`)
102-
}
103-
104-
// A-2/ Finish the test after the body check
105-
expect(strIntro).toContain(`"name":"greetings"`)
35+
it('shows GraphiQL', async () => {
36+
const response = await fetch(serverUrl, {
37+
method: 'GET',
38+
headers: {
39+
Accept: 'text/html',
40+
},
41+
})
42+
expect(response.status).toEqual(200)
43+
expect(response.headers.get('content-type')).toEqual('text/html')
44+
const htmlContents = await response.text()
45+
expect(htmlContents).toContain('Yoga GraphiQL')
46+
})
10647

107-
// C/ Tigger the default request and wait for the response
108-
const [res] = await Promise.all([
109-
page.waitForResponse((res) => res.url().endsWith('/graphql'), {
110-
timeout: timings.waitForResponse,
48+
it('accepts a query', async () => {
49+
const response = await fetch(serverUrl, {
50+
method: 'POST',
51+
headers: {
52+
'Content-Type': 'application/json',
53+
},
54+
body: JSON.stringify({
55+
query: `{ greetings }`,
11156
}),
112-
page.click(`button[class="execute-button"]`),
113-
])
114-
115-
const json = await res.json()
116-
const str = JSON.stringify(json, null, 0)
117-
expect(str).toContain(`{"data":{"greetings":"Hello Bun!"}}`)
57+
})
58+
const result = await response.json()
59+
expect(result).toEqual({
60+
data: {
61+
greetings: 'Hello Bun!',
62+
},
63+
})
11864
})
11965
})

examples/error-handling/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"dependencies": {
1010
"graphql-yoga": "2.13.11",
11-
"@whatwg-node/fetch": "0.4.3",
11+
"@whatwg-node/fetch": "0.4.4",
1212
"graphql": "^16.1.0"
1313
},
1414
"devDependencies": {

packages/event-target/redis-event-target/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"author": "Laurin Quast <[email protected]>",
2020
"license": "MIT",
2121
"dependencies": {
22-
"@whatwg-node/events": "0.0.1",
22+
"@whatwg-node/events": "0.0.2",
2323
"@graphql-yoga/typed-event-target": "^0.1.1"
2424
},
2525
"peerDependencies": {

packages/graphql-yoga/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
"@graphql-tools/schema": "^9.0.0",
6363
"@graphql-tools/utils": "^8.8.0",
6464
"@graphql-yoga/subscription": "^2.2.2",
65-
"@whatwg-node/fetch": "0.4.3",
66-
"@whatwg-node/server": "0.4.4",
65+
"@whatwg-node/fetch": "0.4.4",
66+
"@whatwg-node/server": "0.4.5",
6767
"dset": "^3.1.1",
6868
"graphql-config": "^4.1.0",
6969
"tslib": "^2.3.1",

packages/plugins/apollo-inline-trace/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"graphql-yoga": "^2.13.11"
4545
},
4646
"dependencies": {
47-
"@whatwg-node/fetch": "0.4.3",
47+
"@whatwg-node/fetch": "0.4.4",
4848
"apollo-reporting-protobuf": "^3.3.2"
4949
}
5050
}

packages/plugins/apq/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"access": "public"
4141
},
4242
"dependencies": {
43-
"@whatwg-node/fetch": "0.4.3",
43+
"@whatwg-node/fetch": "0.4.4",
4444
"tiny-lru": "^8.0.2"
4545
},
4646
"peerDependencies": {

packages/subscription/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
"dependencies": {
6363
"@graphql-yoga/typed-event-target": "^0.1.1",
64-
"@whatwg-node/events": "0.0.1",
64+
"@whatwg-node/events": "0.0.2",
6565
"@repeaterjs/repeater": "^3.0.4",
6666
"tslib": "^2.3.1"
6767
},

packages/subscription/src/createPubSub.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Redis from 'ioredis-mock'
22
import { createRedisEventTarget } from '@graphql-yoga/redis-event-target'
33
import { createPubSub } from './createPubSub.js'
4-
import { EventTarget } from '@whatwg-node/fetch'
4+
import { EventTarget } from '@whatwg-node/events'
55

66
async function collectAsyncIterableValues<TType>(
77
asyncIterable: AsyncIterable<TType>,

yarn.lock

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5724,32 +5724,31 @@
57245724
"@webassemblyjs/ast" "1.11.1"
57255725
"@xtuc/long" "4.2.2"
57265726

5727-
"@whatwg-node/[email protected].1":
5728-
version "0.0.1"
5729-
resolved "https://registry.yarnpkg.com/@whatwg-node/events/-/events-0.0.1.tgz#bb64b0060fcb413386cdbf4754ccaf8b88f47918"
5730-
integrity sha512-ly90EZM/EcFYtCj3dxfZsYsjJ0a3gxc60Dvp1Ix71NT1p8s7yURAPMM/Asf777fEl7E5iz1NPo1PilHV1TbqVQ==
5727+
"@whatwg-node/[email protected].2":
5728+
version "0.0.2"
5729+
resolved "https://registry.yarnpkg.com/@whatwg-node/events/-/events-0.0.2.tgz#7b7107268d2982fc7b7aff5ee6803c64018f84dd"
5730+
integrity sha512-WKj/lI4QjnLuPrim0cfO7i+HsDSXHxNv1y0CrJhdntuO3hxWZmnXCwNDnwOvry11OjRin6cgWNF+j/9Pn8TN4w==
57315731

5732-
"@whatwg-node/[email protected].3", "@whatwg-node/fetch@^0.4.0":
5733-
version "0.4.3"
5734-
resolved "https://registry.yarnpkg.com/@whatwg-node/fetch/-/fetch-0.4.3.tgz#6c95c039f0912bbcb1af8e5c496104bbeab242d2"
5735-
integrity sha512-+NzflVRaWl48Jdjq7FOxkmb8wLpSWtk6XKAEMfr/yDOqJS7HWxA+Rc5rTVqh2IRi6QZJyKGoaGKjOAqrGq07nA==
5732+
"@whatwg-node/[email protected].4", "@whatwg-node/fetch@^0.4.0":
5733+
version "0.4.4"
5734+
resolved "https://registry.yarnpkg.com/@whatwg-node/fetch/-/fetch-0.4.4.tgz#9f6502177453d48b76d31f33d32dcd60afb9eb54"
5735+
integrity sha512-/c2u1blMAXHVXneZjVLyE0AwdRuuFpv2P3ghNz2QtpHed+25WdSkTi7XxICwuaRsl/mMgundCzSy1352rZgWPg==
57365736
dependencies:
57375737
"@peculiar/webcrypto" "^1.4.0"
57385738
abort-controller "^3.0.0"
57395739
busboy "^1.6.0"
5740-
event-target-polyfill "^0.0.3"
57415740
form-data-encoder "^1.7.1"
57425741
formdata-node "^4.3.1"
57435742
node-fetch "^2.6.7"
57445743
undici "^5.8.0"
57455744
web-streams-polyfill "^3.2.0"
57465745

5747-
"@whatwg-node/[email protected].4":
5748-
version "0.4.4"
5749-
resolved "https://registry.yarnpkg.com/@whatwg-node/server/-/server-0.4.4.tgz#d773e18e44855c0f23623e1b64afee813eaf3212"
5750-
integrity sha512-Ka1NuF2TKKNV4XIt/PAaprYplTWJwCyPThrA9U9m2anDPF+o7vzQWI+dHlTfxdbHMfqQuSu5DdcVONYGsG1Txg==
5746+
"@whatwg-node/[email protected].5":
5747+
version "0.4.5"
5748+
resolved "https://registry.yarnpkg.com/@whatwg-node/server/-/server-0.4.5.tgz#adbd34134a3cfd7815aef7359c95b65270252eda"
5749+
integrity sha512-3wwIFZOuCXBKk08+S12xHtky3c8LLR6V6fKQMZqj6tKCawaUistuXzZtTAKyOg8NWglVGqAAng5vwcKa8j4hcQ==
57515750
dependencies:
5752-
"@whatwg-node/fetch" "^0.4.0"
5751+
"@whatwg-node/fetch" "0.4.4"
57535752
tslib "^2.3.1"
57545753

57555754
"@wry/context@^0.6.0":
@@ -10091,11 +10090,6 @@ etag@^1.8.1, etag@~1.8.1:
1009110090
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
1009210091
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
1009310092

10094-
event-target-polyfill@^0.0.3:
10095-
version "0.0.3"
10096-
resolved "https://registry.yarnpkg.com/event-target-polyfill/-/event-target-polyfill-0.0.3.tgz#ed373295f3b257774b5d75afb2599331d9f3406c"
10097-
integrity sha512-ZMc6UuvmbinrCk4RzGyVmRyIsAyxMRlp4CqSrcQRO8Dy0A9ldbiRy5kdtBj4OtP7EClGdqGfIqo9JmOClMsGLQ==
10098-
1009910093
event-target-shim@^5.0.0:
1010010094
version "5.0.1"
1010110095
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"

0 commit comments

Comments
 (0)