1 | const babel = require('@babel/core');
|
2 | const { wrap } = require('jest-snapshot-serializer-raw');
|
3 |
|
4 | const preset = require('..');
|
5 |
|
6 | function transform(input, options = {}) {
|
7 | return wrap(
|
8 | babel.transform(input, {
|
9 | filename: 'file.ts',
|
10 | babelrc: false,
|
11 | presets: [preset],
|
12 | sourceMaps: true,
|
13 | }).code
|
14 | );
|
15 | }
|
16 |
|
17 | it('optional-chaining', () => {
|
18 | expect(
|
19 | transform(`
|
20 | foo?.bar;
|
21 | `)
|
22 | ).toMatchSnapshot();
|
23 | });
|
24 | it('nullish-coalescing', () => {
|
25 | expect(
|
26 | transform(`
|
27 | var foo = object.foo ?? "default";
|
28 | `)
|
29 | ).toMatchSnapshot();
|
30 | });
|
31 | it('class-properties', () => {
|
32 | expect(
|
33 | transform(`
|
34 | class Bork {
|
35 | //Property initializer syntax
|
36 | instanceProperty = "bork";
|
37 | boundFunction = () => {
|
38 | return this.instanceProperty;
|
39 | };
|
40 |
|
41 | //Static class properties
|
42 | static staticProperty = "babelIsCool";
|
43 | static staticFunction = function() {
|
44 | return Bork.staticProperty;
|
45 | };
|
46 | }
|
47 | `)
|
48 | ).toMatchSnapshot();
|
49 | });
|
50 | it('preset-typescript', () => {
|
51 | expect(
|
52 | transform(`
|
53 | const x: number = 0;
|
54 | `)
|
55 | ).toMatchSnapshot();
|
56 | });
|
57 | it('plugin-transform-modules-commonjs', () => {
|
58 | expect(
|
59 | transform(`
|
60 | export default 42;
|
61 | `)
|
62 | ).toMatchSnapshot();
|
63 | });
|