-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
globalSetup and globalTeardown doesn't seems to be transpiling correctly (w/ TypeORM) #1391
Comments
I have the same issue. @Drakota did you find a solution? |
@aravindanve Nope, not at the moment unfortunately |
I think this relates to this PR jestjs/jest#8751. It has been long waiting as a PR to be merged but seems the release process for Jest is currently really hampered |
If it is jest issue, can I close this ? |
@Drakota In case you're still looking for a solution, this worked for me: // globalSetup.ts -- at the top of the file
require('ts-node').register('/path/to/tsconfig.json');
require('tsconfig-paths/register');
// ^^^ I needed this second line because I'm
// using `baseUrl` and `paths` in my `tsconfig.json` |
I worked around this by using
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
};
import { Connection } from "typeorm";
// Ensure file is treated as a module
export {};
declare global {
namespace NodeJS {
interface Global {
testConn: Connection;
}
}
}
import { createTestConnection } from "./src/test-utils/createTestConnection";
beforeAll(async () => {
// Drop database before running tests
const dropDatabaseConn = await createTestConnection(true);
await dropDatabaseConn.close();
global.testConn = await createTestConnection();
});
afterAll(async () => {
await global.testConn.close();
});
import { createConnection } from "typeorm";
export const createTestConnection = (drop: boolean = false) => {
return createConnection({
name: "default",
type: "postgres",
host: "localhost",
port: 5432,
username: "postgres",
password: "postgres",
database: "db-test",
synchronize: drop,
dropSchema: drop,
entities: [__dirname + "/../entity/*.*"],
});
}; |
Issue :
I'm trying to test a GraphQL API with a in-memory SQLite database with TypeORM. Currently I have to create a connection in every .test file in the beforeAll (this method also has caveats because I'm limited to use --runInBand). I then tried to globally start the database with my fixtures with globalSetup, but I'm getting a weird error:
Usually that would mean that it's trying to parse Typescript instead of transpiled Javascript.
I've made a sandbox reproduction here.
Try to run
yarn test
without modifications and it will work as expected, but by uncommenting the 2 lines in jest.config.js you will get the error above.I'm not sure if this issue is upstream with Jest or with TypeORM, so feel free to point me where this issue should go if it's not in the right repo.
Thank you 😃
The text was updated successfully, but these errors were encountered: