Skip to content

Commit

Permalink
feat(sourcemaps): inlcude sourcemaps in karma configuration
Browse files Browse the repository at this point in the history
add the bundle source maps to karma files configuration and add inline source maps to transpiler options so unit tests also have source maps.

closes #420
  • Loading branch information
simonfox committed Jul 6, 2017
1 parent cc65ec9 commit ebd79e8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/commands/new/unit-test-runners/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module.exports = function(project) {
'jasmine-core',
'karma',
'karma-chrome-launcher',
'karma-jasmine'
'karma-jasmine',
'karma-sourcemap-loader'
);

if (project.model.transpiler.id === 'babel') {
Expand Down
1 change: 1 addition & 0 deletions lib/dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"karma-jasmine": "^1.0.2",
"karma-babel-preprocessor": "^6.0.1",
"karma-typescript-preprocessor": "^0.2.1",
"karma-sourcemap-loader": "^0.3.7",
"minimatch": "^3.0.2",
"requirejs": "^2.3.2",
"text": "github:requirejs/text#latest",
Expand Down
11 changes: 8 additions & 3 deletions lib/resources/content/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ let output = project.platform.output;
let appSrc = project.build.bundles.map(x => path.join(output, x.name));
let entryIndex = appSrc.indexOf(path.join(output, project.build.loader.configTarget));
let entryBundle = appSrc.splice(entryIndex, 1)[0];
let files = [entryBundle].concat(testSrc).concat(appSrc);
let sourceMaps = [{pattern:'scripts/**/*.js.map', included: false}];
let files = [entryBundle].concat(testSrc).concat(appSrc).concat(sourceMaps);

let transpilerOptions = project.transpiler.options;
transpilerOptions.sourceMap = 'inline';

module.exports = function(config) {
config.set({
Expand All @@ -20,9 +24,10 @@ module.exports = function(config) {
files: files,
exclude: [],
preprocessors: {
[project.unitTestRunner.source]: [project.transpiler.id]
[project.unitTestRunner.source]: [project.transpiler.id],
[appSrc]: ['sourcemap']
},
'babelPreprocessor': { options: project.transpiler.options },
'babelPreprocessor': { options: transpilerOptions },
reporters: ['progress'],
port: 9876,
colors: true,
Expand Down
12 changes: 9 additions & 3 deletions lib/resources/content/karma.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ let output = project.platform.output;
let appSrc = project.build.bundles.map(x => path.join(output, x.name));
let entryIndex = appSrc.indexOf(path.join(output, project.build.loader.configTarget));
let entryBundle = appSrc.splice(entryIndex, 1)[0];
let files = [entryBundle].concat(testSrc).concat(appSrc);
let sourceMaps = [{pattern:'scripts/**/*.js.map', included: false}];
let files = [entryBundle].concat(testSrc).concat(appSrc).concat(sourceMaps);

let compilerOptions = tsconfig.compilerOptions;
compilerOptions.inlineSourceMap = true;
compilerOptions.inlineSources = true;

module.exports = function(config) {
config.set({
Expand All @@ -21,11 +26,12 @@ module.exports = function(config) {
files: files,
exclude: [],
preprocessors: {
[project.unitTestRunner.source]: [project.transpiler.id]
[project.unitTestRunner.source]: [project.transpiler.id],
[appSrc]: ['sourcemap']
},
typescriptPreprocessor: {
typescript: require('typescript'),
options: tsconfig.compilerOptions
options: compilerOptions
},
reporters: ['progress'],
port: 9876,
Expand Down

0 comments on commit ebd79e8

Please sign in to comment.