Skip to content

Commit b3e8c59

Browse files
committed
Tests more shelled out, still not running correctly but I'm much closer
1 parent 1424c38 commit b3e8c59

8 files changed

+352
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Error.stackTraceLimit = Infinity;
2+
3+
import 'core-js/es6';
4+
import 'core-js/es7/reflect';
5+
import 'ts-helpers';
6+
import 'zone.js/dist/zone';
7+
import 'zone.js/dist/long-stack-trace-zone';
8+
import 'zone.js/dist/jasmine-patch';
9+
import 'zone.js/dist/async-test';
10+
import 'zone.js/dist/fake-async-test';
11+
import 'zone.js/dist/sync-test';
12+
import 'rxjs/Rx';
13+
14+
import {testing} from '@angular/core/testing';
15+
import {browser} from '@angular/platform-browser-dynamic/testing';
16+
17+
testing.setBaseTestProviders(
18+
browser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
19+
browser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
20+
);
21+
22+
Object.assign(global, testing);
23+
24+
/*
25+
* Ok, this is kinda crazy. We can use the the context method on
26+
* require that webpack created in order to tell webpack
27+
* what files we actually want to require or import.
28+
* Below, context will be an function/object with file names as keys.
29+
* using that regex we are saying look in ./src/app and ./test then find
30+
* any file that ends with spec.js and get its path. By passing in true
31+
* we say do this recursively
32+
*/
33+
var testContext = require.context('../src', true, /\.spec\.ts/);
34+
35+
/*
36+
* get all the files, for each file, call the context function
37+
* that will require the file and load it up here. Context will
38+
* loop and require those spec files here
39+
*/
40+
function requireAll(requireContext) {
41+
return requireContext.keys().map(requireContext);
42+
}
43+
44+
// requires and returns all modules that match
45+
var modules = requireAll(testContext);

