Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 0 additions & 88 deletions .github/workflows/automated-tests-publish-results.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Unit tests
on: [pull_request]

permissions:
contents: read

jobs:
unit-tests:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies
run: npm install
- name: Run unit tests
run: npm run test:unit:coverage
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ dist/
dist-tsc/
.env

# vitest
coverage/

# playwright
test-results/
playwright-report/
Expand Down
4 changes: 3 additions & 1 deletion src/data-consumption/factory/hookCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export const createDataConsumptionHook = <T>(
sortedStringify(hookArguments?.variables)
!== sortedStringify(variablesState)
) {
setVariablesState(() => JSON.parse(sortedStringify(hookArguments?.variables)));
setVariablesState(() => (hookArguments?.variables === undefined
? undefined
: JSON.parse(sortedStringify(hookArguments.variables))));
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/unit/data-consumption/factory/hookCreator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ describe('createDataConsumptionHook', () => {
expect(variablesOf(subscribeEvents[1])).toEqual(PT_BR_VARIABLES);
});

it('resubscribes without variables when they become undefined', () => {
const { rerender } = renderHook(
({ variables }: { variables?: object }) => createDataConsumptionHook<CaptionData>(
DataConsumptionHooks.CUSTOM_SUBSCRIPTION,
{ query: QUERY_WITH_ONE_VARIABLE, variables },
),
{ initialProps: { variables: EN_VARIABLES as object | undefined } },
);

rerender({ variables: undefined });

expect(unsubscribeEvents).toHaveLength(1);
expect(variablesOf(unsubscribeEvents[0])).toEqual(EN_VARIABLES);
expect(subscribeEvents).toHaveLength(2);
expect(variablesOf(subscribeEvents[1])).toBeUndefined();
});

it('does not resubscribe when a rerender passes a new variables object with the same content', () => {
const { rerender } = renderCustomSubscriptionHook({ locale: 'en' });

Expand Down
Loading