Open History to see the last commit
1import { describe, expectTypeOf, it } from 'vitest'
2import { environmentManager } from '..'
3import { isServer } from '../environmentManager'
4import type { IsServerValue } from '../environmentManager'
5β
6describe('environmentManager', () => {
7 describe('IsServerValue', () => {
8 it('should take no arguments and return a boolean', () => {
9 expectTypeOf<IsServerValue>().toEqualTypeOf<() => boolean>()
10 })
11β
12 it('should reject an override that returns a non-boolean', () => {
13 // @ts-expect-error the server check has to answer with a boolean
14 const invalid: IsServerValue = () => 'server'
15β
16 expectTypeOf(invalid).toEqualTypeOf<() => boolean>()
17 })
18β
19 it('should reject an override that requires an argument', () => {
20 // @ts-expect-error the server check is called without any argument
21 const invalid: IsServerValue = (_: string) => true
22β
23 expectTypeOf(invalid).toEqualTypeOf<() => boolean>()
24 })
25 })
26β
27 describe('isServer', () => {
28 it('should be a function returning a boolean, not a boolean constant', () => {
29 // `utils.isServer` is a boolean constant evaluated once at module load,
30 // while this one re-runs the (overridable) check on every call.
31 expectTypeOf(isServer).toEqualTypeOf<() => boolean>()
32 expectTypeOf(isServer()).toEqualTypeOf<boolean>()
33 })
34β
35 it('should take no parameters', () => {
36 expectTypeOf(isServer).parameters.toEqualTypeOf<[]>()
37 })
38 })
39β
40 describe('environmentManager', () => {
41 it('should expose exactly isServer and setIsServer', () => {
42 expectTypeOf<keyof typeof environmentManager>().toEqualTypeOf<
43 'isServer' | 'setIsServer'
44 >()
45 })
46β
47 it('should expose isServer as the standalone check', () => {
48 expectTypeOf(environmentManager.isServer).toEqualTypeOf<() => boolean>()
49 })
50β
51 describe('setIsServer', () => {
52 it('should only accept an IsServerValue and return void', () => {
53 expectTypeOf(environmentManager.setIsServer).parameters.toEqualTypeOf<
54 [isServerValue: IsServerValue]
55 >()
56 expectTypeOf(
57 environmentManager.setIsServer,
58 ).returns.toEqualTypeOf<void>()
59 })
60 })
61 })
62})