Skip to content

Commit 989a361

Browse files
authored
feat(logger): Replace Pino with debug.js (#30)
1 parent 45b6821 commit 989a361

File tree

6 files changed

+43
-255
lines changed

6 files changed

+43
-255
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
"@babel/core": "^7.24.7",
7070
"@babel/register": "^7.24.6",
7171
"babel-plugin-extension-resolver": "^1.0.12",
72+
"debug": "^4.3.5",
7273
"dot-prop-immutable": "^2.1.1",
73-
"pino": "^9.2.0",
74-
"pino-pretty": "^11.2.1",
74+
"supports-color": "^9.4.0",
7575
"ts-pattern": "^5.2.0"
7676
},
7777
"devDependencies": {
@@ -84,6 +84,7 @@
8484
"@testing-library/react-native": "^12.5.1",
8585
"@types/babel__core": "^7.20.5",
8686
"@types/babel__register": "^7.17.3",
87+
"@types/debug": "^4.1.12",
8788
"@types/eslint__eslintrc": "^2.1.1",
8889
"@types/eslint__js": "^8.42.3",
8990
"@types/node": "^20.14.9",

src/helpers/commons.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { createRequire } from "module";
22
import path from "path";
33

4+
import { logger } from "./logger";
5+
46
type ExportsLike = object | { default?: unknown; };
57

68
const require = createRequire(import.meta.url);
@@ -36,6 +38,8 @@ export function replace<T extends ExportsLike>(modulePath: string, factory: () =
3638
paths: [],
3739
require,
3840
};
41+
42+
logger.replace(`Module replaced: ${modulePath}`);
3943
}
4044

4145
function resolveId(modulePath: string): string {

src/helpers/logger.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { debug } from "debug";
2+
3+
import { name } from "../../package.json";
4+
5+
export const logger = Object.freeze({
6+
register: debug(`${name}:register`),
7+
replace: debug(`${name}:replace`),
8+
});

src/lib/mockNative.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createRequire } from "module";
33
import { match } from "ts-pattern";
44

55
import { replace } from "../helpers/commons";
6+
import { logger } from "../helpers/logger";
67
import { type AllNativeMethods, mockComponent } from "../helpers/mockComponent";
78
import {
89
type ImageMethods,
@@ -65,6 +66,7 @@ export function mockNative(type: NativeKey, methods: Partial<AllNativeMethods |
6566

6667
replace(path, () => type === "ActivityIndicator" ? { default: Mock } : Mock);
6768
MOCKS.add(type);
69+
logger.replace(`Native methods mocks assigned to ${type}.`);
6870
}
6971

7072
/**
@@ -85,4 +87,5 @@ export function restoreNativeMocks(): void {
8587
});
8688

8789
MOCKS.clear();
90+
logger.replace("All native methods mocks restored!");
8891
}

src/register.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { createRequire } from "module";
22

3-
import pino from "pino";
4-
import pinoPretty from "pino-pretty";
5-
6-
import { name } from "../package.json";
3+
import { logger } from "./helpers/logger";
74

85
const start = Date.now();
9-
const logger = pino({ name }, pinoPretty({ colorize: true }));
106
const require = createRequire(import.meta.url);
117

128
require("./load.cjs");
139

1410
const end = Date.now();
1511
const diff = (end - start) / 1000;
1612

17-
logger.info(`React Native testing mocks registered! (${diff}s)`);
13+
logger.register(`React Native testing mocks registered! (${diff}s)`);

0 commit comments

Comments
 (0)