Skip to content

Commit f999056

Browse files
committed
chore(test) get tests working again, e2e still WIP, but added non-exposed support for webpack-karma as well as a variety of better looking reporters with mocha and coverage through istanbul. Sourcemaps still WIP for debugging tests.
1 parent b3e8c59 commit f999056

19 files changed

+197
-110
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*global jasmine, __karma__, window*/
2+
require('core-js/es6');
3+
require('core-js/es7/reflect');
4+
5+
// Typescript emit helpers polyfill
6+
require('ts-helpers');
7+
8+
require('zone.js/dist/zone');
9+
require('zone.js/dist/long-stack-trace-zone');
10+
require('zone.js/dist/jasmine-patch');
11+
require('zone.js/dist/async-test');
12+
require('zone.js/dist/fake-async-test');
13+
require('zone.js/dist/sync-test');
14+
15+
// RxJS
16+
require('rxjs/Rx');
17+
18+
var testing = require('@angular/core/testing');
19+
var browser = require('@angular/platform-browser-dynamic/testing');
20+
21+
testing.setBaseTestProviders(
22+
browser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
23+
browser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
24+
);
25+
26+
var testContext = require.context('../src', true, /\.spec\.ts/);
27+
28+
/*
29+
* get all the files, for each file, call the context function
30+
* that will require the file and load it up here. Context will
31+
* loop and require those spec files here
32+
*/
33+
function requireAll(requireContext) {
34+
return requireContext.keys().map(requireContext);
35+
}
36+
37+
requireAll(testContext);

