Skip to content

Commit

Permalink
feat(logger): Replace Pino with debug.js (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion committed Jul 6, 2024
1 parent 45b6821 commit 989a361
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 255 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
"@babel/core": "^7.24.7",
"@babel/register": "^7.24.6",
"babel-plugin-extension-resolver": "^1.0.12",
"debug": "^4.3.5",
"dot-prop-immutable": "^2.1.1",
"pino": "^9.2.0",
"pino-pretty": "^11.2.1",
"supports-color": "^9.4.0",
"ts-pattern": "^5.2.0"
},
"devDependencies": {
Expand All @@ -84,6 +84,7 @@
"@testing-library/react-native": "^12.5.1",
"@types/babel__core": "^7.20.5",
"@types/babel__register": "^7.17.3",
"@types/debug": "^4.1.12",
"@types/eslint__eslintrc": "^2.1.1",
"@types/eslint__js": "^8.42.3",
"@types/node": "^20.14.9",
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/commons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createRequire } from "module";
import path from "path";

import { logger } from "./logger";

type ExportsLike = object | { default?: unknown; };

const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -36,6 +38,8 @@ export function replace<T extends ExportsLike>(modulePath: string, factory: () =
paths: [],
require,
};

logger.replace(`Module replaced: ${modulePath}`);
}

function resolveId(modulePath: string): string {
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { debug } from "debug";

import { name } from "../../package.json";

export const logger = Object.freeze({
register: debug(`${name}:register`),
replace: debug(`${name}:replace`),
});
3 changes: 3 additions & 0 deletions src/lib/mockNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createRequire } from "module";
import { match } from "ts-pattern";

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

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

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

MOCKS.clear();
logger.replace("All native methods mocks restored!");
}
8 changes: 2 additions & 6 deletions src/register.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { createRequire } from "module";

import pino from "pino";
import pinoPretty from "pino-pretty";

import { name } from "../package.json";
import { logger } from "./helpers/logger";

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

require("./load.cjs");

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

logger.info(`React Native testing mocks registered! (${diff}s)`);
logger.register(`React Native testing mocks registered! (${diff}s)`);
Loading

0 comments on commit 989a361

Please sign in to comment.