This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sourcemap support for coverage by using remap-istanbul
Added remap-istanbul and all supporting karma plugins to correctly remap the coverage results back to their TypeScript source. Since all generations happens in memory by Webpack, we needed inline sourcemap support, provided by the Karma plugins, the Webpack devtool setting, and the webpack typescript loader. The normal `ts-loader` doesn't support inline sourcemaps, so we switched to `awesome-typescript-loader`. We created a new `tsconfig.test.json` that is the same as the normal `tsconfig.json` but enables inline sourcemaps by adding `"inlineSourceMap": true`. The webpack dist builds have also switched to `awesome-typescript-loader` to keep the configuration consistent. To make the `awesome-typescript-loader` correctly work with const enums, we needed to enable `preserveConstEnums` property in the `tsconfig.json`. We also switched he `test/index.js` to `index.ts` and included `webpack-env` in the `typings.json` so all wepack requires work in TypeScript. To have correct coverage reports consisting of _all_ the source files, we've added a `Dummy.ts` file in the `src/` folder that is not referenced by any tests, but must show up in the coverage results. If this is not the case, we know our test setup is incorrect. re #15
- Loading branch information
Showing
10 changed files
with
192 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"target": "es5", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"preserveConstEnums": true, | ||
"noImplicitAny": false, | ||
"removeComments": false, | ||
"noEmitHelpers": true, | ||
"sourceMap": false, | ||
"inlineSourceMap": true | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
], | ||
"filesGlob": [ | ||
"../src/**/*.ts", | ||
"../typings/index.d.ts" | ||
], | ||
"awesomeTypescriptLoaderOptions": { | ||
"resolveGlobs": false, | ||
"forkChecker": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/*eslint-disable */ | ||
var webpack = require('webpack'); | ||
var path = require('path'); | ||
|
||
module.exports = function() | ||
{ | ||
return { | ||
/** | ||
* Inline source maps, generated by TypeScript compiler, will be used. | ||
*/ | ||
devtool: 'inline-source-map', | ||
|
||
resolve: { | ||
extensions: ['', '.ts', '.js'] | ||
}, | ||
// entry is the "main" source file we want to include/import | ||
entry: './test/index.ts', | ||
|
||
verbose: true, | ||
|
||
module: { | ||
loaders: [ | ||
/** | ||
* Unlike ts-loader, awesome-typescript-loader doesn't allow to override TS compiler options | ||
* in query params. We use separate `tsconfig.test.json` file, which only differs in one thing: | ||
* inline source maps. They are used for code coverage report. | ||
* | ||
* See project repository for details / configuration reference: | ||
* https://github.com/s-panferov/awesome-typescript-loader | ||
*/ | ||
{ | ||
test: /\.ts$/, | ||
exclude: /node_modules/, | ||
loader: 'awesome-typescript-loader', | ||
query: { | ||
tsconfig: 'config/tsconfig.test.json' | ||
} | ||
} | ||
], | ||
postLoaders: [ | ||
/** | ||
* Instruments TS source files for subsequent code coverage. | ||
* See https://github.com/deepsweet/istanbul-instrumenter-loader | ||
*/ | ||
{ | ||
test: /\.ts$/, | ||
loader: 'istanbul-instrumenter-loader', | ||
exclude: [ | ||
/node_modules/, | ||
/test/, | ||
/Spec\.ts$/ | ||
] | ||
} | ||
] | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Test file for code coverage checks | ||
* This file is not covered by any tests, but should show up in code coverage | ||
* results as a very low coverage percentage. | ||
* | ||
* @namespace example | ||
* @class Dummy | ||
* @constructor | ||
*/ | ||
export default class Dummy | ||
{ | ||
/** | ||
* Returns a value! | ||
* | ||
* @method foo | ||
* @param {string} str The input string | ||
* @returns {string} | ||
*/ | ||
public foo(str?:string):string | ||
{ | ||
if (typeof str == 'undefined') | ||
{ | ||
return 'baz'; | ||
} | ||
else | ||
{ | ||
return str + 'bar'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
// require all test files | ||
const testsContext = require.context('./', true, /Spec\.ts$/); | ||
const testsContext = require.context( | ||
'./', | ||
true, | ||
/Spec\.ts/ | ||
); | ||
|
||
testsContext.keys().forEach(testsContext); | ||
|
||
// require all source files | ||
const sourcesContext = require.context('../src/', true, /\.ts$/); | ||
const sourcesContext = require.context( | ||
'../src/', | ||
true, | ||
/\.ts$/ | ||
); | ||
|
||
sourcesContext.keys().forEach(sourcesContext); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters