Skip to content

Commit 490c85f

Browse files
committed
Merge branch 'source-paths-remapping'
2 parents c7bc688 + b29f606 commit 490c85f

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,23 @@ module.exports = function(config) {
144144
};
145145
```
146146

147+
The code below shows a sample configuration of the preprocessor with source map loading only for files with the `sourceMappingURL` set. The default behaviour is trying to load source maps for all JavaScript files, also those without the `sourceMappingURL` set.
148+
149+
```js
150+
// karma.conf.js
151+
module.exports = function(config) {
152+
config.set({
153+
plugins: ['karma-sourcemap-loader'],
154+
preprocessors: {
155+
'**/*.js': ['sourcemap']
156+
},
157+
sourceMapLoader: {
158+
onlyWithURL: true
159+
}
160+
});
161+
};
162+
```
163+
147164
The code below shows a sample configuration of the preprocessor with a strict error checking. A missing or an invalid source map will cause the test run fail.
148165

149166
```js

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var createSourceMapLocatorPreprocessor = function(args, logger, config) {
99
var remapPrefixes = options.remapPrefixes;
1010
var remapSource = options.remapSource;
1111
var useSourceRoot = options.useSourceRoot;
12+
var onlyWithURL = options.onlyWithURL;
1213
var strict = options.strict;
1314
var needsUpdate = remapPrefixes || remapSource || useSourceRoot;
1415

@@ -228,7 +229,11 @@ var createSourceMapLocatorPreprocessor = function(args, logger, config) {
228229
}
229230

230231
if (!mapUrl) {
231-
fileMap(file.path + ".map", true);
232+
if (onlyWithURL) {
233+
done(content);
234+
} else {
235+
fileMap(file.path + ".map", true);
236+
}
232237
} else if (/^data:application\/json/.test(mapUrl)) {
233238
inlineMap(mapUrl.slice('data:application/json'.length));
234239
} else {

test/karma.source-root-value.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const sharedConfig = require('./karma.shared');
33
module.exports = function (config) {
44
config.set(Object.assign({}, sharedConfig(config, 'test-source-root'), {
55
sourceMapLoader: {
6-
useSourceRoot: '/sources'
6+
useSourceRoot: '/sources',
7+
onlyWithURL: true // Just to complete the code coverage
78
}
89
}));
910
};

0 commit comments

Comments
 (0)