forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next-swc.test.ts
51 lines (43 loc) · 1.26 KB
/
next-swc.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
/* eslint-env jest */
import { transform } from 'next/dist/build/swc'
const swc = async (code) => {
let output = await transform(code)
return output.code
}
const trim = (s) => s.join('\n').trim().replace(/^\s+/gm, '')
describe('next/swc', () => {
describe('hook_optimizer', () => {
it('should transform Array-destructured hook return values use object destructuring', async () => {
const output = await swc(
trim`
import { useState } from 'react';
const [count, setCount] = useState(0);
`
)
expect(output).toMatch(trim`
var ref = useState(0), count = ref[0], setCount = ref[1];
`)
expect(output).toMatchInlineSnapshot(`
"import { useState } from \\"react\\";
var ref = useState(0), count = ref[0], setCount = ref[1];
"
`)
})
it('should be able to ignore some Array-destructured hook return values', async () => {
const output = await swc(
trim`
import { useState } from 'react';
const [, setCount] = useState(0);
`
)
expect(output).toMatch(trim`
var ref = useState(0), setCount = ref[1];
`)
expect(output).toMatchInlineSnapshot(`
"import { useState } from \\"react\\";
var ref = useState(0), setCount = ref[1];
"
`)
})
})
})