This commit is contained in:
Moriz Wahl 2023-12-04 14:45:20 +01:00
parent caea11f904
commit 04cff232e5
7 changed files with 4042 additions and 3 deletions

14
jest.config.js Normal file
View File

@ -0,0 +1,14 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
// eslint-disable-next-line import/no-commonjs
module.exports = {
verbose: true,
preset: 'ts-jest',
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts', '!**/node_modules/**', '!src/seeds/**', '!build/**'],
coverageThreshold: {
global: {
lines: 86,
},
},
setupFiles: ['./test/testSetup.ts'],
}

3980
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,8 @@
"dev": "TZ=UTC nodemon -w src --ext ts,json --exec ts-node -r tsconfig-paths/register src/index.ts",
"test:lint": "npm run test:lint:eslint && npm run test:lint:remark",
"test:lint:eslint": "eslint --ext .ts,.tsx,.js,.jsx,.json,.yml,.yaml --max-warnings 0 --ignore-path .gitignore .",
"test:lint:remark": "remark . --quiet --frail"
"test:lint:remark": "remark . --quiet --frail",
"test:unit": "TZ=UTC jest --runInBand --forceExit --detectOpenHandles"
},
"dependencies": {
"apollo-server-express": "^3.13.0",
@ -31,9 +32,11 @@
"devDependencies": {
"@eslint-community/eslint-plugin-eslint-comments": "^4.1.0",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.10",
"@types/node": "^20.10.1",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"apollo-server-testing": "^2.25.3",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard": "^17.1.0",
@ -45,6 +48,7 @@
"eslint-plugin-security": "^1.7.1",
"eslint-plugin-vitest": "^0.3.10",
"eslint-plugin-yml": "^1.10.0",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"prettier": "^3.1.0",
"remark-cli": "^12.0.0",
@ -52,12 +56,15 @@
"remark-preset-lint-consistent": "^5.1.2",
"remark-preset-lint-markdown-style-guide": "^5.1.3",
"remark-preset-lint-recommended": "^6.1.3",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsc-watch": "^6.0.4",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.3.2"
},
"imports": {
"#types/*": "./src/graphql/types/*"
"#graphql/*": "./src/graphql/*",
"#types/*": "./src/graphql/types/*",
"#test/*": "./test/*"
}
}

View File

@ -0,0 +1,22 @@
import { ApolloServerTestClient } from 'apollo-server-testing'
import { testEnvironment } from '#test/helpers'
let query: ApolloServerTestClient['query']
beforeAll(async () => {
const testEnv = await testEnvironment()
query = testEnv.query
})
describe('HelloResolver', () => {
it('return "Hello World!"', async () => {
await expect(query({ query: '{ hello { hello } }' })).resolves.toMatchObject({
data: {
hello: {
hello: 'Hello world!',
},
},
})
})
})

12
test/helpers.ts Normal file
View File

@ -0,0 +1,12 @@
import { ApolloServer } from 'apollo-server-express'
import { createTestClient } from 'apollo-server-testing'
import { schema } from '#graphql/schema'
export const testEnvironment = async () => {
const server = new ApolloServer({
schema: await schema(),
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return createTestClient(server as any)
}

2
test/testSetup.ts Normal file
View File

@ -0,0 +1,2 @@
// eslint-disable-next-line import/no-unassigned-import
import 'reflect-metadata'

View File

@ -8,7 +8,9 @@
"baseUrl": ".",
"lib": ["ESNext"],
"paths": {
"#types/*": ["./src/graphql/types/*"]
"#graphql/*": ["./src/graphql/*"],
"#types/*": ["./src/graphql/types/*"],
"#test/*": ["./test/*"]
},
"outDir": "./build/src",
"esModuleInterop": true,