-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
30 lines (22 loc) · 1.5 KB
/
test.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
var fakeImport = require('./')
var test = require('tape')
test('test imports', function (t) {
t.plan(8);
t.ok(fakeImport('import React from \'React\'') == 'const React = require("React");\n');
t.ok(fakeImport('import React from "React"') == 'const React = require("React");\n');
t.ok(fakeImport('import\t\'React\'') == 'require("React");\n');
t.ok(fakeImport('import\n\t\n"React"') == 'require("React");\n');
t.ok(fakeImport('import {h1, p} from \'React\'') == 'var h1 = require("React").h1;\nvar p = require("React").p;');
t.ok(fakeImport('import {\th1,\t\tp } from "React"') == 'var h1 = require("React").h1;\nvar p = require("React").p;');
t.ok(fakeImport('import React, {h1, p} from \'React\'') == 'const React = require("React");\nvar h1 = require("React").h1;\nvar p = require("React").p;');
t.ok(fakeImport('import React , {\th1,\t\tp } from "React"') == 'const React = require("React");\nvar h1 = require("React").h1;\nvar p = require("React").p;');
})
test('test exports', function (t) {
t.plan(6);
t.ok(fakeImport('export default MyVar') == 'module.exports = MyVar');
t.ok(fakeImport('export var MyVar') == 'var MyVar = module.exports.MyVar');
t.ok(fakeImport('export let MyVar') == 'let MyVar = module.exports.MyVar');
t.ok(fakeImport('export const MyVar') == 'const MyVar = module.exports.MyVar');
t.ok(fakeImport('export function MyVar') == 'var MyVar = module.exports.MyVar = function');
t.ok(fakeImport('export class MyVar') == 'var MyVar = module.exports.MyVar = class');
})