@faststore/core 4.11.4-dev.2 → 4.11.4-dev.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,6 +3,18 @@
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
+
6
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)
7
19
 
8
20
  **Note:** Version bump only for package @faststore/core
@@ -93,7 +93,17 @@
93
93
  "searchTopTitle": {
94
94
  "title": "Top Search Title",
95
95
  "type": "string",
96
- "default": "Top search"
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"
97
107
  },
98
108
  "quickOrderSettings": {
99
109
  "title": "Quick Order settings",
@@ -2064,7 +2064,17 @@
2064
2064
  "searchTopTitle": {
2065
2065
  "title": "Top Search Title",
2066
2066
  "type": "string",
2067
- "default": "Top search"
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"
2068
2078
  },
2069
2079
  "quickOrderSettings": {
2070
2080
  "title": "Quick Order settings",
@@ -235,7 +235,17 @@
235
235
  "searchTopTitle": {
236
236
  "title": "Top Search Title",
237
237
  "type": "string",
238
- "default": "Top search"
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"
239
249
  },
240
250
  "quickOrderSettings": {
241
251
  "title": "Quick Order settings",
@@ -196,6 +196,11 @@ 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,
199
204
  enableSearchSSR: false,
200
205
  enableFaststoreMyAccount: false,
201
206
  useIsGiftFromOrderForm: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/core",
3
- "version": "4.11.4-dev.2",
3
+ "version": "4.11.4-dev.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/diagnostics": "4.11.4-dev.2",
74
- "@faststore/sdk": "4.11.4-dev.2",
75
- "@faststore/api": "4.11.4-dev.2",
76
- "@faststore/lighthouse": "4.11.4-dev.2",
77
- "@faststore/ui": "4.11.4-dev.2"
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"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@cypress/code-coverage": "^3.12.1",
@@ -185,6 +185,8 @@ 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}
188
190
  />
189
191
  )}
190
192
 
@@ -222,6 +224,8 @@ function Navbar({
222
224
  loadingLabel={searchInput?.loadingLabel}
223
225
  searchHistoryTitle={searchInput?.searchHistoryTitle}
224
226
  searchTopTitle={searchInput?.searchTopTitle}
227
+ searchHistoryClearLabel={searchInput?.searchHistoryClearLabel}
228
+ searchProductsTitle={searchInput?.searchProductsTitle}
225
229
  />
226
230
  )}
227
231
 
@@ -24,7 +24,9 @@ interface SearchDropdownProps {
24
24
  sort: SearchState['sort']
25
25
  quickOrderSettings?: NavbarProps['searchInput']['quickOrderSettings']
26
26
  searchHistoryTitle?: string
27
+ searchHistoryClearLabel?: string
27
28
  searchTopTitle?: string
29
+ searchProductsTitle?: string
28
30
  [key: string]: any
29
31
  onChangeCustomSearchDropdownVisible?: Dispatch<SetStateAction<boolean>>
30
32
  }
