-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
98 lines (78 loc) · 2.79 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
'use strict';
var assert = require('assert');
var RSVP = require('rsvp');
var gutil = require('gulp-util');
var systemResolver = require('./');
var path = require('path');
var fixture = [
"/* @importPath '~bourbon' */",
'@import "~bourbon/test.scss"',
"@import '~neat/test.scss'",
"@import './variable/test.scss'",
'p {background-color: 10px}'
].join('\n');
var expected = [
"/* @importPath '~bourbon' */",
'@import "path/resolved/bourbon/test.scss"',
"@import 'path/resolved/neat/test.scss'",
"@import './variable/test.scss'",
'p {background-color: 10px}'
].join('\n');
var includePaths = [];
it('should resolve the import string', function(done) {
var stream = systemResolver({systemConfig: './fixtures/config.js', includePaths: includePaths});
stream.write(new gutil.File({
base : __dirname,
path : __dirname + '/file.ext',
contents: new Buffer(fixture)
}));
stream.on('data', function(file) {
assert.strictEqual(file.contents.toString('utf8'), expected);
assert.deepEqual(includePaths, [__dirname + path.sep + path.join('path', 'resolved', 'bourbon')]);
done();
});
RSVP.on('error', done);
});
it('shoud not throw exception when no resolution needed', function(done) {
var stream = systemResolver({systemConfig: './fixtures/config.js', includePaths: includePaths});
stream.write(new gutil.File({
base : __dirname,
path : __dirname + path.sep + 'file.ext',
contents: new Buffer("@import './variable/test.scss'")
}));
stream.on('data', function(file) {
assert.strictEqual(file.contents.toString('utf8'), "@import './variable/test.scss'");
done();
});
RSVP.on('error', done);
});
it('should append path', function(done) {
includePaths = ['Exemple1'];
var stream = systemResolver({systemConfig: './fixtures/config.js', includePaths: includePaths});
stream.write(new gutil.File({
base : __dirname,
path : __dirname + path.sep + 'file.ext',
contents: new Buffer(fixture)
}));
stream.on('data', function(file) {
assert.strictEqual(file.contents.toString('utf8'), expected);
assert.deepEqual(includePaths, ["Exemple1", __dirname + path.sep + path.join('path', 'resolved', 'bourbon')]);
done();
});
RSVP.on('error', done);
});
it('should resolve path', function(done) {
includePaths = [];
var stream = systemResolver({systemConfig: './fixtures/config.js', includePaths: includePaths});
stream.write(new gutil.File({
base : __dirname,
path : __dirname + path.sep + 'file.ext',
contents: new Buffer('/* @importPath "~bourbon" */')
}));
stream.on('data', function(file) {
assert.strictEqual(file.contents.toString('utf8'), '/* @importPath "~bourbon" */');
assert.deepEqual(includePaths, [__dirname + path.sep + path.join('path', 'resolved', 'bourbon')]);
done();
});
RSVP.on('error', done);
});