@faststore/core 4.11.4-dev.4 → 4.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,27 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [4.11.4-dev.4](https://github.com/vtex/faststore/compare/v4.11.4-dev.3...v4.11.4-dev.4) (2026-11-19)
7
-
8
- ### Bug Fixes
9
-
10
- - **core:** forward search dropdown labels from the CMS ([#3600](https://github.com/vtex/faststore/issues/3600)) ([0f18b72](https://github.com/vtex/faststore/commit/0f18b729eb90e7053b823ceb90207967d9d383f8)), closes [#3334](https://github.com/vtex/faststore/issues/3334) [#3334](https://github.com/vtex/faststore/issues/3334) [#3240](https://github.com/vtex/faststore/issues/3240) [#3240](https://github.com/vtex/faststore/issues/3240)
11
-
12
- ## [4.11.4-dev.3](https://github.com/vtex/faststore/compare/v4.11.4-dev.2...v4.11.4-dev.3) (2026-11-18)
13
-
14
- ### Bug Fixes
15
-
16
- - **core:** add experimental.revalidatePLP to refresh cached PLPs ([#3595](https://github.com/vtex/faststore/issues/3595)) ([f14ca23](https://github.com/vtex/faststore/commit/f14ca23c3581d94961eac3bdc6839207066eff74)), closes [#3553](https://github.com/vtex/faststore/issues/3553) [#3553](https://github.com/vtex/faststore/issues/3553)
17
-
18
- ## [4.11.4-dev.2](https://github.com/vtex/faststore/compare/v4.11.4-dev.1...v4.11.4-dev.2) (2026-11-17)
19
-
20
- **Note:** Version bump only for package @faststore/core
21
-
22
- ## [4.11.4-dev.1](https://github.com/vtex/faststore/compare/v4.11.4-dev.0...v4.11.4-dev.1) (2026-11-16)
23
-
24
- **Note:** Version bump only for package @faststore/core
25
-
26
- ## [4.11.4-dev.0](https://github.com/vtex/faststore/compare/v4.11.3...v4.11.4-dev.0) (2026-11-10)
6
+ ## [4.11.4](https://github.com/vtex/faststore/compare/v4.11.3...v4.11.4) (2026-11-19)
27
7
 
28
8
  **Note:** Version bump only for package @faststore/core
29
9
 
@@ -93,17 +93,7 @@
93
93
  "searchTopTitle": {
94
94
  "title": "Top Search Title",
95
95
  "type": "string",
96
- "default": "Top Search"
97
- },
98
- "searchHistoryClearLabel": {
99
- "title": "Clear Search History Button Label",
100
- "type": "string",
101
- "default": "Clear History"
102
- },
103
- "searchProductsTitle": {
104
- "title": "Suggested Products Title",
105
- "type": "string",
106
- "default": "Suggested Products"
96
+ "default": "Top search"
107
97
  },
108
98
  "quickOrderSettings": {
109
99
  "title": "Quick Order settings",
@@ -2064,17 +2064,7 @@
2064
2064
  "searchTopTitle": {
2065
2065
  "title": "Top Search Title",
2066
2066
  "type": "string",
2067
- "default": "Top Search"
2068
- },
2069
- "searchHistoryClearLabel": {
2070
- "title": "Clear Search History Button Label",
2071
- "type": "string",
2072
- "default": "Clear History"
2073
- },
2074
- "searchProductsTitle": {
2075
- "title": "Suggested Products Title",
2076
- "type": "string",
2077
- "default": "Suggested Products"
2067
+ "default": "Top search"
2078
2068
  },
2079
2069
  "quickOrderSettings": {
2080
2070
  "title": "Quick Order settings",
@@ -235,17 +235,7 @@
235
235
  "searchTopTitle": {
236
236
  "title": "Top Search Title",
237
237
  "type": "string",
238
- "default": "Top Search"
239
- },
240
- "searchHistoryClearLabel": {
241
- "title": "Clear Search History Button Label",
242
- "type": "string",
243
- "default": "Clear History"
244
- },
245
- "searchProductsTitle": {
246
- "title": "Suggested Products Title",
247
- "type": "string",
248
- "default": "Suggested Products"
238
+ "default": "Top search"
249
239
  },
250
240
  "quickOrderSettings": {
251
241
  "title": "Quick Order settings",
@@ -196,11 +196,6 @@ module.exports = {
196
196
  enableRedirects: false,
197
197
  // ISR window (seconds) for notFound PDP/PLP paths.
198
198
  revalidate404: 60 * 5, // 5 minutes
199
- // ISR window (seconds) for PLPs served by `[...slug]`. `false` (default)
200
- // caches the page until the next deploy. Set a positive integer number of
201
- // seconds (values below 60 are raised to 60) to refresh the
202
- // server-rendered first page (price, stock, order).
203
- revalidatePLP: false,
204
199
  enableSearchSSR: false,
205
200
  enableFaststoreMyAccount: false,
206
201
  useIsGiftFromOrderForm: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/core",
3
- "version": "4.11.4-dev.4",
3
+ "version": "4.11.4",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -70,11 +70,11 @@
70
70
  "style-loader": "^3.3.1",
71
71
  "swr": "^2.2.5",
72
72
  "use-sync-external-store": "^1.6.0",
73
- "@faststore/api": "4.11.4-dev.4",
74
- "@faststore/diagnostics": "4.11.4-dev.4",
75
- "@faststore/lighthouse": "4.11.4-dev.4",
76
- "@faststore/sdk": "4.11.4-dev.4",
77
- "@faststore/ui": "4.11.4-dev.4"
73
+ "@faststore/api": "4.11.4",
74
+ "@faststore/lighthouse": "4.11.4",
75
+ "@faststore/diagnostics": "4.11.4",
76
+ "@faststore/sdk": "4.11.4",
77
+ "@faststore/ui": "4.11.4"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@cypress/code-coverage": "^3.12.1",
@@ -185,8 +185,6 @@ function Navbar({
185
185
  loadingLabel={searchInput?.loadingLabel}
186
186
  searchHistoryTitle={searchInput?.searchHistoryTitle}
187
187
  searchTopTitle={searchInput?.searchTopTitle}
188
- searchHistoryClearLabel={searchInput?.searchHistoryClearLabel}
189
- searchProductsTitle={searchInput?.searchProductsTitle}
190
188
  />
191
189
  )}
192
190
 
@@ -224,8 +222,6 @@ function Navbar({
224
222
  loadingLabel={searchInput?.loadingLabel}
225
223
  searchHistoryTitle={searchInput?.searchHistoryTitle}
226
224
  searchTopTitle={searchInput?.searchTopTitle}
227
- searchHistoryClearLabel={searchInput?.searchHistoryClearLabel}
228
- searchProductsTitle={searchInput?.searchProductsTitle}
229
225
  />
230
226
  )}
231
227
 
@@ -24,9 +24,7 @@ interface SearchDropdownProps {
24
24
  sort: SearchState['sort']
25
25
  quickOrderSettings?: NavbarProps['searchInput']['quickOrderSettings']
26
26
  searchHistoryTitle?: string
27
- searchHistoryClearLabel?: string
28
27
  searchTopTitle?: string
29
- searchProductsTitle?: string
30
28
  [key: string]: any
31
29
  onChangeCustomSearchDropdownVisible?: Dispatch<SetStateAction<boolean>>
32
30
  }
@@ -49,12 +47,10 @@ function SearchDropdown({
49
47
  sort,
50
48
  quickOrderSettings,
51
49
  searchHistoryTitle,
52
- searchHistoryClearLabel,
53
50
  searchTopTitle,
54
- searchProductsTitle,
55
51
  onChangeCustomSearchDropdownVisible,
56
52
  ...otherProps
57
- }: Readonly<SearchDropdownProps>) {
53
+ }: SearchDropdownProps) {
58
54
  const {
59
55
  values: { onSearchSelection, products, term, terms, searchId },
60
56
  } = useSearch()
@@ -62,11 +58,7 @@ function SearchDropdown({
62
58
 
63
59
  return (
64
60
  <UISearchDropdown {...otherProps}>
65
- <SearchHistory
66
- title={searchHistoryTitle}
67
- clearLabel={searchHistoryClearLabel}
68
- sort={sort}
69
- />
61
+ <SearchHistory title={searchHistoryTitle} sort={sort} />
70
62
  <SearchTop title={searchTopTitle} sort={sort} />
71
63
  <UISearchAutoComplete>
72
64
  {terms?.map(({ value: suggestion }) => (
@@ -103,7 +95,6 @@ function SearchDropdown({
103
95
  ))}
104
96
  </UISearchAutoComplete>
105
97
  <SearchProducts
106
- title={searchProductsTitle}
107
98
  data-af-element={searchId && 'search-autocomplete'}
108
99
  data-af-onimpression={!!searchId}
109
100
  data-af-search-id={searchId}
@@ -7,15 +7,10 @@ import useSearchHistory from 'src/sdk/search/useSearchHistory'
7
7
 
8
8
  interface SearchHistoryProps {
9
9
  title?: string
10
- clearLabel?: string
11
10
  [key: string]: unknown
12
11
  }
13
12
 
14
- const SearchHistory = ({
15
- title,
16
- clearLabel,
17
- ...props
18
- }: Readonly<SearchHistoryProps>) => {
13
+ const SearchHistory = ({ title, ...props }: SearchHistoryProps) => {
19
14
  const {
20
15
  values: { onSearchSelection },
21
16
  } = useSearch()
@@ -26,12 +21,7 @@ const SearchHistory = ({
26
21
  }
27
22
 
28
23
  return (
29
- <UISearchHistory
30
- title={title}
31
- clearLabel={clearLabel}
32
- onClear={clearSearchHistory}
33
- {...props}
34
- >
24
+ <UISearchHistory title={title} onClear={clearSearchHistory} {...props}>
35
25
  {searchHistory.map((item) => (
36
26
  <UISearchHistoryTerm
37
27
  key={item.term}
@@ -73,9 +73,7 @@ export type SearchInputProps = {
73
73
  submitButtonAriaLabel?: string
74
74
  loadingLabel?: string
75
75
  searchHistoryTitle?: string
76
- searchHistoryClearLabel?: string
77
76
  searchTopTitle?: string
78
- searchProductsTitle?: string
79
77
  } & Omit<UISearchInputFieldProps, 'onSubmit' | 'attachmentButtonIcon'>
80
78
 
81
79
  export type SearchInputRef = UISearchInputFieldRef & {
@@ -116,11 +114,6 @@ const SearchInput = forwardRef<SearchInputRef, SearchInputProps>(
116
114
  sort,
117
115
  placeholder,
118
116
  quickOrderSettings,
119
- loadingLabel,
120
- searchHistoryTitle,
121
- searchHistoryClearLabel,
122
- searchTopTitle,
123
- searchProductsTitle,
124
117
  ...otherProps
125
118
  },
126
119
  ref
@@ -397,11 +390,6 @@ const SearchInput = forwardRef<SearchInputRef, SearchInputProps>(
397
390
  onChangeCustomSearchDropdownVisible={
398
391
  setCustomSearchDropdownVisibleCondition
399
392
  }
400
- loadingLabel={loadingLabel}
401
- searchHistoryTitle={searchHistoryTitle}
402
- searchHistoryClearLabel={searchHistoryClearLabel}
403
- searchTopTitle={searchTopTitle}
404
- searchProductsTitle={searchProductsTitle}
405
393
  />
406
394
  </Suspense>
407
395
  )}
@@ -25,9 +25,7 @@ export interface NavbarProps {
25
25
  sort: string
26
26
  submitButtonAriaLabel?: string
27
27
  searchHistoryTitle?: string
28
- searchHistoryClearLabel?: string
29
28
  searchTopTitle?: string
30
- searchProductsTitle?: string
31
29
  collapseSearchAriaLabel?: string
32
30
  quickOrderSettings?: {
33
31
  quickOrder: boolean
@@ -32,7 +32,6 @@ import { contentService } from 'src/server/content/service'
32
32
  import type { PreviewData } from 'src/server/content/types'
33
33
  import { getDynamicContent } from 'src/utils/dynamicContent'
34
34
  import { fetchServerManyProducts } from 'src/utils/fetchProductGallerySSR'
35
- import { toRevalidate } from 'src/utils/toRevalidate'
36
35
 
37
36
  const LandingPage = dynamic(
38
37
  () => import('src/components/templates/LandingPage')
@@ -245,15 +244,6 @@ export const getStaticProps: GetStaticProps<
245
244
  type: 'plp',
246
245
  key: slug,
247
246
  },
248
- // Without a window, the first page's products (price, stock, order) stay
249
- // frozen at the state of their first render until the next deploy. Each
250
- // regeneration reruns the CMS, collection and first-page search queries,
251
- // so the window has a floor to bound the upstream load.
252
- revalidate: toRevalidate(
253
- storeConfig.experimental.revalidatePLP,
254
- 'experimental.revalidatePLP',
255
- { min: 60 }
256
- ),
257
247
  }
258
248
  }
259
249
 
@@ -3,30 +3,12 @@
3
3
  */
4
4
 
5
5
  import React from 'react'
6
- import { act, fireEvent, render, waitFor } from '@testing-library/react'
6
+ import { act, render, waitFor } from '@testing-library/react'
7
7
  import { afterEach, describe, expect, it, vi } from 'vitest'
8
8
 
9
- // ─── next/dynamic: render the input field as a plain <input> ─────────────────
10
- // `onFocus` opens the dropdown, and props leaked from SearchInput show up as
11
- // DOM attributes.
9
+ // ─── next/dynamic: return a plain functional component ───────────────────────
12
10
  vi.mock('next/dynamic', () => ({
13
- default: () =>
14
- function InputField({
15
- onFocus,
16
- ...props
17
- }: Readonly<React.InputHTMLAttributes<HTMLInputElement>>) {
18
- const domProps = Object.fromEntries(
19
- Object.entries(props).filter(([, value]) => typeof value === 'string')
20
- )
21
- return (
22
- <input
23
- data-testid="search-field"
24
- readOnly
25
- onFocus={onFocus}
26
- {...domProps}
27
- />
28
- )
29
- },
11
+ default: () => () => null,
30
12
  }))
31
13
 
32
14
  // ─── next/router ─────────────────────────────────────────────────────────────
@@ -35,16 +17,7 @@ vi.mock('next/router', () => ({
35
17
  }))
36
18
 
37
19
  // ─── lazy-loaded chunk ───────────────────────────────────────────────────────
38
- const dropdownProps = vi.hoisted(() => ({
39
- current: null as Record<string, unknown> | null,
40
- }))
41
-
42
- vi.mock('src/components/search/SearchDropdown', () => ({
43
- default: (props: Record<string, unknown>) => {
44
- dropdownProps.current = props
45
- return null
46
- },
47
- }))
20
+ vi.mock('src/components/search/SearchDropdown', () => ({ default: () => null }))
48
21
 
49
22
  // ─── discovery.config ────────────────────────────────────────────────────────
50
23
  vi.mock('discovery.config', () => ({
@@ -152,7 +125,6 @@ import SearchInput from '../../../src/components/search/SearchInput/SearchInput'
152
125
 
153
126
  afterEach(() => {
154
127
  vi.clearAllMocks()
155
- dropdownProps.current = null
156
128
  oesState.status = null
157
129
  oesState.isUploading = false
158
130
  oesState.isProcessing = false
@@ -302,42 +274,3 @@ describe('SearchInput (OES integration)', () => {
302
274
  expect(true).toBe(true)
303
275
  })
304
276
  })
305
-
306
- describe('SearchInput dropdown labels', () => {
307
- const labels = {
308
- loadingLabel: 'Carregando...',
309
- searchHistoryTitle: 'Histórico',
310
- searchHistoryClearLabel: 'Limpar histórico',
311
- searchTopTitle: 'Mais buscados',
312
- searchProductsTitle: 'Produtos sugeridos',
313
- }
314
-
315
- it('forwards the CMS labels to the SearchDropdown', async () => {
316
- const { getByTestId } = render(
317
- <Wrapper>
318
- <SearchInput {...labels} />
319
- </Wrapper>
320
- )
321
-
322
- await act(async () => {
323
- fireEvent.focus(getByTestId('search-field'))
324
- })
325
-
326
- await waitFor(() => {
327
- expect(dropdownProps.current).toMatchObject(labels)
328
- })
329
- })
330
-
331
- it('does not leak the CMS labels to the input element', () => {
332
- const { getByTestId } = render(
333
- <Wrapper>
334
- <SearchInput {...labels} />
335
- </Wrapper>
336
- )
337
-
338
- const field = getByTestId('search-field')
339
- for (const name of Object.keys(labels)) {
340
- expect(field.hasAttribute(name)).toBe(false)
341
- }
342
- })
343
- })
@@ -1,74 +0,0 @@
1
- /**
2
- * Config keys already warned about in this process. `getStaticProps` runs on
3
- * every regeneration, so a per-call warning would repeat for every hot page.
4
- */
5
- const warnedKeys = new Set<string>()
6
-
7
- function warnOnce(key: string, message: string) {
8
- if (warnedKeys.has(key)) {
9
- return
10
- }
11
-
12
- warnedKeys.add(key)
13
- console.warn(message)
14
- }
15
-
16
- /**
17
- * Normalizes an ISR `revalidate` window read from the store config.
18
- *
19
- * Returns the value when it is a positive integer number of seconds, raised
20
- * to `min` when it is lower. Any other value returns `false`, which keeps
21
- * Next.js' default for static pages: the page is cached until the next
22
- * deploy. Next.js rejects `0`, negative and fractional windows at render
23
- * time, so those fall back to `false` with a warning instead of breaking the
24
- * page.
25
- *
26
- * @param value The configured window, e.g. `experimental.revalidatePLP`.
27
- * @param key The config key, used in the warnings.
28
- * @param options.min The shortest window allowed, in seconds. Defaults to 1.
29
- */
30
- export function toRevalidate(
31
- value: unknown,
32
- key: string,
33
- { min = 1 }: { min?: number } = {}
34
- ): number | false {
35
- if (typeof value === 'number' && Number.isInteger(value) && value > 0) {
36
- if (value < min) {
37
- warnOnce(
38
- key,
39
- `[FastStore] ${key} is ${value}s. Using the minimum of ${min}s.`
40
- )
41
-
42
- return min
43
- }
44
-
45
- return value
46
- }
47
-
48
- if (value !== false && value !== undefined && value !== null) {
49
- warnOnce(
50
- key,
51
- `[FastStore] Invalid ${key}: ${describeValue(value)}. Expected a positive integer number of seconds or false. The page will be cached until the next deploy.`
52
- )
53
- }
54
-
55
- return false
56
- }
57
-
58
- /**
59
- * Describes a config value for a warning without ever throwing: objects can
60
- * be circular or hold bigints, which JSON.stringify rejects, so only their
61
- * type is printed.
62
- */
63
- function describeValue(value: unknown): string {
64
- switch (typeof value) {
65
- case 'number':
66
- case 'bigint':
67
- case 'boolean':
68
- return `${value}`
69
- case 'string':
70
- return JSON.stringify(value)
71
- default:
72
- return `a value of type ${typeof value}`
73
- }
74
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * @vitest-environment jsdom
3
- */
4
-
5
- import React from 'react'
6
- import { render } from '@testing-library/react'
7
- import { afterEach, describe, expect, it, vi } from 'vitest'
8
-
9
- const { received, capture } = vi.hoisted(() => {
10
- const received: Record<string, Record<string, unknown>> = {}
11
- const capture =
12
- (name: string) =>
13
- ({
14
- children,
15
- ...props
16
- }: Readonly<{ children?: unknown } & Record<string, unknown>>) => {
17
- received[name] = props
18
- return (children ?? null) as never
19
- }
20
- return { received, capture }
21
- })
22
-
23
- vi.mock('@faststore/ui', () => ({
24
- SearchDropdown: capture('SearchDropdown'),
25
- SearchAutoComplete: capture('SearchAutoComplete'),
26
- SearchAutoCompleteTerm: capture('SearchAutoCompleteTerm'),
27
- SearchProducts: capture('SearchProducts'),
28
- useSearch: () => ({
29
- values: { products: [], term: '', terms: [], searchId: undefined },
30
- }),
31
- }))
32
-
33
- vi.mock('src/components/search/SearchHistory', () => ({
34
- SearchHistory: capture('SearchHistory'),
35
- }))
36
-
37
- vi.mock('src/components/search/SearchTop', () => ({
38
- SearchTop: capture('SearchTop'),
39
- }))
40
-
41
- vi.mock('src/components/search/SearchProductItem', () => ({
42
- default: () => null,
43
- }))
44
-
45
- vi.mock('src/sdk/search/formatSearchPath', () => ({
46
- useFormatSearchPath: () => (args: { term: string }) => `/s?q=${args.term}`,
47
- }))
48
-
49
- import SearchDropdown from '../../../src/components/search/SearchDropdown/SearchDropdown'
50
-
51
- afterEach(() => {
52
- for (const key of Object.keys(received)) delete received[key]
53
- })
54
-
55
- describe('SearchDropdown labels', () => {
56
- it('forwards the CMS labels to each dropdown block', () => {
57
- render(
58
- <SearchDropdown
59
- sort="score_desc"
60
- loadingLabel="Carregando..."
61
- searchHistoryTitle="Histórico"
62
- searchHistoryClearLabel="Limpar histórico"
63
- searchTopTitle="Mais buscados"
64
- searchProductsTitle="Produtos sugeridos"
65
- />
66
- )
67
-
68
- expect(received.SearchDropdown).toMatchObject({
69
- loadingLabel: 'Carregando...',
70
- })
71
- expect(received.SearchHistory).toMatchObject({
72
- title: 'Histórico',
73
- clearLabel: 'Limpar histórico',
74
- })
75
- expect(received.SearchTop).toMatchObject({ title: 'Mais buscados' })
76
- expect(received.SearchProducts).toMatchObject({
77
- title: 'Produtos sugeridos',
78
- })
79
- })
80
- })
@@ -1,118 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
-
3
- import type { toRevalidate as ToRevalidate } from 'src/utils/toRevalidate'
4
-
5
- const KEY = 'experimental.revalidatePLP'
6
-
7
- // The helper warns once per key per process, so each test loads a fresh
8
- // module to start with no warnings recorded.
9
- let toRevalidate: typeof ToRevalidate
10
-
11
- beforeEach(async () => {
12
- vi.resetModules()
13
- ;({ toRevalidate } = await import('src/utils/toRevalidate'))
14
- })
15
-
16
- afterEach(() => {
17
- vi.restoreAllMocks()
18
- })
19
-
20
- describe('toRevalidate', () => {
21
- it('returns the number of seconds when it is a positive integer', () => {
22
- expect(toRevalidate(300, KEY)).toBe(300)
23
- expect(toRevalidate(1, KEY)).toBe(1)
24
- })
25
-
26
- it('returns false without a warning when the window is disabled or unset', () => {
27
- const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
28
-
29
- expect(toRevalidate(false, KEY)).toBe(false)
30
- expect(toRevalidate(undefined, KEY)).toBe(false)
31
- expect(toRevalidate(null, KEY)).toBe(false)
32
- expect(warn).not.toHaveBeenCalled()
33
- })
34
-
35
- it.each([
36
- // Next.js throws for these.
37
- 0,
38
- -60,
39
- 90.5,
40
- 0.5,
41
- Number.NaN,
42
- Number.POSITIVE_INFINITY,
43
- '300',
44
- // Next.js reads `true` as 1 second; the config expects explicit seconds.
45
- true,
46
- ])('returns false and warns for %s', (value) => {
47
- const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
48
-
49
- expect(toRevalidate(value, KEY)).toBe(false)
50
- expect(warn).toHaveBeenCalledWith(expect.stringContaining(KEY))
51
- })
52
-
53
- it('prints the received value in the warning', () => {
54
- const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
55
-
56
- toRevalidate('300', 'a')
57
- toRevalidate(Number.NaN, 'b')
58
- toRevalidate({ seconds: 300 }, 'c')
59
-
60
- expect(warn).toHaveBeenNthCalledWith(1, expect.stringContaining('"300"'))
61
- expect(warn).toHaveBeenNthCalledWith(2, expect.stringContaining(': NaN.'))
62
- expect(warn).toHaveBeenNthCalledWith(
63
- 3,
64
- expect.stringContaining('a value of type object')
65
- )
66
- })
67
-
68
- it('does not throw for values JSON.stringify rejects', () => {
69
- vi.spyOn(console, 'warn').mockImplementation(() => {})
70
-
71
- const circular: Record<string, unknown> = {}
72
- circular.self = circular
73
-
74
- expect(toRevalidate(circular, 'a')).toBe(false)
75
- expect(toRevalidate({ seconds: BigInt(300) }, 'b')).toBe(false)
76
- expect(toRevalidate(BigInt(300), 'c')).toBe(false)
77
- })
78
-
79
- it('warns about an invalid value once per key', () => {
80
- const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
81
-
82
- toRevalidate('300', KEY)
83
- toRevalidate('300', KEY)
84
-
85
- expect(warn).toHaveBeenCalledTimes(1)
86
- })
87
-
88
- describe('with a minimum', () => {
89
- it('raises a lower window to the minimum and warns once', () => {
90
- const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
91
-
92
- expect(toRevalidate(30, KEY, { min: 60 })).toBe(60)
93
- expect(toRevalidate(30, KEY, { min: 60 })).toBe(60)
94
- expect(toRevalidate(1, KEY, { min: 60 })).toBe(60)
95
- expect(warn).toHaveBeenCalledTimes(1)
96
- expect(warn).toHaveBeenCalledWith(
97
- `[FastStore] ${KEY} is 30s. Using the minimum of 60s.`
98
- )
99
- })
100
-
101
- it('keeps windows at or above the minimum', () => {
102
- const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
103
-
104
- expect(toRevalidate(60, KEY, { min: 60 })).toBe(60)
105
- expect(toRevalidate(120, KEY, { min: 60 })).toBe(120)
106
- expect(warn).not.toHaveBeenCalled()
107
- })
108
-
109
- it('still returns false for invalid values', () => {
110
- vi.spyOn(console, 'warn').mockImplementation(() => {})
111
-
112
- expect(toRevalidate(0, KEY, { min: 60 })).toBe(false)
113
- expect(toRevalidate(30.5, 'a', { min: 60 })).toBe(false)
114
- expect(toRevalidate('30', 'b', { min: 60 })).toBe(false)
115
- expect(toRevalidate(false, 'c', { min: 60 })).toBe(false)
116
- })
117
- })
118
- })