This repository has been archived by the owner on Feb 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
test.js
127 lines (100 loc) · 3.21 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
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
'use strict';
const expect = require('chai').expect;
const CoffeeCompiler = require('./');
describe('coffee-script-brunch', () => {
const path = 'file.coffee';
let plugin;
beforeEach(() => {
plugin = new CoffeeCompiler({
conventions: {},
plugins: {},
});
});
it('should be an object', () => {
expect(plugin).to.be.an.instanceof(CoffeeCompiler);
});
it('should have #compile method', () => {
expect(plugin).to.respondTo('compile');
});
it('should compile and produce valid result', () => {
const data = 'a = 1';
const expected = 'var a;\n\na = 1;\n';
return plugin.compile({data, path}).then(file => {
expect(file.data).to.equal(expected);
});
});
it('should compile literal source and produce valid result', () => {
const data = 'I am a literal string\n\n a = 1';
const path = 'file.litcoffee';
const expected = '// I am a literal string\nvar a;\n\na = 1;\n';
return plugin.compile({data, path}).then(file => {
expect(file.data).to.equal(expected);
});
});
it('should produce source maps', () => {
plugin = new CoffeeCompiler({
conventions: {},
plugins: {},
sourceMaps: true,
});
const data = 'a = 1';
const expected = 'var a;\n\na = 1;\n';
return plugin.compile({data, path}).then(file => {
expect(file.data).to.equal(expected);
expect(file.map).to.be.a('string');
});
});
it('should produce inline source maps', () => {
plugin = new CoffeeCompiler({
conventions: {},
plugins: {},
sourceMaps: 'inline',
});
const data = 'a = 1';
return plugin.compile({data, path}).then(file => {
expect(file.data).to
.include(data)
.include('//# sourceMappingURL=data:application/json;base64,')
.include(`//# sourceURL=${path}`);
});
});
it('should support explicit bare setting', () => {
plugin = new CoffeeCompiler({
conventions: {},
plugins: {coffeescript: {bare: false}},
});
let data = 'a = 1';
let expected = '(function() {\n var a;\n\n a = 1;\n\n}).call(this);\n';
return plugin.compile({data, path}).then(file => {
expect(file.data).to.equal(expected);
plugin = new CoffeeCompiler({
conventions: {},
plugins: {coffeescript: {bare: true}},
});
data = 'a = 1';
expected = 'var a;\n\na = 1;\n';
return plugin.compile({data, path}).then(file => {
expect(file.data).to.equal(expected);
});
});
});
it('should support transpile settings', () => {
plugin = new CoffeeCompiler({
conventions: {},
plugins: {coffeescript: {transpile: false}},
});
const data = 'a = () => {};';
let expected = 'var a;\n\na = () => {\n return {};\n};\n';
return plugin.compile({data, path}).then(file => {
expect(file.data).to.equal(expected);
plugin = new CoffeeCompiler({
conventions: {},
plugins: {coffeescript: {transpile: {plugins: ['@babel/plugin-transform-arrow-functions']}}},
});
expected = 'var a;\n\na = function () {\n return {};\n};';
return plugin.compile({data, path}).then(file => {
expect(file.data).to.equal(expected);
});
});
});
});