Skip to content

Commit

Permalink
test: added test example
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Sep 18, 2024
1 parent 39e1fc3 commit 55c205b
Show file tree
Hide file tree
Showing 7 changed files with 1,785 additions and 1,694 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@
"@akryum/sheep": "^0.5.2",
"@antfu/eslint-config": "^2.6.3",
"eslint": "^8.57.0"
},
"pnpm": {
"overrides": {
"graphql": "^16.8.1"
}
}
}
2 changes: 1 addition & 1 deletion playground/.moquerie/snapshots/vitest/Query.res.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
]
}
}
}
}
2 changes: 1 addition & 1 deletion playground/.moquerie/snapshots/vitest/snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
]
}
}
}
}
3 changes: 2 additions & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"start": "node dist/index.js",
"prepare": "pnpm run codegen",
"codegen": "graphql-codegen --config codegen.ts",
"moquerie": "moquerie"
"moquerie": "moquerie",
"test": "vitest"
},
"dependencies": {
"@graphql-tools/schema": "^10.0.0",
Expand Down
75 changes: 75 additions & 0 deletions playground/src/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import type { MoquerieInstance } from 'moquerie'
import { createMoquerieInstance, startServer, useSnapshot } from 'moquerie'

describe('fetch', () => {
let mq: MoquerieInstance
let port: number

beforeEach(async () => {
mq = await createMoquerieInstance({
cwd: process.cwd(),
skipWrites: true,
watching: false,
})

await useSnapshot(mq, 'vitest')

const result = await startServer(mq)
port = result.port
})

afterEach(async () => {
await mq.destroy()
})

it('should fetch hello', async () => {
const response = await fetch(`http://localhost:${port}/graphql`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
query {
hello
}
`,
}),
})
const data = await response.json()
expect(data).toEqual({
data: {
hello: 'villa',
},
})
})

it('should fetch manyHellos', async () => {
const response = await fetch(`http://localhost:${port}/graphql`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
query {
manyHellos
manyHellosCount
}
`,
}),
})
const data = await response.json()
expect(data).toEqual({
data: {
manyHellosCount: 3,
manyHellos: [
'succedo',
'comparo',
'denego',
],
},
})
})
})
14 changes: 14 additions & 0 deletions playground/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
server: {
deps: {
external: [
/\/node_modules\//,
/graphql/,
],
},
},
},
})
Loading

0 comments on commit 55c205b

Please sign in to comment.