This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest.js
62 lines (49 loc) · 1.67 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
/* eslint-env mocha */
/* eslint no-unused-expressions: off */
'use strict';
const fs = require('fs');
const join = require('path').join;
const expect = require('chai').expect;
const LESSCompiler = require('./');
describe('less-brunch', () => {
let plugin;
beforeEach(() => {
plugin = new LESSCompiler({
paths: {root: '.'},
plugins: {},
});
});
it('should be an object', () => {
expect(plugin).to.be.an.instanceof(LESSCompiler);
});
it('should have #compile method', () => {
expect(plugin).to.respondTo('compile');
});
it('should have #getDependencies method', () => {
expect(plugin).to.respondTo('getDependencies');
});
it('should compile and produce valid result', () => {
const data = '@color: #4D926F; #header {color: @color;}';
const expected = '#header {\n color: #4D926F;\n}\n';
return plugin.compile({data, path: 'style.less'}).then(result => {
expect(result.data).to.equal(expected);
});
});
it('should handle invalid less gracefully', () => {
const data = '#header {color: @color;}';
const expected = 'L1:16 NameError: variable @color is undefined';
return plugin.compile({data, path: 'style.less'}).catch(error => {
expect(error.toString()).to.equal(expected);
});
});
it('should correctly identify stylesheet and data-uri dependencies', () => {
const path = 'test-files/test-dependency-resolution.less';
const data = fs.readFileSync(path, 'utf-8');
return plugin.getDependencies({data, path}).then(deps => {
expect(deps).to.deep.equal([
join('test-files', 'test-include.less'),
join('test-files', 'img', 'foo.jpg'),
]);
});
});
});