@@ -47,10 +49,12 @@ function SearchDropdown({
47
49
  sort,
48
50
  quickOrderSettings,
49
51
  searchHistoryTitle,
52
+ searchHistoryClearLabel,
50
53
  searchTopTitle,
54
+ searchProductsTitle,
51
55
  onChangeCustomSearchDropdownVisible,
52
56
  ...otherProps
53
- }: SearchDropdownProps) {
57
+ }: Readonly<SearchDropdownProps>) {
54
58
  const {
55
59
  values: { onSearchSelection, products, term, terms, searchId },
56
60
  } = useSearch()
@@ -58,7 +62,11 @@ function SearchDropdown({
58
62
 
59
63
  return (
60
64
  <UISearchDropdown {...otherProps}>
61
- <SearchHistory title={searchHistoryTitle} sort={sort} />
65
+ <SearchHistory
66
+ title={searchHistoryTitle}
67
+ clearLabel={searchHistoryClearLabel}
68
+ sort={sort}
69
+ />
62
70
  <SearchTop title={searchTopTitle} sort={sort} />
63
71
  <UISearchAutoComplete>
64
72
  {terms?.map(({ value: suggestion }) => (
@@ -95,6 +103,7 @@ function SearchDropdown({
95
103
  ))}
96
104
  </UISearchAutoComplete>
97
105
  <SearchProducts
106
+ title={searchProductsTitle}
98
107
  data-af-element={searchId && 'search-autocomplete'}
99
108
  data-af-onimpression={!!searchId}
100
109
  data-af-search-id={searchId}
@@ -7,10 +7,15 @@ import useSearchHistory from 'src/sdk/search/useSearchHistory'
7
7
 
8
8
  interface SearchHistoryProps {
9
9
  title?: string
10
+ clearLabel?: string
10
11
  [key: string]: unknown
11
12
  }
12
13
 
13
- const SearchHistory = ({ title, ...props }: SearchHistoryProps) => {
14
+ const SearchHistory = ({
15
+ title,
16
+ clearLabel,
17
+ ...props
18
+ }: Readonly<SearchHistoryProps>) => {
14
19
  const {
15
20
  values: { onSearchSelection },
16
21
  } = useSearch()
@@ -21,7 +26,12 @@ const SearchHistory = ({ title, ...props }: SearchHistoryProps) => {
21
26
  }
22
27
 
23
28
  return (
24
- <UISearchHistory title={title} onClear={clearSearchHistory} {...props}>
29
+ <UISearchHistory
30
+ title={title}
31
+ clearLabel={clearLabel}
32
+ onClear={clearSearchHistory}
33
+ {...props}
34
+ >
25
35
  {searchHistory.map((item) => (
26
36
  <UISearchHistoryTerm
27
37
  key={item.term}
@@ -73,7 +73,9 @@ export type SearchInputProps = {
73
73
  submitButtonAriaLabel?: string
74
74
  loadingLabel?: string
75
75
  searchHistoryTitle?: string
76
+ searchHistoryClearLabel?: string
76
77
  searchTopTitle?: string
78
+ searchProductsTitle?: string
77
79
  } & Omit<UISearchInputFieldProps, 'onSubmit' | 'attachmentButtonIcon'>
78
80
 
79
81
  export type SearchInputRef = UISearchInputFieldRef & {
@@ -114,6 +116,11 @@ const SearchInput = forwardRef<SearchInputRef, SearchInputProps>(
114
116
  sort,
115
117
  placeholder,
116
118
  quickOrderSettings,
119
+ loadingLabel,
120
+ searchHistoryTitle,
121
+ searchHistoryClearLabel,
122
+ searchTopTitle,
123
+ searchProductsTitle,
117
124
  ...otherProps
118
125
  },
119
126
  ref
@@ -390,6 +397,11 @@ const SearchInput = forwardRef<SearchInputRef, SearchInputProps>(
390
397
  onChangeCustomSearchDropdownVisible={
391
398
  setCustomSearchDropdownVisibleCondition
392
399
  }
400
+ loadingLabel={loadingLabel}
401
+ searchHistoryTitle={searchHistoryTitle}
402
+ searchHistoryClearLabel={searchHistoryClearLabel}
403
+ searchTopTitle={searchTopTitle}
404
+ searchProductsTitle={searchProductsTitle}
393
405
  />
394
406
  </Suspense>
395
407
  )}
@@ -25,7 +25,9 @@ export interface NavbarProps {
25
25
  sort: string
26
26
  submitButtonAriaLabel?: string
27
27
  searchHistoryTitle?: string
28
+ searchHistoryClearLabel?: string
28
29
  searchTopTitle?: string
30
+ searchProductsTitle?: string
29
31
  collapseSearchAriaLabel?: string
30
32
  quickOrderSettings?: {
31
33
  quickOrder: boolean
@@ -32,6 +32,7 @@ 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'
35
36
 
36
37
  const LandingPage = dynamic(
37
38
  () => import('src/components/templates/LandingPage')
@@ -244,6 +245,15 @@ export const getStaticProps: GetStaticProps<
244
245
  type: 'plp',
245
246
  key: slug,
246
247
  },
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
+ ),
247
257
  }
248
258
  }
249
259
 
@@ -0,0 +1,74 @@
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
+ }
@@ -0,0 +1,80 @@
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
+ })
@@ -3,12 +3,30 @@
3
3
  */
4
4
 
5
5
  import React from 'react'
6
- import { act, render, waitFor } from '@testing-library/react'
6
+ import { act, fireEvent, render, waitFor } from '@testing-library/react'
7
7
  import { afterEach, describe, expect, it, vi } from 'vitest'
8
8
 
9
- // ─── next/dynamic: return a plain functional component ───────────────────────
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.
10
12
  vi.mock('next/dynamic', () => ({
11
- default: () => () => null,
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
+ },
12
30
  }))
13
31
 
14
32
  // ─── next/router ─────────────────────────────────────────────────────────────
@@ -17,7 +35,16 @@ vi.mock('next/router', () => ({
17
35
  }))
18
36
 
19
37
  // ─── lazy-loaded chunk ───────────────────────────────────────────────────────
20
- vi.mock('src/components/search/SearchDropdown', () => ({ default: () => null }))
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
+ }))
21
48
 
22
49
  // ─── discovery.config ────────────────────────────────────────────────────────
23
50
  vi.mock('discovery.config', () => ({
@@ -125,6 +152,7 @@ import SearchInput from '../../../src/components/search/SearchInput/SearchInput'
125
152
 
126
153
  afterEach(() => {
127
154
  vi.clearAllMocks()
155
+ dropdownProps.current = null
128
156
  oesState.status = null
129
157
  oesState.isUploading = false
130
158
  oesState.isProcessing = false
@@ -274,3 +302,42 @@ describe('SearchInput (OES integration)', () => {
274
302
  expect(true).toBe(true)
275
303
  })
276
304
  })
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
+ })
@@ -0,0 +1,118 @@
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
+ })