addon/ng2/models/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export * from './webpack-build-common';
2+
export * from './webpack-build-test';
3+
export * from './webpack-build-production';
4+
export * from './webpack-build-development';
5+
export * from './webpack-build-utils';
6+
7+
export * from './webpack-karma-config';
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import * as webpack from 'webpack';
2+
import {ngAppResolve} from './webpack-build-utils';
3+
4+
const path = require('path');
5+
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;
6+
const CopyWebpackPlugin = require('copy-webpack-plugin');
7+
const HtmlWebpackPlugin = require('html-webpack-plugin');
8+
9+
export const webpackCommonConfig = {
10+
resolve: {
11+
extensions: ['', '.ts', '.js'],
12+
root: ngAppResolve('./src')
13+
},
14+
context: path.resolve(__dirname, './'),
15+
entry: {
16+
main: [ngAppResolve('./src/main.ts')],
17+
vendor: ngAppResolve('./src/vendor.ts'),
18+
polyfills: ngAppResolve('./src/polyfills.ts')
19+
},
20+
output: {
21+
path: ngAppResolve('./dist'),
22+
filename: '[name].bundle.js'
23+
},
24+
module: {
25+
preLoaders: [
26+
{
27+
test: /\.js$/,
28+
loader: 'source-map-loader',
29+
exclude: [
30+
ngAppResolve('node_modules/rxjs'),
31+
ngAppResolve('node_modules/@angular'),
32+
]
33+
}
34+
],
35+
loaders: [
36+
{
37+
test: /\.ts$/,
38+
loaders: [
39+
{
40+
loader: 'awesome-typescript-loader',
41+
query: {
42+
useWebpackText: true,
43+
tsconfig: ngAppResolve('./src/tsconfig.json'),
44+
resolveGlobs: false,
45+
module: "es2015",
46+
target: "es5",
47+
library: 'es6',
48+
useForkChecker: true
49+
}
50+
},
51+
{
52+
loader: 'angular2-template-loader'
53+
}
54+
],
55+
exclude: [/\.(spec|e2e)\.ts$/]
56+
},
57+
{ test: /\.json$/, loader: 'json-loader'},
58+
{ test: /\.css$/, loaders: ['raw-loader', 'postcss-loader'] },
59+
{ test: /\.styl$/, loaders: ['raw-loader', 'postcss-loader', 'stylus-loader'] },
60+
{ test: /\.less$/, loaders: ['raw-loader', 'postcss-loader', 'less-loader'] },
61+
{ test: /\.scss$/, loaders: ['raw-loader', 'postcss-loader', 'sass-loader'] },
62+
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000'},
63+
{ test: /\.html$/, loader: 'raw-loader' }
64+
]
65+
},
66+
plugins: [
67+
new ForkCheckerPlugin(),
68+
new HtmlWebpackPlugin({
69+
template: ngAppResolve('src/index.html'),
70+
chunksSortMode: 'dependency'
71+
}),
72+
new webpack.optimize.CommonsChunkPlugin({
73+
name: ['polyfills', 'vendor'].reverse()
74+
}),
75+
new webpack.optimize.CommonsChunkPlugin({
76+
minChunks: Infinity,
77+
name: 'inline',
78+
filename: 'inline.js',
79+
sourceMapFilename: 'inline.map'
80+
}),
81+
new CopyWebpackPlugin([{from: ngAppResolve('./public'), to: ngAppResolve('./dist/public')}])
82+
],
83+
node: {
84+
global: 'window',
85+
crypto: 'empty',
86+
module: false,
87+
clearImmediate: false,
88+
setImmediate: false
89+
}
90+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { webpackCommonConfig } from './webpack-build-common';
2+
import { ngAppResolve } from './webpack-build-utils';
3+
4+
const webpackMerge = require('webpack-merge');
5+
6+
export const webpackDevConfig = webpackMerge(webpackCommonConfig, {
7+
debug: true,
8+
devtool: 'cheap-module-source-map',
9+
output: {
10+
path: ngAppResolve('./dist'),
11+
filename: '[name].bundle.js',
12+
sourceMapFilename: '[name].map',
13+
chunkFilename: '[id].chunk.js'
14+
},
15+
tslint: {
16+
emitErrors: false,
17+
failOnHint: false,
18+
resourcePath: ngAppResolve('./src')
19+
},
20+
node: {
21+
global: 'window',
22+
crypto: 'empty',
23+
process: true,
24+
module: false,
25+
clearImmediate: false,
26+
setImmediate: false
27+
}
28+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as webpack from 'webpack';
2+
import {ngAppResolve} from './webpack-build-utils';
3+
4+
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
6+
const WebpackMd5Hash = require('webpack-md5-hash');
7+
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin'); //TODO WP2 Typings
8+
9+
export const webpackProdConfig = webpackMerge(commonConfig, {
10+
debug: false,
11+
devtool: 'source-map',
12+
output: {
13+
path: ngAppResolve('dist'),
14+
filename: '[name].[chunkhash].bundle.js',
15+
sourceMapFilename: '[name].[chunkhash].bundle.map',
16+
chunkFilename: '[id].[chunkhash].chunk.js'
17+
18+
},
19+
plugins: [
20+
new WebpackMd5Hash(),
21+
new webpack.optimize.DedupePlugin(),
22+
// new webpack.optimize.UglifyJsPlugin({
23+
// beautify: false, //prod
24+
// mangle: { screw_ie8 : true }, //prod
25+
// compress: { screw_ie8: true }, //prod
26+
// comments: false //prod
27+
// }),
28+
new LoaderOptionsPlugin({
29+
test: /\.js/,
30+
minimize: true,
31+
debug: false
32+
})
33+
],
34+
tslint: {
35+
emitErrors: true,
36+
failOnHint: true,
37+
resourcePath: ngAppResolve('./src')
38+
},
39+
htmlLoader: {
40+
minimize: true,
41+
removeAttributeQuotes: false,
42+
caseSensitive: true,
43+
customAttrSurround: [
44+
[/#/, /(?:)/],
45+
[/\*/, /(?:)/],
46+
[/\[?\(?/, /(?:)/]
47+
],
48+
customAttrAssign: [/\)?\]?=/]
49+
},
50+
node: {
51+
global: 'window',
52+
crypto: 'empty',
53+
process: false,
54+
module: false,
55+
clearImmediate: false,
56+
setImmediate: false
57+
}
58+
});
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import * as webpack from 'webpack';
2+
import {ngAppResolve} from './webpack-build-utils';
3+
4+
export const webpackTestConfig = {
5+
context: ngAppResolve('./'),
6+
devtool: 'inline-source-map',
7+
resolve: {
8+
extensions: ['', '.ts', '.js'],
9+
root: ngAppResolve('./src'),
10+
},
11+
entry: {
12+
main: [ngAppResolve('./src/main.ts')],
13+
vendor: ngAppResolve('./src/vendor.ts'),
14+
polyfills: ngAppResolve('./src/polyfills.ts')
15+
},
16+
output: {
17+
path: ngAppResolve('./dist'),
18+
filename: '[name].bundle.js'
19+
},
20+
module: {
21+
preLoaders: [
22+
{
23+
test: /\.ts$/,
24+
loader: 'tslint-loader',
25+
exclude: [ngAppResolve('node_modules')]
26+
},
27+
{
28+
test: /\.js$/,
29+
loader: 'source-map-loader',
30+
exclude: [
31+
ngAppResolve('node_modules/rxjs'),
32+
ngAppResolve('node_modules/@angular')
33+
]}
34+
],
35+
loaders: [
36+
{
37+
test: /\.ts$/,
38+
loader: 'awesome-typescript-loader',
39+
query: {
40+
compilerOptions: {
41+
removeComments: true
42+
}
43+
},
44+
exclude: [/\.e2e\.ts$/]
45+
},
46+
{ test: /\.json$/, loader: 'json-loader', exclude: [ngAppResolve('src/index.html')] },
47+
{ test: /\.css$/, loader: 'raw-loader', exclude: [ngAppResolve('src/index.html')] },
48+
{ test: /\.html$/, loader: 'raw-loader', exclude: [ngAppResolve('src/index.html')] }
49+
],
50+
postLoaders: [
51+
{
52+
test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader',
53+
include: ngAppResolve('src'),
54+
exclude: [
55+
/\.(e2e|spec)\.ts$/,
56+
/node_modules/
57+
]
58+
}
59+
]
60+
},
61+
tslint: {
62+
emitErrors: false,
63+
failOnHint: false,
64+
resourcePath: 'src'
65+
},
66+
node: {
67+
global: 'window',
68+
process: false,
69+
crypto: 'empty',
70+
module: false,
71+
clearImmediate: false,
72+
setImmediate: false
73+
}
74+
};
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const path = require('path');
2+
const autoprefixer = require('autoprefixer');
3+
4+
export function ngAppResolve(resolvePath: string): string {
5+
return path.resolve(process.cwd(), resolvePath);
6+
}
7+
8+
export const webpackOutputOptions: WebpackProgressPluginOutputOptions = {
9+
colors: true,
10+
chunks: true,
11+
modules: false,
12+
reasons: false,
13+
chunkModules: false
14+
}
15+
16+
export const postCssConfiguration = () => {
17+
return {
18+
defaults: [autoprefixer]
19+
};
20+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export default function(config) {
2+
var testWebpackConfig = require('./webpack.test.js');
3+
config.set({
4+
basePath: '',
5+
frameworks: ['jasmine'],
6+
exclude: [ ],
7+
files: [ { pattern: './config/spec-bundle.js', watched: false } ],
8+
coverageReporter: {
9+
dir : 'coverage/',
10+
reporters: [
11+
{ type: 'text-summary' },
12+
{ type: 'json' },
13+
{ type: 'html' }
14+
]
15+
},
16+
preprocessors: { './config/spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] },
17+
webpack: testWebpackConfig,
18+
webpackServer: { noInfo: true },
19+
reporters: [ 'mocha', 'coverage' ],
20+
port: 9876,
21+
colors: true,
22+
logLevel: config.LOG_INFO,
23+
autoWatch: false,
24+
browsers: [
25+
// 'Chrome',
26+
'PhantomJS'
27+
],
28+
singleRun: true
29+
});
30+
};

0 commit comments

Comments
 (0)