-
Notifications
You must be signed in to change notification settings - Fork 220
/
mocha-env-loader.js
36 lines (27 loc) · 922 Bytes
/
mocha-env-loader.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
//var path = require('path')
var SourceNode = require('source-map').SourceNode
var loaderUtils = require('loader-utils')
module.exports = function(content, map) {
this.cacheable()
var sourceNode
var id = this.options.name
if (!id) {
this.callback(null, content, map)
}
if (map) {
sourceNode = SourceNode.fromSourceWithMap(content, map)
} else {
var fileName = loaderUtils.getRemainingRequest(this)
sourceNode = new SourceNode(null, null, null)
content.split('\n').forEach(function(line, idx) {
sourceNode.add(new SourceNode(idx + 1, 0, fileName, line + '\n'))
})
sourceNode.setSourceContent(fileName, content)
}
var concatSrc = new SourceNode()
concatSrc.add([
'describe(' + JSON.stringify(id) + ', function() {\n', sourceNode, '\n});'
])
var result = concatSrc.toStringWithSourceMap()
this.callback(undefined, result.code, result.map.toString())
}