Skip to content

Commit 1c0f059

Browse files
authored
chore: improve test debug logging (#56)
1 parent 4aa6037 commit 1c0f059

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.config/jest.config.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
44
const jestExpo = require("jest-expo/jest-preset");
55

6+
process.env.REACT_NATIVE_CSS_TEST_DEBUG = true;
7+
68
module.exports = {
79
...jestExpo,
810
testPathIgnorePatterns: ["dist/"],

src/jest/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Appearance, Dimensions } from "react-native";
22

3+
import util from "node:util";
4+
35
import { compile, type CompilerOptions } from "../compiler";
46
import { StyleCollection } from "../runtime/native/injection";
57
import { colorScheme, dimensions, rem } from "../runtime/native/reactivity";
@@ -23,16 +25,23 @@ beforeEach(() => {
2325
colorScheme.set(null);
2426
});
2527

28+
const debugDefault = Boolean(
29+
process.env.REACT_NATIVE_CSS_TEST_DEBUG &&
30+
process.env.NODE_OPTIONS?.includes("--inspect"),
31+
);
32+
2633
export function registerCSS(
2734
css: string,
2835
{
29-
debugCompiled = process.env.NODE_OPTIONS?.includes("--inspect"),
36+
debug = debugDefault,
3037
...options
31-
}: CompilerOptions & { debugCompiled?: boolean } = {},
38+
}: CompilerOptions & { debug?: boolean } = {},
3239
) {
3340
const compiled = compile(css, options);
34-
if (debugCompiled) {
35-
console.log(`Compiled styles:\n\n${JSON.stringify({ compiled }, null, 2)}`);
41+
if (debug) {
42+
console.log(
43+
`Compiled:\n---\n${util.inspect(compiled, { depth: null, colors: true, compact: false })}`,
44+
);
3645
}
3746

3847
StyleCollection.inject(compiled);

0 commit comments

Comments
 (0)