jest-doctor 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/consts.d.ts +2 -0
  2. package/dist/consts.js +6 -0
  3. package/dist/consts.js.map +1 -0
  4. package/dist/createEnvMixin.d.ts +69 -0
  5. package/dist/createEnvMixin.js +137 -0
  6. package/dist/createEnvMixin.js.map +1 -0
  7. package/dist/env/jsdom.d.ts +47 -0
  8. package/dist/env/jsdom.js +8 -0
  9. package/dist/env/jsdom.js.map +1 -0
  10. package/dist/env/node.d.ts +47 -0
  11. package/dist/env/node.js +8 -0
  12. package/dist/env/node.js.map +1 -0
  13. package/dist/patch/console.d.ts +4 -0
  14. package/dist/patch/console.js +37 -0
  15. package/dist/patch/console.js.map +1 -0
  16. package/dist/patch/fakeTimers.d.ts +3 -0
  17. package/dist/patch/fakeTimers.js +66 -0
  18. package/dist/patch/fakeTimers.js.map +1 -0
  19. package/dist/patch/hook.d.ts +3 -0
  20. package/dist/patch/hook.js +24 -0
  21. package/dist/patch/hook.js.map +1 -0
  22. package/dist/patch/it.d.ts +3 -0
  23. package/dist/patch/it.js +31 -0
  24. package/dist/patch/it.js.map +1 -0
  25. package/dist/patch/promise.d.ts +3 -0
  26. package/dist/patch/promise.js +35 -0
  27. package/dist/patch/promise.js.map +1 -0
  28. package/dist/patch/timers.d.ts +3 -0
  29. package/dist/patch/timers.js +63 -0
  30. package/dist/patch/timers.js.map +1 -0
  31. package/dist/reporter.d.ts +16 -0
  32. package/dist/reporter.js +150 -0
  33. package/dist/reporter.js.map +1 -0
  34. package/dist/requireEnvironment.d.ts +48 -0
  35. package/dist/requireEnvironment.js +21 -0
  36. package/dist/requireEnvironment.js.map +1 -0
  37. package/dist/types.d.ts +104 -0
  38. package/dist/types.js +3 -0
  39. package/dist/types.js.map +1 -0
  40. package/dist/utils/analyzeCallback.d.ts +4 -0
  41. package/dist/utils/analyzeCallback.js +29 -0
  42. package/dist/utils/analyzeCallback.js.map +1 -0
  43. package/dist/utils/cleanupAfterTest.d.ts +3 -0
  44. package/dist/utils/cleanupAfterTest.js +25 -0
  45. package/dist/utils/cleanupAfterTest.js.map +1 -0
  46. package/dist/utils/createAsyncHookCleaner.d.ts +3 -0
  47. package/dist/utils/createAsyncHookCleaner.js +16 -0
  48. package/dist/utils/createAsyncHookCleaner.js.map +1 -0
  49. package/dist/utils/createAsyncHookDetector.d.ts +3 -0
  50. package/dist/utils/createAsyncHookDetector.js +22 -0
  51. package/dist/utils/createAsyncHookDetector.js.map +1 -0
  52. package/dist/utils/getAllAfterEach.d.ts +3 -0
  53. package/dist/utils/getAllAfterEach.js +15 -0
  54. package/dist/utils/getAllAfterEach.js.map +1 -0
  55. package/dist/utils/getReporterTmpDir.d.ts +3 -0
  56. package/dist/utils/getReporterTmpDir.js +23 -0
  57. package/dist/utils/getReporterTmpDir.js.map +1 -0
  58. package/dist/utils/initLeakRecord.d.ts +3 -0
  59. package/dist/utils/initLeakRecord.js +19 -0
  60. package/dist/utils/initLeakRecord.js.map +1 -0
  61. package/dist/utils/initOriginal.d.ts +15 -0
  62. package/dist/utils/initOriginal.js +18 -0
  63. package/dist/utils/initOriginal.js.map +1 -0
  64. package/dist/utils/normalizeOptions.d.ts +3 -0
  65. package/dist/utils/normalizeOptions.js +66 -0
  66. package/dist/utils/normalizeOptions.js.map +1 -0
  67. package/dist/utils/reportLeaks.d.ts +3 -0
  68. package/dist/utils/reportLeaks.js +76 -0
  69. package/dist/utils/reportLeaks.js.map +1 -0
  70. package/package.json +2 -2
