Closed Oliboy50 closed 6 years ago
I cannot reproduce your issue locally. Could you share a repository in which this error occurs?
@kamilmysliwiec sorry, I forgot to add the Error message in the issue, I updated it now
the error message is => TypeError: Cannot read property 'create' of null
while calling app.init()
it's weird that you cannot reproduce locally, i'll try to take time to create a repo for this
@kamilmysliwiec I tried to make a reproducing project for this issue
I got something really small which was still reproducing the issue... but then I rm -rf node_modules
and update everything and the issue disappeared and I can't reproduce it again π€¦ββοΈ
So I think this has something to do with installed packages... but I'm not sure at all...
And I can't manage to fix this issue in my own project π
I'd love to hear if someone reproduce and know how to fix
Maybe just update your packages into latest versions @Oliboy50
I tried yes... but it didn't work, I have the exact same packages versions for @nestjs/*
packages installed in those 2 projects... I don't understand what could go wrong :'(
Have you tried removing node_modules
? Without reproducery repository, we cannot help too much.
π I'll make another reproducing repository when I'll have more time
@kamilmysliwiec I finished the minimal repository which reproduce the issue => https://github.com/Oliboy50/reproduce-issue-nestjs-websockets-test-e2e
Hope you will be able to tell me what's wrong with this issue π
Let's try with such test:
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { AppModule } from '../../src/app.module';
describe('SomethingController (e2e)', () => {
let app: INestApplication;
beforeAll(async () => {
const moduleFixture = await Test.createTestingModule({
imports: [AppModule],
})
// @TODO uncomment these lines to make tests green
// .overrideProvider(SomethingGateway)
// .useValue('fake provider because gateway break our tests')
.compile();
app = moduleFixture.createNestApplication();
await app.init();
});
describe(`GET`, () => {
it(`fake test`, async done => {
done();
});
});
});
with reorganized imports statements.
PASS tests/e2e/something.e2e-spec.ts
SomethingController (e2e)
GET
β fake test (1ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.628s
Ran all test suites.
^ this is my output
I believe it might be a race condition. I need to investigate this issue further
omg...
this is because I defined a moduleMapper
rule in jest config which maps every import
starting with @
to ../../src/
... and the ts-lint
rule ordered-imports
was reordering this import
statement before the @nestjs/*
imports
IMO, this should be either:
import
statements shouldn't be a problem in the first place)anyway, congrats and thank you for having spotted the bug so fast π
I let you close the issue when you think it's ok to close it
Lol. π Glad it works now! :)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
TL;DR: The issue was due to the order of the
import
statements in the test file (@nestjs/*
stuff must be imported first) π±I'm submitting a...
Current behavior
Following the E2E Testing documentation, it works perfectly well to test controllers.
But as soon as you register a websocket (using
providers
as describe in documentation), and even if no controller is registered, we end up with the following error:Expected behavior
E2E testing of the whole application should work as expected even with websockets registered. Moreover, we should be able to setup E2E testing for websockets just like we do for controllers.
Minimal reproduction of the problem with instructions
https://github.com/Oliboy50/reproduce-issue-nestjs-websockets-test-e2e
What is the motivation / use case for changing the behavior?
I don't want to have to "mock" my Websocket providers in e2e tests.
Environment