Skip to content

Commit 0c2084c

Browse files
committed
use old istanbul-loader
1 parent 84d34a2 commit 0c2084c

File tree

7 files changed

+575
-74
lines changed

7 files changed

+575
-74
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ Thumbs.db
2222

2323
# generated documents
2424
/doc
25+
26+
coverage

config/karma.conf.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@ module.exports = function (config) {
55
frameworks: ['jasmine'],
66
exclude: [],
77
files: [
8-
{pattern: './config/spec-bundle.ts', watched: false},
8+
{pattern: './config/spec-bundle.js', watched: false},
99
],
1010
preprocessors: {
11-
'./config/spec-bundle.ts': ['webpack', 'sourcemap'],
11+
'./config/spec-bundle.js': ['coverage', 'webpack', 'sourcemap'],
1212
},
1313
webpack: testWebpackConfig,
14-
webpackMiddleware: { stats: 'errors-only'},
15-
reporters: ['mocha'],
14+
coverageReporter: {
15+
type: 'in-memory'
16+
},
17+
remapCoverageReporter: {
18+
'text-summary': null,
19+
json: './coverage/coverage.json',
20+
html: './coverage/html'
21+
},
22+
webpackMiddleware: {stats: 'errors-only'},
23+
reporters: ['mocha', 'coverage', 'remap-coverage'],
1624
port: 9876,
1725
colors: true,
1826
logLevel: config.LOG_INFO,
@@ -27,7 +35,7 @@ module.exports = function (config) {
2735
singleRun: true,
2836
};
2937

30-
if (process.env.TRAVIS){
38+
if (process.env.TRAVIS) {
3139
configuration.browsers = [
3240
'ChromeTravisCi'
3341
];

config/spec-bundle.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @author: @AngularClass
3+
*/
4+
5+
/*
6+
* When testing with webpack and ES6, we have to do some extra
7+
* things to get testing to work right. Because we are gonna write tests
8+
* in ES6 too, we have to compile those as well. That's handled in
9+
* karma.conf.js with the karma-webpack plugin. This is the entry
10+
* file for webpack test. Just like webpack will create a bundle.js
11+
* file for our client, when we run test, it will compile and bundle them
12+
* all here! Crazy huh. So we need to do some setup
13+
*/
14+
Error.stackTraceLimit = Infinity;
15+
16+
require('core-js/es6');
17+
require('core-js/es7/reflect');
18+
19+
// Typescript emit helpers polyfill
20+
require('ts-helpers');
21+
22+
require('zone.js/dist/zone');
23+
require('zone.js/dist/long-stack-trace-zone');
24+
require('zone.js/dist/proxy'); // since zone.js 0.6.15
25+
require('zone.js/dist/sync-test');
26+
require('zone.js/dist/jasmine-patch'); // put here since zone.js 0.6.14
27+
require('zone.js/dist/async-test');
28+
require('zone.js/dist/fake-async-test');
29+
30+
// RxJS
31+
require('rxjs/Rx');
32+
33+
var testing = require('@angular/core/testing');
34+
var browser = require('@angular/platform-browser-dynamic/testing');
35+
36+
testing.TestBed.initTestEnvironment(
37+
browser.BrowserDynamicTestingModule,
38+
browser.platformBrowserDynamicTesting()
39+
);
40+
41+
/*
42+
* Ok, this is kinda crazy. We can use the context method on
43+
* require that webpack created in order to tell webpack
44+
* what files we actually want to require or import.
45+
* Below, context will be a function/object with file names as keys.
46+
* Using that regex we are saying look in ../src then find
47+
* any file that ends with spec.ts and get its path. By passing in true
48+
* we say do this recursively
49+
*/
50+
var testContext = require.context('../src', true, /\.spec\.ts/);
51+
52+
/*
53+
* get all the files, for each file, call the context function
54+
* that will require the file and load it up here. Context will
55+
* loop and require those spec files here
56+
*/
57+
function requireAll(requireContext) {
58+
return requireContext.keys().map(requireContext);
59+
}
60+
61+
// requires and returns all modules that match
62+
var modules = requireAll(testContext);

config/webpack.test.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require('path');
12
const helpers = require('./helpers');
23
const webpack = require('webpack');
34

@@ -9,6 +10,7 @@ module.exports = {
910
devtool: 'inline-source-map',
1011
resolve: {
1112
extensions: ['.ts', '.js'],
13+
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
1214
alias: {
1315
"lodash": "lodash-es",
1416
},
@@ -32,10 +34,31 @@ module.exports = {
3234
},
3335
{
3436
test: /\.ts$/,
35-
loaders: ['awesome-typescript-loader', 'angular2-template-loader']
37+
loader: 'awesome-typescript-loader',
38+
query: {
39+
sourceMap: false,
40+
inlineSourceMap: true,
41+
module: 'commonjs',
42+
},
43+
},
44+
{
45+
test: /\.ts$/,
46+
loader: 'angular2-template-loader',
3647
},
3748
{test: /\.css$/, loader: 'raw-loader'},
3849
{test: /\.html$/, loader: 'raw-loader'},
50+
{
51+
enforce: 'post',
52+
test: /\.(js|ts)$/,
53+
loader: 'istanbul-instrumenter-loader',
54+
include: [
55+
helpers.root('src'),
56+
],
57+
exclude: [
58+
/\.(e2e|spec)\.ts$/,
59+
/node_modules/
60+
]
61+
},
3962
]
4063
},
4164
plugins: [

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@
6565
"extract-text-webpack-plugin": "^2.0.0-beta.4",
6666
"html-webpack-plugin": "^2.24.1",
6767
"http-proxy": "^1.15.2",
68+
"istanbul-instrumenter-loader": "0.2.0",
6869
"jasmine-core": "^2.5.2",
6970
"karma": "^1.3.0",
7071
"karma-chrome-launcher": "^2.0.0",
72+
"karma-coverage": "^1.1.1",
7173
"karma-jasmine": "^1.0.2",
7274
"karma-mocha-reporter": "^2.0.2",
7375
"karma-notify-reporter": "^1.0.1",
76+
"karma-remap-coverage": "^0.1.2",
7477
"karma-sourcemap-loader": "^0.3.7",
7578
"karma-webpack": "^1.8.0",
7679
"raw-loader": "^0.5.1",

src/app/core/services/auth.service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import {Observable} from "rxjs/Observable";
22
import {Subject} from "rxjs/Subject";
33
import {Injectable} from "@angular/core";
44
import {Response} from "@angular/http";
5-
import jwtDecode from "jwt-decode";
65
import {JsonHttp} from "./";
76
import {User} from "../domains";
87

8+
const jwtDecode = require('jwt-decode');
9+
910
@Injectable()
1011
export class AuthService {
1112

0 commit comments

Comments
 (0)