forked from shreeve/coffeescript-brunch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
102 lines (81 loc) · 2.47 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
'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 = 'var 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);
});
});
});
});