I have a simple NestJS + Fastify + Graphql app, however when I try to use fastify in my e2e, the tests are erring out. I can't seem to figure out the issue here. Anybody else seen this? When I run the app, everything works as expected.
Depedencies from package.json For those who know the dependencies better than I. Perhaps there is a mismatch.
"dependencies": {
"@nestjs/common": "^7.0.0",
"@nestjs/config": "^0.5.0",
"@nestjs/core": "^7.0.0",
"@nestjs/graphql": "^7.6.0",
"@nestjs/platform-express": "^7.0.0",
"@nestjs/platform-fastify": "^7.2.0",
"apollo-server-fastify": "^2.16.1",
"class-transformer": "^0.3.1",
"class-validator": "^0.12.2",
"graphql": "^15.3.0",
"joi": "^17.2.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"type-graphql": "^1.0.0-rc.3",
"typegraphql-nestjs": "^0.2.2"
},
"devDependencies": {
"@nestjs/cli": "^7.0.0",
"@nestjs/schematics": "^7.0.0",
"@nestjs/testing": "^7.0.0",
"@types/express": "^4.17.3",
"@types/humps": "^2.0.0",
"@types/jest": "25.2.3",
"@types/joi": "^14.3.4",
"@types/jsonwebtoken": "^8.5.0",
"@types/node": "^13.9.1",
"@types/supertest": "^2.0.10",
"@typescript-eslint/eslint-plugin": "3.0.2",
"@typescript-eslint/parser": "3.0.2",
"eslint": "7.1.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-simple-import-sort": "^5.0.3",
"humps": "^2.0.1",
"husky": "^4.2.5",
"jest": "26.0.1",
"jsonwebtoken": "^8.5.1",
"lint-staged": "^10.2.11",
"mockserver-client": "^5.11.1",
"organize-imports-cli": "^0.7.0",
"prettier": "1.19.1",
"supertest": "^4.0.2",
"ts-jest": "26.1.0",
"ts-loader": "^6.2.1",
"ts-node": "^8.6.2",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.7.4"
},
Code
import { Test, TestingModule } from '@nestjs/testing';
import { AppModule } from './../src/app.module';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
describe('AppController (e2e)', () => {
let app: NestFastifyApplication;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication<NestFastifyApplication>(
new FastifyAdapter(),
);
await app.init();
});
it('GET /', () => {
console.log('HELLO');
return app.inject({
method: 'get',
url: '/',
headers: {
'Content-Type': 'application/json',
},
});
});
});
Output
AppController (e2e)
✕ GET / (399 ms)
● AppController (e2e) › GET /
TypeError: The "warning" argument must be one of type Error or string. Received type objectTypeError [ERR_INVALID_ARG_TYPE]: The "warning" argument must be one of type Error or string. Received type object
at emitWarning (../node_modules/fastify/lib/warnings.js:63:11)
at new Parser (../node_modules/fastify/lib/contentTypeParser.js:233:5)
at ContentTypeParser.add (../node_modules/fastify/lib/contentTypeParser.js:51:18)
at Object.addContentTypeParser (../node_modules/fastify/lib/contentTypeParser.js:262:30)
at ApolloServer.<anonymous> (../node_modules/apollo-server-fastify/src/ApolloServer.ts:168:22)
at ../node_modules/apollo-server-fastify/dist/ApolloServer.js:8:71
at __awaiter (../node_modules/apollo-server-fastify/dist/ApolloServer.js:4:12)
console.log
HELLO
at Object.<anonymous> (app.e2e-spec.ts:24:13)