-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest.js
90 lines (76 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
var fs = require('fs')
var path = require('path')
var assetFunctions = require('../')
var renderAsync = function(sass, file, options, done) {
options = options || {}
options.images_path = __dirname + '/images'
options.fonts_path = __dirname + '/fonts'
options.implemantation = sass
return sass.render({
functions: assetFunctions(options),
file: __dirname + '/scss/' + file,
}, done)
}
var equalsFileAsync = function(sass, file, suite, options, done) {
renderAsync(sass, file, options, function(err, result) {
expect(err).toBeNull()
var cssPath = path.join(cssDir, suite, file.replace(/\.scss$/, '.css'))
fs.readFile(cssPath, function(err, expected) {
expect(err).toBeNull()
expect(result.css.toString()).toEqual(expected.toString())
done()
})
})
}
var sassDir = path.join(__dirname, 'scss')
var cssDir = path.join(__dirname, 'css')
var asset_host = function(http_path, done) {
done('http://example.com')
}
var query_asset_cache_buster = function(http_path, real_path, done) {
setTimeout(function() {
done('v=123')
}, 10)
}
var path_asset_cache_buster = function(http_path, real_path, done) {
setTimeout(function() {
var extname = path.extname(http_path)
, basename = path.basename(http_path, extname)
, dirname = path.dirname(http_path)
done({path: path.join(dirname, basename + '-v123') + extname, query: null})
}, 10)
}
var files = fs.readdirSync(sassDir)
describe.each(['node-sass', 'sass'])('with require("%s")', function(impl) {
var sass = require(impl)
describe('basic', function() {
files.forEach(function(file) {
test(file, function(done) {
equalsFileAsync(sass, file, 'basic', {}, done)
})
})
})
describe('asset_host', function() {
files.forEach(function(file) {
test(file, function(done) {
equalsFileAsync(sass, file, 'asset_host', { asset_host: asset_host }, done)
})
})
})
describe('asset_cache_buster', function() {
describe('using query', function() {
files.forEach(function(file) {
test(file, function(done) {
equalsFileAsync(sass, file, 'asset_cache_buster/query', { asset_cache_buster: query_asset_cache_buster }, done)
})
})
})
describe('using path', function() {
files.forEach(function(file) {
test(file, function(done) {
equalsFileAsync(sass, file, 'asset_cache_buster/path', { asset_cache_buster: path_asset_cache_buster }, done)
})
})
})
})
})