Permalink
Browse files

acurate test coverage

  • Loading branch information...
1 parent cd9dc75 commit 30b59cde69a3525d9151fa8bfa6e75bb2d207554 @mseemann committed Apr 29, 2016
Showing with 169 additions and 90 deletions.
  1. +0 −7 README.md
  2. +46 −0 config/karma.conf.js
  3. +15 −0 config/spec-bundle.js
  4. +16 −0 config/utils.js
  5. +78 −0 config/webpack.test.js
  6. +1 −56 karma.conf.js
  7. +7 −2 package.json
  8. +1 −1 src/core/decorator-parser.spec.ts
  9. +0 −21 src/core/decorators.spec.ts
  10. +1 −0 src/vendor.ts
  11. +1 −0 tsconfig.json
  12. +2 −3 typings.json
  13. +1 −0 webpack.config.js
View
@@ -52,10 +52,3 @@ class BookService {
}
}
```
-
-**I Need Help!**
-The coverage bage shows not the right coverage.
-Because of the preprocessing used libs (for example
-the source for reflect-metadata) is included in
-the measurements. For sure this is wrong.
-If anybody knows how to fix it - your are welcome!
View
@@ -0,0 +1,46 @@
+
+module.exports = function(config) {
+ var testWebpackConfig = require('./webpack.test.js');
+
+ config.set({
+
+ basePath: '',
+
+ frameworks: ['jasmine'],
+
+ exclude: [ ],
+
+ files: [ { pattern: './config/spec-bundle.js', watched: false } ],
+
+ preprocessors: { './config/spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] },
+
+ webpack: testWebpackConfig,
+
+ coverageReporter: {
+ dir : 'coverage/',
+ reporters: [
+ { type: 'text-summary' },
+ { type: 'json' },
+ { type: 'html' },
+ { type: 'lcov' }
+ ]
+ },
+
+ webpackServer: { noInfo: true },
+
+ reporters: ['mocha', 'coverage', 'coveralls' ],
+
+ port: 9876,
+
+ colors: true,
+
+ logLevel: config.LOG_INFO,
+
+ autoWatch: false,
+
+ browsers: ['PhantomJS'],
+
+ singleRun: true
+ });
+
+};
View
@@ -0,0 +1,15 @@
+
+Error.stackTraceLimit = Infinity;
+
+require('ts-helpers');
+
+
+var testContext = require.context('../src', true, /\.spec\.ts/);
+
+
+function requireAll(requireContext) {
+ return requireContext.keys().map(requireContext);
+}
+
+
+var modules = requireAll(testContext);
View
@@ -0,0 +1,16 @@
+
+var path = require('path');
+
+var _root = path.resolve(__dirname, '..');
+
+function absPath(args) {
+ args = Array.prototype.slice.call(arguments, 0);
+ var p = path.join.apply(path, [_root].concat(args));
+ return p;
+}
+
+
+exports.absPath = absPath;
+
+
+
@@ -0,0 +1,78 @@
+const utils = require('./utils');
+
+
+const ProvidePlugin = require('webpack/lib/ProvidePlugin');
+const DefinePlugin = require('webpack/lib/DefinePlugin');
+
+
+const ENV = process.env.ENV = process.env.NODE_ENV = 'test';
+
+
+module.exports = {
+
+ devtool: 'inline-source-map',
+
+ resolve: {
+ extensions: ['', '.ts', '.js'],
+ absPath: utils.absPath('src'),
+ },
+
+ module: {
+
+ preLoaders: [
+ {
+ test: /\.ts$/,
+ loader: 'tslint-loader',
+ exclude: [utils.absPath('node_modules')]
+ },
+ {
+ test: /\.js$/,
+ loader: 'source-map-loader',
+ }
+ ],
+
+ loaders: [
+ {
+ test: /\.ts$/,
+ loader: 'ts-loader',
+ query: {
+ compilerOptions: {
+ // Remove TypeScript helpers to be injected
+ // below by DefinePlugin
+ removeComments: true
+ }
+ },
+ exclude: [/\.e2e\.ts$/]
+ }
+ ],
+
+
+ postLoaders: [
+ {
+ test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader',
+ include: utils.absPath('src'),
+ exclude: [
+ /\.(spec)\.ts$/,
+ /node_modules/
+ ]
+ }
+ ]
+ },
+
+ tslint: {
+ emitErrors: false,
+ failOnHint: false,
+ resourcePath: 'src'
+ },
+
+
+ node: {
+ global: 'window',
+ process: false,
+ crypto: 'empty',
+ module: false,
+ clearImmediate: false,
+ setImmediate: false
+ }
+
+};
View
@@ -1,56 +1 @@
-var path = require('path');
-
-module.exports = function (config) {
- var _config = {
- basePath: '',
- frameworks: ['jasmine'],
-
- files: [
- { pattern: 'src/**/*.spec.ts', watched: false }
- ],
-
- preprocessors: {
- 'src/**/*.ts': ['webpack', 'sourcemap', 'coverage']
- },
-
- webpack: {
- resolve: {
- root: __dirname,
- modulesDirectories: ['node_modules', 'src'],
- extensions: ['', '.ts', '.js', '.json'],
- },
- devtool: 'inline-source-map',
- module: {
- loaders: [
- {
- test: /\.ts$/,
- loader: 'ts',
- exclude: [/node_modules/],
- }
- ]
- },
- stats: { colors: true, reasons: true },
- debug: true
- },
-
- webpackServer: {
- noInfo: true
- },
-
- reporters: ['progress', 'coverage', 'coveralls'],
-
- coverageReporter: {
- type: 'lcov', // lcov or lcovonly are required for generating lcov.info files
- dir: 'coverage/'
- },
-
- port: 9875,
- colors: true,
- logLevel: config.LOG_INFO,
- autoWatch: false,
- browsers: ['PhantomJS'],
- singleRun: true
- };
-
- config.set(_config);
-};
+module.exports = require('./config/karma.conf.js');
View
@@ -6,7 +6,7 @@
"typings": "./src/js-restful.d.ts",
"scripts": {
"install_typings": "typings install",
- "test": "tslint *.ts && typings install && tsc && karma start",
+ "test": "typings install && tsc && node --max-old-space-size=4096 node_modules/karma/bin/karma start",
"prepublish": "typings install && tsc",
"docs": "jsdoc -c jsdoc-conf.json -r src"
},
@@ -33,18 +33,23 @@
},
"devDependencies": {
"coveralls": "^2.11.9",
+ "istanbul-instrumenter-loader": "^0.2.0",
"jasmine-core": "2.4.1",
"jsdoc": "^3.4.0",
"karma": "^0.13.22",
"karma-coverage": "^0.5.5",
"karma-coveralls": "^1.1.2",
"karma-jasmine": "0.3.8",
+ "karma-mocha-reporter": "^2.0.2",
"karma-phantomjs-launcher": "^1.0.0",
"karma-sourcemap-loader": "0.3.7",
"karma-webpack": "1.7.0",
"phantomjs-prebuilt": "^2.1.7",
- "ts-loader": "0.8.2",
+ "source-map-loader": "^0.1.5",
+ "ts-helpers": "^1.1.1",
+ "ts-loader": "^0.8.2",
"tslint": "3.8.1",
+ "tslint-loader": "^2.1.4",
"typescript": "1.8.10",
"typings": "0.8.1",
"webpack": "1.13.0"
@@ -20,7 +20,7 @@ describe('rest-descriptor-parser', () => {
it('should have a base path', () => {
// TODO this will not work! what the hell is the reason why the meta data are lost if i use the class with metadata in different spec files!
- // expect(descriptor.basePath).toBe('/books');
+ expect(descriptor.basePath).toBe('/books');
})
});
@@ -1,12 +1,10 @@
import { ParamDescription } from './decorators';
import * as namings from './namings';
import { BookService } from './test-classes';
-import { DecoratorParser } from './decorator-parser';
describe('rest-decorator', () => {
const bookService = new BookService();
- const descriptor = DecoratorParser.parse(bookService)
describe('http method decorator', () => {
@@ -30,13 +28,6 @@ describe('rest-decorator', () => {
describe('path decorator', () => {
it('should have a Path decorator at the class', () => {
-
- // console.log('y----y');
- // console.log(bookService);
- // console.log(Reflect.getMetadataKeys(bookService.constructor));
- // console.log(Reflect.getMetadataKeys(bookService.allBooks));
- // console.log('y----Xy');
-
expect(Reflect.getMetadata(namings.buildFullName((namings.path)), bookService.constructor)).toBe('/books');
})
@@ -78,16 +69,4 @@ describe('rest-decorator', () => {
})
})
-
- describe('RestDescriptor', () => {
-
- it('should create a RestDescriptor from the service', () => {
- expect(descriptor).not.toBeNull();
- })
-
- it('should have a base path', () => {
- expect(descriptor.basePath).toBe('/books');
- })
- })
-
});
View
@@ -0,0 +1 @@
+import 'reflect-metadata';
View
@@ -12,6 +12,7 @@
},
"files":[
"typings/main.d.ts",
+ "src/vendor.ts",
"src/js-restful.ts",
"src/core/namings.ts",
"src/core/namings.spec.ts",
View
@@ -1,10 +1,9 @@
{
"version": false,
"ambientDependencies": {
+ "reflect-metadata": "github:rbuckton/ReflectDecorators/reflect-metadata.d.ts#1affc8fcd1301caac47602e3738b057ecfd88830"
},
"ambientDevDependencies": {
- "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#dd638012d63e069f2c99d06ef4dcc9616a943ee4",
- "reflect-metadata": "github:rbuckton/ReflectDecorators/reflect-metadata.d.ts#1affc8fcd1301caac47602e3738b057ecfd88830"
-
+ "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#dd638012d63e069f2c99d06ef4dcc9616a943ee4"
}
}
View
@@ -0,0 +1 @@
+module.exports = require('./config/webpack.dev');

0 comments on commit 30b59cd

Please sign in to comment.