forked from codymikol/karma-webpack
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmocha-env-loader.js
31 lines (26 loc) · 888 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
var path = require("path");
var SourceNode = require("source-map").SourceNode;
var loaderUtils = require("loader-utils");
module.exports = function(content, map) {
this.cacheable();
var id = this.options.name;
if(!id) this.callback(null, content, map);
if(map) {
var sourceNode = SourceNode.fromSourceWithMap(content, map);
} else {
var fileName = loaderUtils.getRemainingRequest(this);
var 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());
};