From e73139c2182958f9dddd19b8d914d34a19a02fec Mon Sep 17 00:00:00 2001 From: Cris Vergara Date: Tue, 5 Dec 2023 11:25:42 -0500 Subject: [PATCH] Add failing test for client-side router filtering --- test/unit/create-client-router-filter.test.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/unit/create-client-router-filter.test.ts diff --git a/test/unit/create-client-router-filter.test.ts b/test/unit/create-client-router-filter.test.ts new file mode 100644 index 0000000000000..80e18f4187623 --- /dev/null +++ b/test/unit/create-client-router-filter.test.ts @@ -0,0 +1,29 @@ +/* eslint-env jest */ +import { createClientRouterFilter } from 'next/dist/lib/create-client-router-filter' +import { BloomFilter } from 'next/dist/shared/lib/bloom-filter' + +describe('createClientRouterFilter', () => { + it('creates a filter that does not collide with wildly different path names', () => { + const { staticFilter, dynamicFilter } = createClientRouterFilter( + ['/_not-found', '/a/[lang]/corporate', '/a/[lang]/gift'], // Routes are based on BOTM's app router migration project. + [] + ) + + const staticFilterInstance = new BloomFilter( + staticFilter.numItems, + staticFilter.errorRate + ) + staticFilterInstance.import(staticFilter) + const dynamicFilterInstance = new BloomFilter( + dynamicFilter.numItems, + dynamicFilter.errorRate + ) + dynamicFilterInstance.import(dynamicFilter) + + expect( + staticFilterInstance.contains( + '/all-hardcovers/no-one-can-know-1511?category=current-features' + ) + ).toBe(false) + }) +})