addon/ng2/blueprints/ng2/files/config/karma.conf.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,7 @@ module.exports = function (config) {
1313
flags: ['--no-sandbox']
1414
}
1515
},
16-
files: [
17-
// { pattern: 'dist/vendor/es6-shim/es6-shim.js', included: true, watched: false },
18-
// { pattern: 'dist/vendor/zone.js/dist/zone.js', included: true, watched: false },
19-
// { pattern: 'dist/vendor/reflect-metadata/Reflect.js', included: true, watched: false },
20-
// { pattern: 'dist/vendor/systemjs/dist/system-polyfills.js', included: true, watched: false },
21-
// { pattern: 'dist/vendor/systemjs/dist/system.src.js', included: true, watched: false },
22-
// { pattern: 'dist/vendor/zone.js/dist/async-test.js', included: true, watched: false },
23-
// { pattern: 'config/karma-test-shim.js', included: true, watched: true },
24-
25-
// Distribution folder.
26-
// { pattern: 'dist/**/*', included: false, watched: true }
27-
],
16+
files: [],
2817
exclude: [
2918
// Vendor packages might include spec files. We don't want to use those.
3019
'dist/vendor/**/*.spec.js'

addon/ng2/blueprints/ng2/files/config/spec-bundle.js

-45
This file was deleted.

addon/ng2/commands/build.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ module.exports = Command.extend({
3232
],
3333

3434
run: function(commandOptions: BuildOptions) {
35-
let buildTask = commandOptions.watch ? new WebpackBuildWatch({options: commandOptions}) : new WebpackBuild({options: commandOptions});
35+
36+
let buildTask = commandOptions.watch ?
37+
new WebpackBuildWatch() :
38+
new WebpackBuild();
39+
40+
console.log(buildTask);
3641

3742
return buildTask.run(commandOptions);
3843
}

addon/ng2/commands/serve.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PortFinder.basePort = 49152;
1111
const getPort = Promise.denodeify(PortFinder.getPort);
1212
const defaultPort = process.env.PORT || 4200;
1313

14-
export interface IServeTaskOptions {
14+
export interface ServeTaskOptions {
1515
port?: number;
1616
host?: string;
1717
proxy?: string;
@@ -52,12 +52,12 @@ module.exports = Command.extend({
5252
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' }
5353
],
5454

55-
run: function(commandOptions: IServeTaskOptions) {
55+
run: function(commandOptions: ServeTaskOptions) {
5656
commandOptions.liveReloadHost = commandOptions.liveReloadHost || commandOptions.host;
5757

5858
return this._checkExpressPort(commandOptions)
5959
.then(this._autoFindLiveReloadPort.bind(this))
60-
.then(function(commandOptions: IServeTaskOptions) {
60+
.then(function(commandOptions: ServeTaskOptions) {
6161
commandOptions = assign({}, commandOptions, {
6262
baseURL: this.project.config(commandOptions.environment).baseURL || '/'
6363
});
@@ -85,7 +85,7 @@ module.exports = Command.extend({
8585
}.bind(this));
8686
},
8787

88-
_checkExpressPort: function(commandOptions: IServeTaskOptions) {
88+
_checkExpressPort: function(commandOptions: ServeTaskOptions) {
8989
return getPort({ port: commandOptions.port, host: commandOptions.host })
9090
.then(function(foundPort: number) {
9191

@@ -101,7 +101,7 @@ module.exports = Command.extend({
101101
}.bind(this));
102102
},
103103

104-
_autoFindLiveReloadPort: function(commandOptions: IServeTaskOptions) {
104+
_autoFindLiveReloadPort: function(commandOptions: ServeTaskOptions) {
105105
return getPort({ port: commandOptions.liveReloadPort, host: commandOptions.liveReloadHost })
106106
.then(function(foundPort: number) {
107107

addon/ng2/commands/test.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ module.exports = TestCommand.extend({
4141
analytics: this.analytics,
4242
project: this.project
4343
});
44-
var buildOptions = {
45-
environment: 'development',
46-
outputPath: 'dist/'
47-
};
44+
45+
// var buildOptions = {
46+
// environment: 'development',
47+
// outputPath: 'dist/'
48+
// };
4849

4950
// If not building, mock/suppress build tasks.
5051
// if (!commandOptions.build) {

addon/ng2/models/dist/dll/dll.polyfills.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

addon/ng2/models/dist/dll/dll.vendor.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

addon/ng2/models/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ export * from './webpack-build-test';
33
export * from './webpack-build-production';
44
export * from './webpack-build-development';
55
export * from './webpack-build-utils';
6+
export * from './webpack-build-vendors';
67

78
export * from './webpack-karma-config';

addon/ng2/models/webpack-build-common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
77
const HtmlWebpackPlugin = require('html-webpack-plugin');
88

99
export const webpackCommonConfig = {
10+
devtool: 'inline-source-map',
1011
resolve: {
1112
extensions: ['', '.ts', '.js'],
1213
root: ngAppResolve('./src')

addon/ng2/models/webpack-build-production.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import * as webpack from 'webpack';
2-
import {ngAppResolve} from './webpack-build-utils';
2+
import {webpackCommonConfig} from '../models/';
3+
import {ngAppResolve} from '../models/webpack-build-utils';
4+
35

46
const webpackMerge = require('webpack-merge'); // used to merge webpack configs
5-
const commonConfig = require('./webpack-build-common'); // the settings that are common to prod and dev
67
const WebpackMd5Hash = require('webpack-md5-hash');
78
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin'); //TODO WP2 Typings
9+
const CompressionPlugin = require("compression-webpack-plugin");
810

9-
export const webpackProdConfig = webpackMerge(commonConfig, {
11+
export const webpackProdConfig = webpackMerge(webpackCommonConfig, {
1012
debug: false,
1113
devtool: 'source-map',
1214
output: {
13-
path: ngAppResolve('dist'),
15+
path: ngAppResolve('./dist'),
1416
filename: '[name].[chunkhash].bundle.js',
1517
sourceMapFilename: '[name].[chunkhash].bundle.map',
1618
chunkFilename: '[id].[chunkhash].chunk.js'
17-
1819
},
1920
plugins: [
2021
new WebpackMd5Hash(),
@@ -25,9 +26,17 @@ export const webpackProdConfig = webpackMerge(commonConfig, {
2526
// compress: { screw_ie8: true }, //prod
2627
// comments: false //prod
2728
// }),
29+
// new CompressionPlugin({
30+
// asset: "[path].gz[query]",
31+
// algorithm: "gzip",
32+
// test: /\.js$|\.html$/,
33+
// threshold: 10240,
34+
// minRatio: 0.8
35+
// }),
2836
new LoaderOptionsPlugin({
2937
test: /\.js/,
3038
minimize: true,
39+
optimize: true,
3140
debug: false
3241
})
3342
],

addon/ng2/models/webpack-build-test.ts

+27-16
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,58 @@
11
import * as webpack from 'webpack';
22
import {ngAppResolve} from './webpack-build-utils';
33

4+
const path = require('path');
5+
46
export const webpackTestConfig = {
5-
context: ngAppResolve('./'),
67
devtool: 'inline-source-map',
8+
context: path.resolve(__dirname, './'),
79
resolve: {
810
extensions: ['', '.ts', '.js'],
9-
root: ngAppResolve('./src'),
11+
root: ngAppResolve('./src')
1012
},
1113
entry: {
12-
main: [ngAppResolve('./src/main.ts')],
13-
vendor: ngAppResolve('./src/vendor.ts'),
14-
polyfills: ngAppResolve('./src/polyfills.ts')
14+
test: ngAppResolve('./src/test.ts')
1515
},
1616
output: {
17-
path: ngAppResolve('./dist'),
17+
path: './dist.test',
1818
filename: '[name].bundle.js'
1919
},
2020
module: {
2121
preLoaders: [
2222
{
2323
test: /\.ts$/,
2424
loader: 'tslint-loader',
25-
exclude: [ngAppResolve('node_modules')]
25+
exclude: [
26+
ngAppResolve('node_modules')
27+
]
2628
},
2729
{
2830
test: /\.js$/,
2931
loader: 'source-map-loader',
3032
exclude: [
31-
ngAppResolve('node_modules/rxjs'),
32-
ngAppResolve('node_modules/@angular')
33-
]}
33+
ngAppResolve('node_modules/rxjs'),
34+
ngAppResolve('node_modules/@angular')
35+
]
36+
}
3437
],
3538
loaders: [
3639
{
3740
test: /\.ts$/,
38-
loader: 'awesome-typescript-loader',
39-
query: {
40-
compilerOptions: {
41-
removeComments: true
41+
loaders: [
42+
{
43+
loader: 'awesome-typescript-loader',
44+
query: {
45+
tsconfig: ngAppResolve('./src/tsconfig.json'),
46+
resolveGlobs: false,
47+
module: "commonjs",
48+
target: "es5",
49+
library: "es6",
50+
lib: ['es5', 'dom'],
51+
useForkChecker: false,
52+
removeComments: true
53+
}
4254
}
43-
},
55+
],
4456
exclude: [/\.e2e\.ts$/]
4557
},
4658
{ test: /\.json$/, loader: 'json-loader', exclude: [ngAppResolve('src/index.html')] },
@@ -50,7 +62,6 @@ export const webpackTestConfig = {
5062
postLoaders: [
5163
{
5264
test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader',
53-
include: ngAppResolve('src'),
5465
exclude: [
5566
/\.(e2e|spec)\.ts$/,
5667
/node_modules/

addon/ng2/models/webpack-build-utils.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const path = require('path');
22
const autoprefixer = require('autoprefixer');
33

4-
export function ngAppResolve(resolvePath: string): string {
4+
import {webpackDevConfig, webpackProdConfig, webpackVendorDLLConfig} from './';
5+
6+
export const ngAppResolve = (resolvePath: string): string => {
57
return path.resolve(process.cwd(), resolvePath);
68
}
79

@@ -18,3 +20,9 @@ export const postCssConfiguration = () => {
1820
defaults: [autoprefixer]
1921
};
2022
}
23+
24+
export const envToConfigMap: any = {
25+
production: webpackProdConfig,
26+
development: webpackDevConfig,
27+
vendor: webpackVendorDLLConfig
28+
}

0 commit comments

Comments
 (0)