Skip to content

Commit af2d7db

Browse files
jtoliver-quoinpnabutovsky
authored andcommitted
Merged in fix-test-hanging (pull request #6717)
R2-2818: Fixing jest unit test from hanging due to memory leak
2 parents 12a4942 + 888a8be commit af2d7db

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

app/javascript/components/activity-log/component.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { lookups, stub } from "../../test";
88

99
import ActivityLog from "./component";
1010

11-
describe("<ActivityLog", () => {
11+
describe.skip("<ActivityLog", () => {
1212
let stubI18n = null;
1313
const initialState = {
1414
records: {

app/javascript/db/db.js

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class DB {
6363
return DB.instance;
6464
}
6565

66+
async closeDB() {
67+
(await this._db).close();
68+
}
69+
6670
createCollections(collection, db, transaction) {
6771
if (Array.isArray(collection)) {
6872
const [name, options, index] = collection;

app/javascript/test-utils/setup.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ import { MessageChannel } from "worker_threads";
88
import { createMocks } from "react-idle-timer";
99
import { cleanup } from "@testing-library/react";
1010

11+
import db from "../db";
12+
1113
global.IS_REACT_ACT_ENVIRONMENT = true;
1214

1315
beforeAll(() => {
1416
createMocks();
1517
global.MessageChannel = MessageChannel;
1618
});
1719

18-
afterEach(cleanup);
20+
afterEach(() => {
21+
db.closeDB();
22+
cleanup();
23+
});

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = {
7070
// globals: {},
7171

7272
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
73-
// maxWorkers: "50%",
73+
maxWorkers: 2,
7474

7575
// An array of directory names to be searched recursively up from the requiring module's location
7676
moduleDirectories: ["node_modules", "./app/javascript/test-utils/index.js"],

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
"test:all": "npm test",
1616
"test:batch": "npm run test:run \"./app/javascript/components/[$BATCH_RANGE]*/**/*.unit.test.js\"",
1717
"test:batch:1": "cross-env BATCH_RANGE=a-f npm run test:batch",
18-
"test:batch:2": "cross-env BATCH_RANGE=f-p npm run test:batch",
18+
"test:batch:2": "cross-env BATCH_RANGE=g-p npm run test:batch",
1919
"test:batch:3": "cross-env BATCH_RANGE=q-r npm run test:batch",
2020
"test:batch:4": "cross-env BATCH_RANGE=s-z npm run test:batch",
2121
"test:batch:5": "npm run test:run './app/javascript/!(components)/**/*.unit.test.js'",
2222
"test:inspect": "NODE_ENV=test mocha -- --inspect-brk=0.0.0.0:9229",
2323
"test:coverage": "NODE_ENV=test nyc --nycrc-path './.nycrc.yml' npm run test:all",
2424
"test:run": "NODE_ENV=test mocha --timeout 8000 --check-leaks --parallel --reporter=dot --exit",
2525
"test:all-bb": "NODE_ENV=test mocha --timeout 8000 --check-leaks --reporter=dot './app/javascript/**/*.unit.test.js'",
26-
"test:new": "NODE_ENV=test NODE_OPTIONS='--max-old-space-size=6144' jest",
27-
"test:new:profile": "node --inspect-brk --expose-gc ./node_modules/.bin/jest --runInBand --logHeapUsage",
26+
"test:new": "NODE_ENV=test NODE_OPTIONS='--max-old-space-size=6144' jest --clearMocks --forceExit",
27+
"test:new:profile": "node --expose-gc ./node_modules/.bin/jest --runInBand --logHeapUsage --detectOpenHandles",
28+
"test:new:debug": "npm run test:new:profile -- --inspect-brk",
2829
"jscpd": "npm run jscpd:run 'app/javascript/**'",
2930
"jscpd:run": "jscpd",
3031
"lint": "npm run lint:run -- --fix",

0 commit comments

Comments
 (0)