forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
149 lines (128 loc) · 3.42 KB
/
index.test.ts
File metadata and controls
149 lines (128 loc) · 3.42 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { convertEsModule } from '.';
describe('convert-esmodule', () => {
it('can convert reexports', () => {
const code = `
export * from './test/store.js';
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('can convert normal exports', () => {
const code = `
export { test, test2 } from './test/store.js';
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('can convert function exports', () => {
const code = `
export function test() {}
export const test2 = () => {}
export class Test {}
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('can convert default exports', () => {
const code = `
export default function test() {}
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('can convert class default exports', () => {
const code = `
export default class A {}
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('can convert weird default exports', () => {
const code = `
export default a = 'b';
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('can convert default imports', () => {
const code = `
import a from './b';
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('can convert named imports', () => {
const code = `
import {a, b, c} from './b';
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('can handle as imports', () => {
const code = `
import { a as b } from './b';
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('ignores comments', () => {
const code = `
// import { a as b } from './b';
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('can handle inline comments', () => {
const code = `
import { a as b, /* HELLO WORLD */ c } from './b';
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('can handle class properties', () => {
const code = `
import T from './test';
class T2 {
a = () => {
return 'test'
}
b = ''
c = {}
static d = ''
}
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('can handle async code', () => {
const code = `
import T from './test';
async () => {
const test = await test2()
}
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('handles export mutations', () => {
const code = `
export default function test() {}
test = 5;
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('handles export mutations with no named function', () => {
const code = `
export default function() {}
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('handles default as exports', () => {
const code = `
export { default as Field } from './Field';
`;
expect(convertEsModule(code)).toMatchSnapshot();
});
it('parses and writes chars with linebreaks', () => {
const code =
"var WS_CHARS = 'u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff'";
expect(convertEsModule(code)).toMatchSnapshot();
});
it('has good perf', () => {
/* eslint-disable */
const code = require('./big-file');
const t = Date.now();
for (let i = 0; i < 1; i++) {
convertEsModule(code);
}
console.log(Date.now() - t);
/* eslint-enable */
});
});