Skip to content

Commit

Permalink
add failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Aug 28, 2024
1 parent 9aab08e commit 38afd9d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/qwik/src/core/v2/shared/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export const createScheduler = (
// we need to process cleanup tasks for deleted nodes
nextChore.$type$ !== ChoreType.CLEANUP_VISIBLE
) {
DEBUG && debugTrace('skip chore', nextChore, currentChore, choreQueue);
continue;
}
const returnValue = executeChore(nextChore);
Expand Down Expand Up @@ -521,12 +522,13 @@ function debugChoreToString(chore: Chore): string {
[ChoreType.COMPONENT_SSR]: 'COMPONENT_SSR',
[ChoreType.JOURNAL_FLUSH]: 'JOURNAL_FLUSH',
[ChoreType.VISIBLE]: 'VISIBLE',
[ChoreType.CLEANUP_VISIBLE]: 'CLEANUP_VISIBLE',
[ChoreType.WAIT_FOR_ALL]: 'WAIT_FOR_ALL',
[ChoreType.WAIT_FOR_COMPONENTS]: 'WAIT_FOR_COMPONENTS',
} as any
)[chore.$type$] || 'UNKNOWN: ' + chore.$type$;
const host = String(chore.$host$).replaceAll(/\n.*/gim, '');
const qrlTarget = (chore.$target$ as QRLInternal<any>).$symbol$;
const qrlTarget = (chore.$target$ as QRLInternal<any>)?.$symbol$;
return `Chore(${type} ${chore.$type$ === ChoreType.QRL_RESOLVE ? qrlTarget : host} ${chore.$idx$})`;
}

Expand Down
34 changes: 34 additions & 0 deletions packages/qwik/src/core/v2/tests/use-signal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { Slot } from '../../render/jsx/slot.public';
import type { Signal as SignalType } from '../../state/signal';
import { untrack } from '../../use/use-core';
import { useSignal } from '../../use/use-signal';
import { vnode_getFirstChild, vnode_getProp, vnode_locate } from '../client/vnode';
import { QSubscribers } from '../../util/markers';

const debug = false; //true;
Error.stackTraceLimit = 100;
Expand Down Expand Up @@ -262,6 +264,38 @@ describe.each([
);
});

it("should don't add multiple the same subscribers", async () => {
const Child = component$(() => {
return <></>;
});

const Cmp = component$(() => {
const counter = useSignal<number>(0);
const cleanupCounter = useSignal<number>(0);

return (
<>
<button onClick$={() => counter.value++}></button>
<Child key={counter.value} />
<pre>{cleanupCounter.value + ''}</pre>
</>
);
});

const { container } = await render(<Cmp />, { debug });

await trigger(container.element, 'button', 'click');
await trigger(container.element, 'button', 'click');
await trigger(container.element, 'button', 'click');
await trigger(container.element, 'button', 'click');

const signalVNode = vnode_getFirstChild(
vnode_locate(container.rootVNode, container.element.querySelector('pre')!)
)!;
const subscribers = vnode_getProp<unknown[]>(signalVNode, QSubscribers, null);
expect(subscribers).toHaveLength(1);

Check failure on line 296 in packages/qwik/src/core/v2/tests/use-signal.spec.tsx

View workflow job for this annotation

GitHub Actions / Unit Tests

qwik/src/core/v2/tests/use-signal.spec.tsx > 'ssrRenderToDom': useSignal > should don't add multiple the same subscribers

AssertionError: expected [ DerivedSignal2{ …(8) }, …(3) ] to have a length of 1 but got 4 - Expected + Received - 1 + 4 ❯ qwik/src/core/v2/tests/use-signal.spec.tsx:296:25

Check failure on line 296 in packages/qwik/src/core/v2/tests/use-signal.spec.tsx

View workflow job for this annotation

GitHub Actions / Unit Tests

qwik/src/core/v2/tests/use-signal.spec.tsx > 'domRender': useSignal > should don't add multiple the same subscribers

AssertionError: expected [ DerivedSignal2{ …(8) }, …(4) ] to have a length of 1 but got 5 - Expected + Received - 1 + 5 ❯ qwik/src/core/v2/tests/use-signal.spec.tsx:296:25

Check failure on line 296 in packages/qwik/src/core/v2/tests/use-signal.spec.tsx

View workflow job for this annotation

GitHub Actions / Unit Tests

qwik/src/core/v2/tests/use-signal.spec.tsx > 'ssrRenderToDom': useSignal > should don't add multiple the same subscribers

AssertionError: expected [ DerivedSignal2{ …(8) }, …(3) ] to have a length of 1 but got 4 - Expected + Received - 1 + 4 ❯ qwik/src/core/v2/tests/use-signal.spec.tsx:296:25

Check failure on line 296 in packages/qwik/src/core/v2/tests/use-signal.spec.tsx

View workflow job for this annotation

GitHub Actions / Unit Tests

qwik/src/core/v2/tests/use-signal.spec.tsx > 'domRender': useSignal > should don't add multiple the same subscribers

AssertionError: expected [ DerivedSignal2{ …(8) }, …(4) ] to have a length of 1 but got 5 - Expected + Received - 1 + 5 ❯ qwik/src/core/v2/tests/use-signal.spec.tsx:296:25
});

