-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Issue description
A 'Segmentation fault' error occurs when trying to initialize a SQLite database via TypeORM within a Jest test file.
Expected Behavior
Execution of test script (eg. jest) successfully executes setup, teardown, and test case.
Actual Behavior
Test script execution outputs segmentation fault error.
# output:
$ jest
RUNS ./db.test.ts
Segmentation faultSteps to reproduce
Please visit the following sandbox to reproduce error: https://codesandbox.io/p/sandbox/jest-typeorm-sigsegv-xg5gx6
My Environment
- note: for version column, first values represent versions in original repo and second values represent versions in codesandbox created to showcase bug
| Dependency | Version |
|---|---|
| Operating System | Ventura 13.2.1 & unknown |
| Node.js version | 18.12.1 & 18.16.0 |
| Typescript version | ^5.0.2 & ^5.1.6 |
| TypeORM version | ^0.3.16 & ^0.3.17 |
Additional Context
About the issue
A 'Segmentation fault' error occurs when trying to initialize a SQLite database via TypeORM within a Jest test file.
More especifically, it appears the value for 'entities' property in DataSource's constructor is related to the error. If an array containing a directory path is provided as value, error will surface. Otherwise, if an array containing an entity class is provided, test will execute successfully.
Note: Issue is present whether storing SQLite in-memory or disk file.
Workaround
Pass entity classes as argument, not directories, to DataSource's entities option.
import { MyEntity } from "./entities/MyEntity.ts";
// ...
- entities: ["entities/*.ts"],
+ entities: [MyEntity]Relevant Database Driver(s)
- aurora-mysql
- aurora-postgres
- better-sqlite3
- cockroachdb
- cordova
- expo
- mongodb
- mysql
- nativescript
- oracle
- postgres
- react-native
- sap
- spanner
- sqlite
- sqlite-abstract
- sqljs
- sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, but I don't know how to start. I would need guidance.