Skip to content

@repobuddy/vitest/setup/browser

@repobuddy/vitest/setup/browser makes Intl.DateTimeFormat().resolvedOptions().timeZone report GMT in browser tests.

browserTestPreset() adds it to test.setupFiles for you. Add it yourself only in a browser config that does not use the preset:

export default defineConfig({
test: { setupFiles: ['@repobuddy/vitest/setup/browser'] },
})

None. The file exports nothing.

  • Before the tests in each file (beforeAll), it spies on Intl.DateTimeFormat.prototype.resolvedOptions and returns the original options with timeZone: 'GMT'.
  • After the tests in each file (afterAll), it calls vi.restoreAllMocks().
  • It changes only what resolvedOptions() returns. It does not change the time zone the browser uses to format dates.
  • vi.restoreAllMocks() in afterAll also restores spies your own tests left in place at the end of the file.
  • In Node.js, nodeTestPreset() sets process.env.TZ instead.
// a.spec.tsx, run by browserTestPreset()
it('reports GMT', () => {
expect(Intl.DateTimeFormat().resolvedOptions().timeZone).toBe('GMT')
})