forked from brunch/coffee-script-brunch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
77 lines (61 loc) · 2.07 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
var expect = require('chai').expect;
var Plugin = require('./');
describe('Plugin', function() {
var plugin;
beforeEach(function() {
plugin = new Plugin({});
});
it('should be an object', function() {
expect(plugin).to.be.ok;
});
it('should has #compile method', function() {
expect(plugin.compile).to.be.an.instanceof(Function);
});
it('should compile and produce valid result', function(done) {
var content = 'a = 1';
var expected = 'var a;\n\na = 1;\n';
plugin.compile(content, 'file.coffee', function(error, data) {
expect(error).not.to.be.ok;
expect(data.data).to.equal(expected);
done();
});
});
it('should compile literal source and produce valid result', function(done)
{
var content = 'I am a literal string\n\n a = 1';
var expected = 'var a;\n\na = 1;\n';
plugin.compile(content, 'file.litcoffee', function(error, data) {
expect(error).not.to.be.ok;
expect(data.data).to.equal(expected);
done();
});
});
it('should produce source maps', function(done) {
plugin = new Plugin({sourceMaps: true});
var content = 'a = 1';
var expected = 'var a;\n\na = 1;\n';
plugin.compile(content, 'file.coffee', function(error, data) {
expect(error).not.to.be.ok;
expect(data.data).to.equal(expected);
expect(data.map).to.be.a('string');
done();
});
});
it('should support explicit bare setting', function(done) {
plugin = new Plugin({plugins:{coffeescript:{bare:false}}});
var content = 'a = 1';
var expected = '(function() {\n var a;\n\n a = 1;\n\n}).call(this);\n';
plugin.compile(content, 'file.coffee', function(error, data) {
expect(error).not.to.be.ok;
expect(data.data).to.equal(expected);
plugin = new Plugin({plugins:{coffeescript:{bare:true}}});
content = 'a = 1';
expected = 'var a;\n\na = 1;\n';
plugin.compile(content, 'file.coffee', function(error, data) {
expect(error).not.to.be.ok;
expect(data.data).to.equal(expected);
done();
});
});
});
});