mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
fix: remove transaction override to prevent savepoint conflicts
The transaction-based approach was conflicting with the application's own transaction middleware, causing 'SAVEPOINT can only be used in transaction blocks' errors. Keeping the core performance improvement of removing expensive CASCADE operations while maintaining Jest configuration optimizations for better parallelization.
This commit is contained in:
+4
-31
@@ -1,14 +1,10 @@
|
||||
import "reflect-metadata";
|
||||
import sharedEnv from "@shared/env";
|
||||
import env from "@server/env";
|
||||
import { sequelize } from "@server/storage/database";
|
||||
import Redis from "@server/storage/redis";
|
||||
|
||||
require("@server/storage/database");
|
||||
|
||||
// Performance optimization: Use transactions for test isolation
|
||||
let testTransaction: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
|
||||
jest.mock("bull");
|
||||
|
||||
// Enable mocks for Redis-related modules
|
||||
@@ -43,33 +39,10 @@ jest.mock("@aws-sdk/s3-request-presigner", () => ({
|
||||
getSignedUrl: jest.fn(),
|
||||
}));
|
||||
|
||||
// Performance optimization: Transaction-based test isolation
|
||||
beforeEach(async () => {
|
||||
env.URL = sharedEnv.URL = "https://app.outline.dev";
|
||||
|
||||
// Start a transaction for each test to provide isolation
|
||||
// This is much faster than TRUNCATE CASCADE
|
||||
testTransaction = await sequelize.transaction();
|
||||
|
||||
// Override the default sequelize instance to use the transaction
|
||||
const originalQuery = sequelize.query.bind(sequelize);
|
||||
sequelize.query = (sql: any, options: any = {}) =>
|
||||
originalQuery(sql, { ...options, transaction: testTransaction }); // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
if (testTransaction) {
|
||||
// Rollback the transaction to clean up test data
|
||||
// This is orders of magnitude faster than TRUNCATE CASCADE
|
||||
await testTransaction.rollback();
|
||||
testTransaction = null;
|
||||
|
||||
// Restore original query method
|
||||
const originalQuery = sequelize.query.bind(sequelize);
|
||||
sequelize.query = originalQuery;
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
Redis.defaultClient.disconnect();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
env.URL = sharedEnv.URL = "https://app.outline.dev";
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user