describe('derived', () => {
it('should update value directly in DOM', async () => {
const log: string[] = [];
Expand Down
47 changes: 46 additions & 1 deletion packages/qwik/src/core/v2/tests/use-visible-task.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
useComputed$,
useContextProvider,
createContextId,
type Signal as SignalType,
useTask$,
} from '@builder.io/qwik';
import { trigger, domRender, ssrRenderToDom } from '@builder.io/qwik/testing';
import { ErrorProvider } from '../../../testing/rendering.unit-util';
Expand All @@ -29,7 +31,7 @@ export function useDelay(value: string) {

describe.each([
{ render: ssrRenderToDom }, //
{ render: domRender }, //
// { render: domRender }, //
])('$render.name: useVisibleTask', ({ render }) => {
it('should execute visible task', async () => {
const VisibleCmp = component$(() => {
Expand Down Expand Up @@ -556,6 +558,49 @@ describe.each([
(globalThis as any).log = undefined;
});

it('should run cleanup with component rerender', async () => {
const Child = component$((props: { cleanupCounter: SignalType<number> }) => {
useTask$(({ cleanup }) => {
cleanup(() => {
props.cleanupCounter.value++;
});
});
return <span></span>;
});

const Cmp = component$(() => {
const counter = useSignal<number>(0);
const cleanupCounter = useSignal<number>(0);
return (
<div>
<button onClick$={() => counter.value++}></button>
<Child key={counter.value} cleanupCounter={cleanupCounter} />
{cleanupCounter.value + ''}
</div>
);
});

const { vNode, container } = await render(<Cmp />, { debug });
await trigger(container.element, 'button', 'click');
await trigger(container.element, 'button', 'click');
await trigger(container.element, 'button', 'click');
await trigger(container.element, 'button', 'click');
await trigger(container.element, 'button', 'click');
await trigger(container.element, 'button', 'click');

expect(vNode).toMatchVDOM(

Check failure on line 591 in packages/qwik/src/core/v2/tests/use-visible-task.spec.tsx

View workflow job for this annotation

GitHub Actions / Unit Tests

qwik/src/core/v2/tests/use-visible-task.spec.tsx > 'ssrRenderToDom': useVisibleTask > ssrRenderToDom: cleanup > should run cleanup with component rerender

Error: Fragment > div > Fragment EXPECTED "6" RECEIVED: "5" ❯ qwik/src/core/v2/tests/use-visible-task.spec.tsx:591:21

Check failure on line 591 in packages/qwik/src/core/v2/tests/use-visible-task.spec.tsx

View workflow job for this annotation

GitHub Actions / Unit Tests

qwik/src/core/v2/tests/use-visible-task.spec.tsx > 'ssrRenderToDom': useVisibleTask > ssrRenderToDom: cleanup > should run cleanup with component rerender

Error: Fragment > div > Fragment EXPECTED "6" RECEIVED: "5" ❯ qwik/src/core/v2/tests/use-visible-task.spec.tsx:591:21
<Component>
<div>
<button></button>
<Component>
<span></span>
</Component>
<Signal>{'6'}</Signal>
</div>
</Component>
);
});

it('should handle promises and visible tasks', async () => {
// vi.useFakeTimers();
const MyComp = component$(() => {
Expand Down

0 comments on commit 38afd9d

Please sign in to comment.