Skip to content

Commit

Permalink
test: custom-named debug
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrHoroshih committed Sep 1, 2022
1 parent 44a580f commit f56a726
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/debug/debug.fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,67 @@ test('logs stores for newly registered scope', async () => {
]
`);
});

test('custom names basic support', () => {
const event = createEvent<number>();
const effect = createEffect().use((payload) => Promise.resolve('result' + payload));
const $store = createStore(0)
.on(event, (state, value) => state + value)
.on(effect.done, (state) => state * 10);
sample({
clock: event,
target: effect,
});

debug({ $customName: $store, name: event, nameFx: effect });
clearConsole();

const scope = fork();

allSettled(event, { scope, params: 1 });

expect(stringArguments(fn)).toMatchInlineSnapshot(`
Array [
"[event] (scope: unknown_scope_5) name 1",
"[store] (scope: unknown_scope_5) $customName 1",
"[effect] (scope: unknown_scope_5) nameFx 1",
]
`);
});

test('custom names with traces support', () => {
const event = createEvent<number>();
const effect = createEffect().use((payload) => Promise.resolve('result' + payload));
const $store = createStore(0)
.on(event, (state, value) => state + value)
.on(effect.done, (state) => state * 10);
sample({
clock: event,
target: effect,
});

debug({ trace: true }, { $customName: $store, name: event, nameFx: effect });
clearConsole();

const scope = fork();

allSettled(event, { scope, params: 1 });

expect(stringArguments(fn)).toMatchInlineSnapshot(`
Array [
"[event] (scope: unknown_scope_6) name 1",
"[event] (scope: unknown_scope_6) name trace",
"<- [event] event 1",
"[store] (scope: unknown_scope_6) $customName 1",
"[store] (scope: unknown_scope_6) $customName trace",
"<- [store] $store 1",
"<- [$store.on] $store.on(event) 1",
"<- [event] event 1",
"[effect] (scope: unknown_scope_6) nameFx 1",
"[effect] (scope: unknown_scope_6) nameFx trace",
"<- [effect] effect 1",
"<- [sample] 1",
"<- [event] event 1",
]
`);
});
58 changes: 58 additions & 0 deletions src/debug/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,61 @@ test('domain is traceable', async () => {
]
`);
});

test('custom names basic support', () => {
const event = createEvent<number>();
const effect = createEffect().use((payload) => Promise.resolve('result' + payload));
const $store = createStore(0)
.on(event, (state, value) => state + value)
.on(effect.done, (state) => state * 10);
sample({
clock: event,
target: effect,
});

debug({ $customName: $store, name: event, nameFx: effect });
event(1);

expect(stringArguments(fn)).toMatchInlineSnapshot(`
Array [
"[store] $customName 0",
"[event] name 1",
"[store] $customName 1",
"[effect] nameFx 1",
]
`);
});

test('custom names with traces support', () => {
const event = createEvent<number>();
const effect = createEffect().use((payload) => Promise.resolve('result' + payload));
const $store = createStore(0)
.on(event, (state, value) => state + value)
.on(effect.done, (state) => state * 10);
sample({
clock: event,
target: effect,
});

debug({ trace: true }, { $customName: $store, name: event, nameFx: effect });
event(1);

expect(stringArguments(fn)).toMatchInlineSnapshot(`
Array [
"[store] $customName 0",
"[event] name 1",
"[event] name trace",
"<- [event] event 1",
"[store] $customName 1",
"[store] $customName trace",
"<- [store] $store 1",
"<- [$store.on] $store.on(event) 1",
"<- [event] event 1",
"[effect] nameFx 1",
"[effect] nameFx trace",
"<- [effect] effect 1",
"<- [sample] 1",
"<- [event] event 1",
]
`);
});

0 comments on commit f56a726

Please sign in to comment.