@@ -0,0 +1,2 @@
1
+ export declare const MAIN_THREAD = "main-thread";
2
+ export declare const REPORTER_TMP_DIR = ".tmp";
package/dist/consts.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REPORTER_TMP_DIR = exports.MAIN_THREAD = void 0;
4
+ exports.MAIN_THREAD = 'main-thread';
5
+ exports.REPORTER_TMP_DIR = '.tmp';
6
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,aAAa,CAAC;AAE5B,QAAA,gBAAgB,GAAG,MAAM,CAAC"}
@@ -0,0 +1,69 @@
1
+ import type { EnvironmentContext, JestEnvironment, JestEnvironmentConfig } from '@jest/environment';
2
+ import type { AsyncHook } from 'node:async_hooks';
3
+ import type { LeakRecord, NormalizedOptions } from './types';
4
+ import { Circus } from '@jest/types';
5
+ import type { LegacyFakeTimers, ModernFakeTimers } from '@jest/fake-timers';
6
+ import type { ModuleMocker } from 'jest-mock';
7
+ import type { Context } from 'node:vm';
8
+ interface JestDoctor {
9
+ handleEvent?(event: Circus.AsyncEvent | Circus.SyncEvent, state: Circus.State): Promise<void>;
10
+ global: JestEnvironment['global'];
11
+ fakeTimers: LegacyFakeTimers<unknown> | null;
12
+ fakeTimersModern: ModernFakeTimers | null;
13
+ moduleMocker: ModuleMocker | null;
14
+ getVmContext: () => Context | null;
15
+ exportConditions: (() => Array<string>) | undefined;
16
+ setup(): Promise<void>;
17
+ teardown(): Promise<void>;
18
+ handleTestEvent?: Circus.EventHandler;
19
+ }
20
+ export interface JestDoctorConstructor {
21
+ new (config: JestEnvironmentConfig, context: EnvironmentContext): JestDoctor;
22
+ }
23
+ declare const createEnvMixin: <EnvironmentConstructor extends JestDoctorConstructor>(Environment: EnvironmentConstructor) => {
24
+ new (config: JestEnvironmentConfig, context: EnvironmentContext): {
25
+ currentTestName: string;
26
+ readonly leakRecords: Map<string, LeakRecord>;
27
+ readonly original: {
28
+ setTimeout: typeof setTimeout;
29
+ clearTimeout: typeof clearTimeout;
30
+ setInterval: typeof setInterval;
31
+ clearInterval: typeof clearInterval;
32
+ console: {
33
+ log: (message?: any, ...optionalParams: any[]) => void;
34
+ info: (message?: any, ...optionalParams: any[]) => void;
35
+ warn: (message?: any, ...optionalParams: any[]) => void;
36
+ error: (message?: any, ...optionalParams: any[]) => void;
37
+ debug: (message?: any, ...optionalParams: any[]) => void;
38
+ trace: (message?: any, ...optionalParams: any[]) => void;
39
+ };
40
+ };
41
+ readonly promiseOwner: Map<number, string>;
42
+ readonly asyncHookDetector?: AsyncHook;
43
+ readonly asyncHookCleaner?: AsyncHook;
44
+ readonly options: NormalizedOptions;
45
+ seenTearDown: boolean;
46
+ currentAfterEachCount: number;
47
+ readonly reporterTmpDir: string;
48
+ readonly testPath: string;
49
+ readonly aggregatedReport: {
50
+ testPath: string;
51
+ promises: number;
52
+ timers: number;
53
+ fakeTimers: number;
54
+ console: number;
55
+ totalDelay: number;
56
+ };
57
+ setup(): Promise<void>;
58
+ handleEvent(event: unknown, state: unknown): Promise<void>;
59
+ handleTestEvent: JestEnvironment["handleTestEvent"];
60
+ teardown(): Promise<void>;
61
+ global: JestEnvironment["global"];
62
+ fakeTimers: LegacyFakeTimers<unknown> | null;
63
+ fakeTimersModern: ModernFakeTimers | null;
64
+ moduleMocker: ModuleMocker | null;
65
+ getVmContext: () => Context | null;
66
+ exportConditions: (() => Array<string>) | undefined;
67
+ };
68
+ } & EnvironmentConstructor;
69
+ export default createEnvMixin;
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ // noinspection JSPotentiallyInvalidUsageOfThis
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const node_fs_1 = require("node:fs");
9
+ const console_1 = __importDefault(require("./patch/console"));
10
+ const initOriginal_1 = __importDefault(require("./utils/initOriginal"));
11
+ const fakeTimers_1 = __importDefault(require("./patch/fakeTimers"));
12
+ const consts_1 = require("./consts");
13
+ const timers_1 = __importDefault(require("./patch/timers"));
14
+ const it_1 = __importDefault(require("./patch/it"));
15
+ const createAsyncHookDetector_1 = __importDefault(require("./utils/createAsyncHookDetector"));
16
+ const createAsyncHookCleaner_1 = __importDefault(require("./utils/createAsyncHookCleaner"));
17
+ const reportLeaks_1 = __importDefault(require("./utils/reportLeaks"));
18
+ const cleanupAfterTest_1 = __importDefault(require("./utils/cleanupAfterTest"));
19
+ const initLeakRecord_1 = __importDefault(require("./utils/initLeakRecord"));
20
+ const hook_1 = __importDefault(require("./patch/hook"));
21
+ const getAllAfterEach_1 = __importDefault(require("./utils/getAllAfterEach"));
22
+ const normalizeOptions_1 = __importDefault(require("./utils/normalizeOptions"));
23
+ const getReporterTmpDir_1 = __importDefault(require("./utils/getReporterTmpDir"));
24
+ const promise_1 = __importDefault(require("./patch/promise"));
25
+ const createEnvMixin = (Environment) => {
26
+ // @ts-expect-error strange ts rule where constructor arguments should be any[] where again TypeScript complains
27
+ return class Base extends Environment {
28
+ currentTestName = consts_1.MAIN_THREAD;
29
+ leakRecords = new Map();
30
+ original = (0, initOriginal_1.default)();
31
+ promiseOwner = new Map();
32
+ asyncHookDetector;
33
+ asyncHookCleaner;
34
+ options;
35
+ seenTearDown = false;
36
+ currentAfterEachCount = 0;
37
+ reporterTmpDir;
38
+ testPath;
39
+ aggregatedReport;
40
+ constructor(config, context) {
41
+ super(config, context);
42
+ this.testPath = context.testPath.replace(/\W/g, '_');
43
+ this.aggregatedReport = {
44
+ testPath: context.testPath,
45
+ promises: 0,
46
+ timers: 0,
47
+ fakeTimers: 0,
48
+ console: 0,
49
+ totalDelay: 0,
50
+ };
51
+ const tmpDir = (0, getReporterTmpDir_1.default)(config.projectConfig.reporters);
52
+ this.reporterTmpDir = tmpDir
53
+ ? node_path_1.default.join(tmpDir, config.globalConfig.seed.toString(), this.testPath + 'json')
54
+ : '';
55
+ this.options = (0, normalizeOptions_1.default)(config.projectConfig.testEnvironmentOptions);
56
+ (0, initLeakRecord_1.default)(this, consts_1.MAIN_THREAD);
57
+ if (this.options.report.promises &&
58
+ this.options.report.promises.patch === 'async_hooks') {
59
+ this.asyncHookCleaner = (0, createAsyncHookCleaner_1.default)(this);
60
+ this.asyncHookDetector = (0, createAsyncHookDetector_1.default)(this);
61
+ }
62
+ }
63
+ async setup() {
64
+ await super.setup();
65
+ const report = this.options.report;
66
+ if (report.fakeTimers) {
67
+ (0, fakeTimers_1.default)(this);
68
+ }
69
+ // always patch to be able to clean them
70
+ (0, timers_1.default)(this);
71
+ if (report.console) {
72
+ (0, console_1.default)(this, report.console);
73
+ }
74
+ if (report.promises && report.promises.patch === 'promise') {
75
+ (0, promise_1.default)(this);
76
+ }
77
+ }
78
+ // unfortunately @jest/types doesn't export the necessary types,
79
+ // so it breaks if public types are exposed and build with declaration enabled
80
+ async handleEvent(event, state) {
81
+ const circusEvent = event;
82
+ const circusState = state;
83
+ if (circusEvent.name === 'test_start') {
84
+ if (this.options.timerIsolation === 'afterEach') {
85
+ this.currentAfterEachCount = (0, getAllAfterEach_1.default)(circusEvent.test.parent);
86
+ }
87
+ }
88
+ else if (circusEvent.name === 'teardown') {
89
+ // the detector needs to be disabled here to avoid the teardown promise polluting the report
90
+ this.asyncHookDetector?.disable();
91
+ this.seenTearDown = true;
92
+ }
93
+ else if (circusEvent.name === 'setup') {
94
+ this.asyncHookCleaner?.enable();
95
+ this.asyncHookDetector?.enable();
96
+ (0, it_1.default)(this);
97
+ (0, hook_1.default)(this, 'beforeEach');
98
+ (0, hook_1.default)(this, 'beforeAll');
99
+ (0, hook_1.default)(this, 'afterEach');
100
+ (0, hook_1.default)(this, 'afterAll');
101
+ }
102
+ await super.handleEvent?.(circusEvent, circusState);
103
+ }
104
+ handleTestEvent = async (event, state) => {
105
+ return this.handleEvent(event, state);
106
+ };
107
+ async teardown() {
108
+ await super.teardown();
109
+ const leakRecord = this.leakRecords.get(consts_1.MAIN_THREAD);
110
+ try {
111
+ // in case jest discovers an error all following events will be skipped
112
+ // and teardown is executed immediately
113
+ if (this.seenTearDown) {
114
+ (0, reportLeaks_1.default)(this, leakRecord);
115
+ }
116
+ }
117
+ finally {
118
+ (0, cleanupAfterTest_1.default)(this, leakRecord, consts_1.MAIN_THREAD);
119
+ this.asyncHookCleaner?.disable();
120
+ // this is added here for safety reasons,
121
+ // because jest could abort and dont hit teardown event
122
+ this.asyncHookDetector?.disable();
123
+ const hasLeak = this.aggregatedReport.promises +
124
+ this.aggregatedReport.timers +
125
+ this.aggregatedReport.fakeTimers +
126
+ this.aggregatedReport.console +
127
+ this.aggregatedReport.totalDelay;
128
+ if (this.reporterTmpDir && hasLeak) {
129
+ // needs to be sync or will be terminated by jest when an error occurs
130
+ (0, node_fs_1.writeFileSync)(this.reporterTmpDir, JSON.stringify(this.aggregatedReport));
131
+ }
132
+ }
133
+ }
134
+ };
135
+ };
136
+ exports.default = createEnvMixin;
137
+ //# sourceMappingURL=createEnvMixin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createEnvMixin.js","sourceRoot":"","sources":["../src/createEnvMixin.ts"],"names":[],"mappings":";AAAA,+CAA+C;;;;;AAQ/C,0DAA6B;AAC7B,qCAAwC;AAQxC,8DAA2C;AAC3C,wEAAgD;AAChD,oEAAiD;AACjD,qCAAuC;AACvC,4DAAoC;AACpC,oDAAiC;AACjC,8FAAsE;AACtE,4FAAoE;AACpE,sEAA8C;AAC9C,gFAAwD;AACxD,4EAAoD;AACpD,wDAAqC;AACrC,8EAAsD;AACtD,gFAAwD;AACxD,kFAA0D;AAC1D,8DAA2C;AA0B3C,MAAM,cAAc,GAAG,CACrB,WAAmC,EACnC,EAAE;IACF,gHAAgH;IAChH,OAAO,MAAM,IAAK,SAAQ,WAAW;QAC5B,eAAe,GAAW,oBAAW,CAAC;QAC7B,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;QAC5C,QAAQ,GAAG,IAAA,sBAAY,GAAE,CAAC;QAC1B,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;QACzC,iBAAiB,CAAa;QAC9B,gBAAgB,CAAa;QAC7B,OAAO,CAAoB;QACpC,YAAY,GAAG,KAAK,C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B,IAAI,CAAC,gBAAgB,CAAC,UAAU;oBAChC,IAAI,CAAC,gBAAgB,CAAC,OAAO;oBAC7B,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC;gBAEnC,IAAI,IAAI,CAAC,cAAc,IAAI,OAAO,EAAE,CAAC;oBACnC,sEAAsE;oBACtE,IAAA,uBAAa,EACX,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CACtC,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,cAAc,CAAC"}
@@ -0,0 +1,47 @@
1
+ declare const _default: {
2
+ new (config: import("@jest/environment").JestEnvironmentConfig, context: import("@jest/environment").EnvironmentContext): {
3
+ currentTestName: string;
4
+ readonly leakRecords: Map<string, import("../types").LeakRecord>;
5
+ readonly original: {
6
+ setTimeout: typeof setTimeout;
7
+ clearTimeout: typeof clearTimeout;
8
+ setInterval: typeof setInterval;
9
+ clearInterval: typeof clearInterval;
10
+ console: {
11
+ log: (message?: any, ...optionalParams: any[]) => void;
12
+ info: (message?: any, ...optionalParams: any[]) => void;
13
+ warn: (message?: any, ...optionalParams: any[]) => void;
14
+ error: (message?: any, ...optionalParams: any[]) => void;
15
+ debug: (message?: any, ...optionalParams: any[]) => void;
16
+ trace: (message?: any, ...optionalParams: any[]) => void;
17
+ };
18
+ };
19
+ readonly promiseOwner: Map<number, string>;
20
+ readonly asyncHookDetector?: import("async_hooks").AsyncHook;
21
+ readonly asyncHookCleaner?: import("async_hooks").AsyncHook;
22
+ readonly options: import("../types").NormalizedOptions;
23
+ seenTearDown: boolean;
24
+ currentAfterEachCount: number;
25
+ readonly reporterTmpDir: string;
26
+ readonly testPath: string;
27
+ readonly aggregatedReport: {
28
+ testPath: string;
29
+ promises: number;
30
+ timers: number;
31
+ fakeTimers: number;
32
+ console: number;
33
+ totalDelay: number;
34
+ };
35
+ setup(): Promise<void>;
36
+ handleEvent(event: unknown, state: unknown): Promise<void>;
37
+ handleTestEvent: import("@jest/environment").JestEnvironment["handleTestEvent"];
38
+ teardown(): Promise<void>;
39
+ global: import("@jest/environment").JestEnvironment["global"];
40
+ fakeTimers: import("@jest/fake-timers").LegacyFakeTimers<unknown> | null;
41
+ fakeTimersModern: import("@jest/fake-timers").ModernFakeTimers | null;
42
+ moduleMocker: import("jest-mock").ModuleMocker | null;
43
+ getVmContext: () => import("vm").Context | null;
44
+ exportConditions: (() => Array<string>) | undefined;
45
+ };
46
+ } & import("../createEnvMixin").JestDoctorConstructor;
47
+ export default _default;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const requireEnvironment_1 = __importDefault(require("../requireEnvironment"));
7
+ exports.default = (0, requireEnvironment_1.default)('jest-environment-jsdom');
8
+ //# sourceMappingURL=jsdom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsdom.js","sourceRoot":"","sources":["../../src/env/jsdom.ts"],"names":[],"mappings":";;;;;AAAA,+EAAuD;AAEvD,kBAAe,IAAA,4BAAkB,EAAC,wBAAwB,CAAC,CAAC"}
@@ -0,0 +1,47 @@
1
+ declare const _default: {
2
+ new (config: import("@jest/environment").JestEnvironmentConfig, context: import("@jest/environment").EnvironmentContext): {
3
+ currentTestName: string;
4
+ readonly leakRecords: Map<string, import("../types").LeakRecord>;
5
+ readonly original: {
6
+ setTimeout: typeof setTimeout;
7
+ clearTimeout: typeof clearTimeout;
8
+ setInterval: typeof setInterval;
9
+ clearInterval: typeof clearInterval;
10
+ console: {
11
+ log: (message?: any, ...optionalParams: any[]) => void;
12
+ info: (message?: any, ...optionalParams: any[]) => void;
13
+ warn: (message?: any, ...optionalParams: any[]) => void;
14
+ error: (message?: any, ...optionalParams: any[]) => void;
15
+ debug: (message?: any, ...optionalParams: any[]) => void;
16
+ trace: (message?: any, ...optionalParams: any[]) => void;
17
+ };
18
+ };
19
+ readonly promiseOwner: Map<number, string>;
20
+ readonly asyncHookDetector?: import("async_hooks").AsyncHook;
21
+ readonly asyncHookCleaner?: import("async_hooks").AsyncHook;
22
+ readonly options: import("../types").NormalizedOptions;
23
+ seenTearDown: boolean;
24
+ currentAfterEachCount: number;
25
+ readonly reporterTmpDir: string;
26
+ readonly testPath: string;
27
+ readonly aggregatedReport: {
28
+ testPath: string;
29
+ promises: number;
30
+ timers: number;
31
+ fakeTimers: number;
32
+ console: number;
33
+ totalDelay: number;
34
+ };
35
+ setup(): Promise<void>;
36
+ handleEvent(event: unknown, state: unknown): Promise<void>;
37
+ handleTestEvent: import("@jest/environment").JestEnvironment["handleTestEvent"];
38
+ teardown(): Promise<void>;
39
+ global: import("@jest/environment").JestEnvironment["global"];
40
+ fakeTimers: import("@jest/fake-timers").LegacyFakeTimers<unknown> | null;
41
+ fakeTimersModern: import("@jest/fake-timers").ModernFakeTimers | null;
42
+ moduleMocker: import("jest-mock").ModuleMocker | null;
43
+ getVmContext: () => import("vm").Context | null;
44
+ exportConditions: (() => Array<string>) | undefined;
45
+ };
46
+ } & import("../createEnvMixin").JestDoctorConstructor;
47
+ export default _default;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const requireEnvironment_1 = __importDefault(require("../requireEnvironment"));
7
+ exports.default = (0, requireEnvironment_1.default)('jest-environment-node');
8
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/env/node.ts"],"names":[],"mappings":";;;;;AAAA,+EAAuD;AAEvD,kBAAe,IAAA,4BAAkB,EAAC,uBAAuB,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { JestDoctorEnvironment, ConsoleOptions } from '../types';
2
+ export declare const isIgnored: (message: string, ignorePatterns: ConsoleOptions["ignore"]) => boolean;
3
+ declare const patchConsole: (that: JestDoctorEnvironment, consoleOptions: ConsoleOptions) => void;
4
+ export default patchConsole;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isIgnored = void 0;
7
+ const node_util_1 = require("node:util");
8
+ const getStack_1 = __importDefault(require("../utils/getStack"));
9
+ const isIgnored = (message, ignorePatterns) => {
10
+ return ignorePatterns.some((pattern) => {
11
+ if (typeof pattern === 'string') {
12
+ return message.includes(pattern);
13
+ }
14
+ return pattern.test(message);
15
+ });
16
+ };
17
+ exports.isIgnored = isIgnored;
18
+ const patchConsole = (that, consoleOptions) => {
19
+ const env = that.global;
20
+ for (const consoleMethod of consoleOptions.methods) {
21
+ const originalMethod = env.console[consoleMethod].bind(env.console);
22
+ env.console[consoleMethod] = (...args) => {
23
+ const message = (0, node_util_1.format)(...args);
24
+ if (!(0, exports.isIgnored)(message, consoleOptions.ignore)) {
25
+ that.leakRecords.get(that.currentTestName)?.console.push({
26
+ method: consoleMethod,
27
+ stack: (0, getStack_1.default)(env.console[consoleMethod]),
28
+ testName: that.currentTestName,
29
+ message,
30
+ });
31
+ }
32
+ return originalMethod(...args);
33
+ };
34
+ }
35
+ };
36
+ exports.default = patchConsole;
37
+ //# sourceMappingURL=console.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/patch/console.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAmC;AAEnC,iEAAyC;AAElC,MAAM,SAAS,GAAG,CACvB,OAAe,EACf,cAAwC,EAC/B,EAAE;IACX,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACrC,IAAI,OAAO,OAAO,KA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default patchFakeTimers;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_console_1 = __importDefault(require("node:console"));
7
+ const getStack_1 = __importDefault(require("../utils/getStack"));
8
+ const patchFakeTimers = (that) => {
9
+ const modernFakeTimers = that.fakeTimersModern;
10
+ const fakeTimers = modernFakeTimers?._fakeTimers;
11
+ const originalFakeTimerInstall = fakeTimers?.install;
12
+ if (fakeTimers && originalFakeTimerInstall) {
13
+ const originalClearAllTimers = modernFakeTimers.clearAllTimers.bind(modernFakeTimers);
14
+ modernFakeTimers.clearAllTimers = () => {
15
+ that.leakRecords.get(that.currentTestName)?.fakeTimers.clear();
16
+ originalClearAllTimers();
17
+ };
18
+ fakeTimers.install = (config) => {
19
+ const clock = originalFakeTimerInstall(config);
20
+ const originalFakeSetTimeout = clock.setTimeout.bind(clock);
21
+ const originalFakeSetInterval = clock.setInterval.bind(clock);
22
+ const originalFakeClearTimeout = clock.clearTimeout.bind(clock);
23
+ const originalFakeClearInterval = clock.clearInterval.bind(clock);
24
+ clock.setTimeout = function (callback, delay) {
25
+ const fakeTimeout = that.leakRecords.get(that.currentTestName)?.fakeTimers;
26
+ const timerId = originalFakeSetTimeout(() => {
27
+ fakeTimeout?.delete(timerId);
28
+ callback();
29
+ }, delay);
30
+ fakeTimeout?.set(timerId, {
31
+ type: 'fakeTimeout',
32
+ delay: delay || 0,
33
+ stack: (0, getStack_1.default)(that.global.setTimeout),
34
+ testName: that.currentTestName,
35
+ });
36
+ return timerId;
37
+ };
38
+ clock.setInterval = function (callback, delay) {
39
+ const intervalId = originalFakeSetInterval(callback, delay);
40
+ that.leakRecords.get(that.currentTestName)?.fakeTimers.set(intervalId, {
41
+ type: 'fakeInterval',
42
+ delay: delay || 0,
43
+ stack: (0, getStack_1.default)(that.global.setInterval),
44
+ testName: that.currentTestName,
45
+ });
46
+ return intervalId;
47
+ };
48
+ clock.clearTimeout = (timerId) => {
49
+ that.leakRecords.get(that.currentTestName)?.fakeTimers.delete(timerId);
50
+ originalFakeClearTimeout(timerId);
51
+ };
52
+ clock.clearInterval = (intervalId) => {
53
+ that.leakRecords
54
+ .get(that.currentTestName)
55
+ ?.fakeTimers.delete(intervalId);
56
+ originalFakeClearInterval(intervalId);
57
+ };
58
+ return clock;
59
+ };
60
+ }
61
+ else {
62
+ node_console_1.default.warn('Fake timers could not be mocked!');
63
+ }
64
+ };
65
+ exports.default = patchFakeTimers;
66
+ //# sourceMappingURL=fakeTimers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fakeTimers.js","sourceRoot":"","sources":["../../src/patch/fakeTimers.ts"],"names":[],"mappings":";;;;;AAAA,gEAAmC;AAEnC,iEAAyC;AAEzC,MAAM,eAAe,GAAG,CAAC,IAA2B,EAAE,EAAE;IACtD,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAyC,CAAC;IACxE,MAAM,UAAU,GAAG,gBAAgB,EAAE,WAAW,CAAC;IACjD,MAAM,wBAAwB,GAAG,UAAU,EAAE,OAAO,CAAC;IAErD,IAAI,UAAU,IAAI,wBAAwB,EAAE,CAAC;QAC3C,MAAM,sBAAsB,GAC1B,gBAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAEzD,gBAAgB,CAAC,cAAc,GAAG,GAAG,EAAE;YACrC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC;YAC/D,sBAAsB,EAAE,CAAC;QAC3B,CAAC,CAAC;QAEF,UAAU,CAAC,OAAO,GAAG,CAAC,MAAM,EAAE,EAAE;YAC9B,MAAM,KAAK,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;YAE/C,MAAM,sBAAsB,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,CAA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,CAAC,WAAW,CAAC;oBACxC,QAAQ,EAAE,IAAI,CAAC,eAAe;iBAC/B,CAAC,CAAC;gBAEH,OAAO,UAAU,CAAC;YACpB,CAAC,CAAC;YAEF,KAAK,CAAC,YAAY,GAAG,CAAC,OAAO,EAAE,EAAE;gBAC/B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBACvE,wBAAwB,CAAC,OAAO,CAAC,CAAC;YACpC,CAAC,CAAC;YAEF,KAAK,CAAC,aAAa,GAAG,CAAC,UAAU,EAAE,EAAE;gBACnC,IAAI,CAAC,WAAW;qBACb,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC;oBAC1B,EAAE,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBAClC,yBAAyB,CAAC,UAAU,CAAC,CAAC;YACxC,CAAC,CAAC;YAEF,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,sBAAO,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;IACnD,CAAC;AACH,CAAC,CAAC;AAEF,kBAAe,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { JestDoctorEnvironment } from '../types';
2
+ declare const patchHook: (that: JestDoctorEnvironment, hookName: string) => void;
3
+ export default patchHook;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const analyzeCallback_1 = __importDefault(require("../utils/analyzeCallback"));
7
+ const patchHook = (that, hookName) => {
8
+ const originalHook = that.global[hookName];
9
+ const test = that.global.expect;
10
+ that.global[hookName] = function (callback, timeout) {
11
+ const hookMock = function () {
12
+ if (hookName === 'afterEach') {
13
+ that.currentAfterEachCount -= 1;
14
+ }
15
+ const testName = test.getState().currentTestName || 'unknown';
16
+ return (0, analyzeCallback_1.default)(that, testName, callback, this);
17
+ };
18
+ // unfortunately, jest types the return type as any
19
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
20
+ return originalHook(hookMock, timeout);
21
+ };
22
+ };
23
+ exports.default = patchHook;
24
+ //# sourceMappingURL=hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.js","sourceRoot":"","sources":["../../src/patch/hook.ts"],"names":[],"mappings":";;;;;AAEA,+EAAuD;AAEvD,MAAM,SAAS,GAAG,CAAC,IAA2B,EAAE,QAAgB,EAAE,EAAE;IAClE,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAsB,CAAC;IAChE,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,MAAuB,CAAC;IACjD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,UAAU,QAAQ,EAAE,OAAO;QACjD,MAAM,QAAQ,GAAG;YACf,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;gBAC7B,IAAI,CAAC,qBAAqB,IAAI,CAAC,CAAC;YAClC,CAAC;YAED,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,eAAe,IAAI,SAAS,CAAC;YAC9D,OAAO,IAAA,yBAAe,EAAC,IAAI,EAAE,QAAQ,EAAE,QAAyB,EAAE,IAAI,CAAC,CAAC;QAC1E,CAAC,CAAC;QAEF,mDAAmD;QACnD,+DAA+D;QAC/D,OAAO,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzC,CAAsB,CAAC;AACzB,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { JestDoctorEnvironment } from '../types';
2
+ declare const patchIt: (that: JestDoctorEnvironment) => void;
3
+ export default patchIt;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const analyzeCallback_1 = __importDefault(require("../utils/analyzeCallback"));
7
+ const node_console_1 = __importDefault(require("node:console"));
8
+ const patchIt = (that) => {
9
+ const originalIt = that.global.it;
10
+ if (originalIt) {
11
+ const test = that.global.expect;
12
+ const originalOnly = that.global.it.only;
13
+ const createItPatch = (originalFn) => (testName, testFunction, timeout) => {
14
+ const testHandler = function () {
15
+ const testName = test.getState().currentTestName || 'unknown';
16
+ return (0, analyzeCallback_1.default)(that, testName, testFunction, this);
17
+ };
18
+ return originalFn(testName, testHandler, timeout);
19
+ };
20
+ const itPatch = createItPatch(originalIt);
21
+ Object.assign(itPatch, originalIt);
22
+ that.global.it = that.global.test = itPatch;
23
+ that.global.it.concurrent = that.global.it;
24
+ that.global.it.only = createItPatch(originalOnly);
25
+ }
26
+ else {
27
+ node_console_1.default.warn('injectGlobal it is set to false, this will impact on leak detection!');
28
+ }
29
+ };
30
+ exports.default = patchIt;
31
+ //# sourceMappingURL=it.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"it.js","sourceRoot":"","sources":["../../src/patch/it.ts"],"names":[],"mappings":";;;;;AAEA,+EAAuD;AACvD,gEAAmC;AAEnC,MAAM,OAAO,GAAG,CAAC,IAA2B,EAAE,EAAE;IAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IAElC,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,MAAuB,CAAC;QACjD,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;QACzC,MAAM,aAAa,GACjB,CAAC,UAAmD,EAAE,EAAE,CACxD,CACE,QAAyB,EACzB,YAA2B,EAC3B,OAAe,EACf,EAAE;YACF,MAAM,WAAW,GAAG;gBAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,eAAe,IAAI,SAAS,CAAC;gBAC9D,OAAO,IAAA,yBAAe,EAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;YAC7D,CAAkB,CAAC;YAEnB,OAAO,UAAU,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC,CAAC;QAEJ,MAAM,OAAO,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;QAE1C,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAEnC,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,OAAuC,CAAC;QAE5E,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,GAAG,aAAa,CACjC,YAAY,CACqB,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,sBAAO,CAAC,IAAI,CACV,sEAAsE,CACvE,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,kBAAe,OAAO,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { JestDoctorEnvironment } from '../types';
2
+ declare const patchPromise: (that: JestDoctorEnvironment) => void;
3
+ export default patchPromise;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const getStack_1 = __importDefault(require("../utils/getStack"));
7
+ const patchPromise = (that) => {
8
+ const OriginalPromise = that.global.Promise;
9
+ class TrackedPromise extends OriginalPromise {
10
+ constructor(executor) {
11
+ let resolveRef;
12
+ let rejectRef;
13
+ super((resolve, reject) => {
14
+ resolveRef = resolve;
15
+ rejectRef = reject;
16
+ });
17
+ const promiseLeaks = that.leakRecords.get(that.currentTestName)?.promises;
18
+ promiseLeaks?.set(this, {
19
+ testName: that.currentTestName,
20
+ stack: (0, getStack_1.default)(that.global.Promise),
21
+ });
22
+ executor((value) => {
23
+ promiseLeaks?.delete(this);
24
+ resolveRef(value);
25
+ }, (reason) => {
26
+ promiseLeaks?.delete(this);
27
+ rejectRef(reason);
28
+ });
29
+ }
30
+ }
31
+ Object.assign(Promise, OriginalPromise);
32
+ that.global.Promise = TrackedPromise;
33
+ };
34
+ exports.default = patchPromise;
35
+ //# sourceMappingURL=promise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/patch/promise.ts"],"names":[],"mappings":";;;;;AACA,iEAAyC;AAEzC,MAAM,YAAY,GAAG,CAAC,IAA2B,EAAE,EAAE;IACnD,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAE5C,MAAM,cAAkB,SAAQ,eAAkB;QAChD,YACE,QAGS;YAET,IAAI,UAA+C,CAAC;YACpD,IAAI,SAAqC,CAAC;YAE1C,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACxB,UAAU,GAAG,OAAO,CAAC;gBACrB,SAAS,GAAG,MAAM,CAAC;YACrB,CAAC,CAAC,CAAC;YAEH,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,QAAQ,CAAC;YAE1E,YAAY,EAAE,GAAG,CAAC,IAAI,EAAE;gBACtB,QAAQ,EAAE,IAAI,CAAC,eAAe;gBAC9B,KAAK,EAAE,IAAA,kBAAQ,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;aACrC,CAAC,CAAC;YAEH,QAAQ,CACN,CAAC,KAAyB,EAAE,EAAE;gBAC5B,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;gBAC3B,UAAU,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC,EACD,CAAC,MAAe,EAAE,EAAE;gBAClB,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;gBAC3B,SAAS,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC,CACF,CAAC;QACJ,CAAC;KACF;IAED,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC;AACvC,CAAC,CAAC;AAEF,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { JestDoctorEnvironment } from '../types';
2
+ declare const timers: (that: JestDoctorEnvironment) => void;
3
+ export default timers;