forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranspilation-tests.js
122 lines (98 loc) · 3.41 KB
/
transpilation-tests.js
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
// These are tests of Babel's generated output. Write tests here when a runtime
// test won't do. Some tests also serve to catch when Babel changes its output,
// such as when it changes its runtime helpers!
function transform(input) {
return Babel.transformMeteor(input).code;
};
function contains(haystack, needle) {
return haystack.indexOf(needle) >= 0;
};
Tinytest.add("ecmascript - transpilation - const", (test) => {
// make sure `const` is turned into `var` (rather than passing
// through, such as when you have es6.blockScoping on but
// es6.constants off)
const output = transform('const x = 5;');
test.isFalse(contains(output, 'const'));
test.isTrue(contains(output, 'var'));
});
Tinytest.add("ecmascript - transpilation - class methods", (test) => {
const output = transform(
`class Foo {
static staticMethod() {
return 'classy';
}
prototypeMethod() {
return 'prototypical';
}
[computedMethod]() {
return 'computed';
}
}`);
// test that we are in "loose" mode and methods of classes are still
// assigned in a simple matter that does rely on Object.defineProperty.
test.isTrue(contains(output, 'Foo.staticMethod = function staticMethod('));
test.isTrue(contains(output,
'Foo.prototype.prototypeMethod = function prototypeMethod('));
test.isTrue(contains(output, 'Foo.prototype[computedMethod] = function ('));
test.isFalse(contains(output, 'createClass'));
});
Tinytest.add("ecmascript - transpilation - helpers - classCallCheck", (test) => {
const output = transform(`
class Foo {
constructor(x) {
this.x = x;
}
}`);
// test that the classCallCheck helper is still in use
test.isTrue(contains(output, 'babelHelpers.classCallCheck'));
});
Tinytest.add("ecmascript - transpilation - helpers - inherits", (test) => {
const output = transform(`
class Foo {}
class Bar extends Foo {}
`);
test.isTrue(contains(output, 'babelHelpers.inherits'));
});
Tinytest.add("ecmascript - transpilation - helpers - bind", (test) => {
const output = transform(`
var foo = new Foo(...oneTwo, 3);
`);
test.isTrue(contains(output, 'babelHelpers.bind'));
});
Tinytest.add("ecmascript - transpilation - helpers - extends", (test) => {
const output = transform(`
var full = {a:1, ...middle, d:4};
`);
test.isTrue(contains(output, 'babelHelpers._extends'));
});
Tinytest.add("ecmascript - transpilation - helpers - objectWithoutProperties", (test) => {
const output = transform(`
var {a, ...rest} = obj;
`);
test.isTrue(contains(output, 'babelHelpers.objectWithoutProperties'));
});
Tinytest.add("ecmascript - transpilation - helpers - objectDestructuringEmpty", (test) => {
const output = transform(`
var {} = null;
`);
test.isTrue(contains(output, 'babelHelpers.objectDestructuringEmpty'));
});
Tinytest.add("ecmascript - transpilation - helpers - taggedTemplateLiteralLoose", (test) => {
const output = transform(`
var x = asdf\`A\${foo}C\`
`);
test.isTrue(contains(output, 'babelHelpers.taggedTemplateLiteralLoose'));
});
Tinytest.add("ecmascript - transpilation - helpers - createClass", (test) => {
const output = transform(`
class Foo {
get blah() { return 123; }
}
`);
test.isTrue(contains(output, 'babelHelpers.createClass'));
});
Tinytest.add("ecmascript - transpilation - flow", (test) => {
const output = transform(
'var foo = function (one: any, two: number, three?): string {};');
test.isTrue(contains(output, '(one, two, three)'));
});