forked from vitest-dev/vitest
/
module.test.ts
63 lines (55 loc) · 2.03 KB
/
module.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { expect, it } from 'vitest'
// @ts-expect-error is not typed
import cjs, { a, b } from '../src/cjs/module-cjs'
// @ts-expect-error is not typed with imports
import bareCjs, { a as bareA, b as bareB } from '../src/cjs/bare-cjs'
// @ts-expect-error is not typed with imports
import primitiveCjs, { a as primitiveA } from '../src/cjs/primitive-cjs'
// @ts-expect-error is not typed with imports
import * as primitiveAll from '../src/cjs/primitive-cjs'
// @ts-expect-error is not typed with imports
import * as arrayCjs from '../src/cjs/array-cjs'
// @ts-expect-error is not typed with imports
import * as classCjs from '../src/cjs/class-cjs'
// @ts-expect-error is not typed with imports
import * as internalEsm from '../src/esm/internal-esm.mjs'
import c, { d } from '../src/module-esm'
import * as timeout from '../src/timeout'
it('doesn\'t when extending module', () => {
expect(() => Object.assign(globalThis, timeout)).not.toThrow()
})
it('should work when using module.exports cjs', () => {
expect(cjs.a).toBe(1)
expect(cjs.b).toBe(2)
expect(a).toBe(1)
expect(b).toBe(2)
})
it('works with bare exports cjs', () => {
expect(bareCjs.a).toBe('a')
expect(bareCjs.b).toBe('b')
expect(bareCjs.c).toBe('c')
expect(bareA).toBe('a')
expect(bareB).toBe('b')
})
it('primitive cjs retains its logic', () => {
expect(primitiveA).toBeUndefined()
expect(primitiveCjs).toBe('string')
expect(primitiveAll.default).toBe('string')
expect(primitiveAll, 'doesn\'t put chars from "string" on exports').not.toHaveProperty('0')
})
it('arrays-cjs', () => {
expect(arrayCjs.default).toEqual([1, '2'])
expect(arrayCjs).not.toHaveProperty('0')
})
it('class-cjs', () => {
expect(classCjs.default).toEqual({ variable: 1, Test: expect.any(Function) })
expect(classCjs.default).toBeInstanceOf(classCjs.Test)
expect(classCjs).not.toHaveProperty('variable')
})
it('should work when using esm module', () => {
expect(c).toBe(1)
expect(d).toBe(2)
})
it('exports all from native ESM module', () => {
expect(internalEsm).toHaveProperty('restoreAll')
})