-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.mjs
60 lines (52 loc) · 2.47 KB
/
test.mjs
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
import { expect } from 'chai';
import { RollupCompiler } from './index.js';
describe('Plugin', function() {
var plugin;
beforeEach(function() {
plugin = new RollupCompiler({});
});
it('is an object', function() {
expect(plugin).to.be.ok;
});
it('has #compile method', function() {
expect(plugin.compile).to.be.an.instanceof(Function);
});
it('compiles and produces valid result', function() {
var content = 'export function a(x,y){\nreturn x+y;\n}';
var expected = "(function (global, factory) {\n"
+ "\ttypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\n"
+ "\ttypeof define === 'function' && define.amd ? define(['exports'], factory) :\n"
+ "\t(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.file = global.file || {}, global.file.js = {})));\n"
+ "})(this, (function (exports) { 'use strict';\n\n"
+ "\tfunction a(x,y){\n"
+ "\treturn x+y;\n"
+ "\t}\n\n"
+ "\texports.a = a;\n\n"
+ "}));\n";
return plugin.compile({data: content, path: 'file.js'}).then(compiled => {
expect(compiled.data).to.be.equal(expected);
}, error => expect(error).not.to.be.ok);
});
it('compiles and produces valid result and sourcemap', function() {
plugin = new RollupCompiler({plugins: {rollup: {sourcemap: true}}});
var content = 'export const a = 1;';
var expected = "(function (global, factory) {\n"
+ "\ttypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\n"
+ "\ttypeof define === 'function' && define.amd ? define(['exports'], factory) :\n"
+ "\t(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.file = global.file || {}, global.file.js = {})));\n"
+ "})(this, (function (exports) { 'use strict';\n\n"
+ "\tconst a = 1;\n\n"
+ "\texports.a = a;\n\n"
+ "}));\n";
var expectedMap = '{"version":3,"file":"file.js","sources":["file.js"],'
+ '"sourcesContent":["' + content + '"],'
+ '"names":[],"mappings":";;;;;;AAAY,OAAC,CAAC,GAAG;;;;;;;;"}';
return plugin.compile({data: content, path: 'file.js'}).then(compiled => {
expect(compiled).to.be.an('object');
expect(compiled.data).to.be.a('string');
expect(compiled.data).to.equal(expected);
expect(compiled.map).to.be.a('string');
expect(compiled.map).to.equal(expectedMap);
}, error => expect(error).not.to.be.ok);
});
});