jeudi 3 octobre 2019

Sql driver can't be found in e2e test of NestJs with in memory database

I have NestJs application with TypeORM configured with mysql. I want to have e2e(integration) test and for that reason I want to have in memory database in the tests which I configured this way:

{
    type: 'sqlite',
    database: ':memory:',
    synchronize: true,
    dropSchema: true,
    entities: [`dist/**/*.entity{.ts,.js}`],
}

. When running the test I got

DriverPackageNotInstalledError: SQLite package has not been found installed. Try to install it: npm install sqlite3 --save
    at new DriverPackageNotInstalledError (/Users/user/workspace/app/src/error/DriverPackageNotInstalledError.ts:8:9)
    at SqliteDriver.Object.<anonymous>.SqliteDriver.loadDependencies (/Users/user/workspace/app/src/driver/sqlite/SqliteDriver.ts:129:10)
    at new SqliteDriver (/Users/user/workspace/app/src/driver/sqlite/SqliteDriver.ts:46:14)
    at DriverFactory.Object.<anonymous>.DriverFactory.create (/Users/user/workspace/app/src/driver/DriverFactory.ts:39:18)
    at new Connection (/Users/user/workspace/app/src/connection/Connection.ts:125:43)
    at ConnectionManager.Object.<anonymous>.ConnectionManager.create (/Users/user/workspace/app/src/connection/ConnectionManager.ts:64:28)
    at Object.<anonymous> (/Users/user/workspace/app/src/index.ts:228:35)
    at step (/Users/user/workspace/app/node_modules/tslib/tslib.js:136:27)
    at Object.next (/Users/user/workspace/app/node_modules/tslib/tslib.js:117:57)
    at /Users/user/workspace/app/node_modules/tslib/tslib.js:110:75

All required dependencies including sqlite3 are installed. Starting the server with the same config works, it only fails during the tests. Should be either config issue or build (if there is difference between nestjs app build and jest tests). Any help appreciated.

Aucun commentaire:

Enregistrer un commentaire