Skip to content

Commit c93b464

Browse files
author
Mehdy Dara
committed
Merge pull request #741 from Swiip/webpack-test-config
Webpack conf enhancement
2 parents 53e48f7 + 499b87f commit c93b464

File tree

13 files changed

+693
-392
lines changed

13 files changed

+693
-392
lines changed

app/files.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"gulp/.eslintrc",
1414
"gulp/e2e-tests.js",
1515
"gulp/tsd.js",
16-
"gulp/unit-tests.js",
1716

1817
"src/favicon.ico",
1918
"src/assets/images/yeoman.png"
@@ -38,6 +37,7 @@
3837
"gulp/styles.js",
3938
"gulp/watch.js",
4039
"gulp/server.js",
40+
"gulp/unit-tests.js",
4141

4242
"src/app/index.module.js",
4343
"src/app/index.config.js",

app/src/preprocessors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module.exports = function(GulpAngularGenerator) {
7474
}
7575

7676
if(this.props.jsPreprocessor.key !== 'none') {
77-
rejectWithRegexp.call(this, /spec\.js/);
77+
rejectWithRegexp.call(this, /^(?!^e2e\/).*spec\.js/);
7878
}
7979
};
8080

app/templates/_package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"gulp-uglify": "~1.2.0",
2525
"gulp-useref": "~1.2.0",
2626
"gulp-util": "~3.0.5",
27+
<% if (props.jsPreprocessor.srcExtension !== 'es6' && props.jsPreprocessor.key !== 'typescript') { -%>
2728
"gulp-ng-annotate": "~1.0.0",
29+
<% } -%>
2830
"gulp-replace": "~0.5.3",
2931
"gulp-rename": "~1.2.2",
3032
"gulp-rev": "~5.0.0",
@@ -46,6 +48,7 @@
4648
"gulp-coffeelint": "~0.5.0",
4749
<% } if (props.jsPreprocessor.srcExtension === 'es6' || props.jsPreprocessor.key === 'typescript') { -%>
4850
"webpack-stream": "~2.0.0",
51+
"ng-annotate-loader": "0.0.6",
4952
<% } if (props.jsPreprocessor.srcExtension === 'es6') { -%>
5053
"eslint-loader": "~1.0.0",
5154
<% } if (props.jsPreprocessor.key === 'babel') { -%>

app/templates/gulp/_build.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ gulp.task('html', ['inject', 'partials'], function () {
4848
.pipe($.rev())
4949
.pipe(jsFilter)
5050
.pipe($.sourcemaps.init())
51+
<% if (props.jsPreprocessor.srcExtension !== 'es6' && props.jsPreprocessor.key !== 'typescript') { -%>
5152
.pipe($.ngAnnotate())
53+
<% } -%>
5254
.pipe($.uglify({ preserveComments: $.uglifySaveLicense })).on('error', conf.errorHandler('Uglify'))
5355
.pipe($.sourcemaps.write('maps'))
5456
.pipe(jsFilter.restore)

app/templates/gulp/_scripts.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ gulp.task('scripts', function () {
3131
.pipe($.size())
3232
});
3333
<% } else { -%>
34-
function webpackWrapper(watch, callback) {
34+
function webpackWrapper(watch, test, callback) {
3535
var webpackOptions = {
3636
<% if (props.jsPreprocessor.key === 'typescript') { -%>
3737
resolve: { extensions: ['', '.ts'] },
@@ -44,11 +44,11 @@ function webpackWrapper(watch, callback) {
4444
preLoaders: [{ test: /\.ts$/, exclude: /node_modules/, loader: 'tslint-loader'}],
4545
<% } -%>
4646
<% if (props.jsPreprocessor.key === 'babel') { -%>
47-
loaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}]
47+
loaders: [{ test: /\.js$/, exclude: /node_modules/, loaders: ['ng-annotate', 'babel-loader']}]
4848
<% } if (props.jsPreprocessor.key === 'traceur') { -%>
49-
loaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'traceur-loader'}]
49+
loaders: [{ test: /\.js$/, exclude: /node_modules/, loaders: ['ng-annotate', 'traceur-loader']}]
5050
<% } if (props.jsPreprocessor.key === 'typescript') { -%>
51-
loaders: [{ test: /\.ts$/, exclude: /node_modules/, loader: 'awesome-typescript-loader'}]
51+
loaders: [{ test: /\.ts$/, exclude: /node_modules/, loaders: ['ng-annotate', 'awesome-typescript-loader']}]
5252
<% } -%>
5353
},
5454
output: { filename: 'index.module.js' }
@@ -75,20 +75,33 @@ function webpackWrapper(watch, callback) {
7575
}
7676
};
7777

78-
return gulp.src(path.join(conf.paths.src, '/app/index.module.<%- props.jsPreprocessor.extension %>'))
78+
var sources = [ path.join(conf.paths.src, '/app/index.module.<%- props.jsPreprocessor.extension %>') ];
79+
if (test) {
80+
sources.push(path.join(conf.paths.src, '/app/**/*.spec.<%- props.jsPreprocessor.extension %>'));
81+
}
82+
83+
return gulp.src(sources)
7984
.pipe(webpack(webpackOptions, null, webpackChangeHandler))
8085
.pipe(gulp.dest(path.join(conf.paths.tmp, '/serve/app')));
8186
}
8287

8388
<% if (props.jsPreprocessor.key === 'typescript') { -%>
8489
gulp.task('scripts', ['tsd:install'], function () {
85-
<% } else { %>
90+
<% } else { -%>
8691
gulp.task('scripts', function () {
87-
<% } %>
88-
return webpackWrapper(false);
92+
<% } -%>
93+
return webpackWrapper(false, false);
8994
});
9095

9196
gulp.task('scripts:watch', ['scripts'], function (callback) {
92-
return webpackWrapper(true, callback);
97+
return webpackWrapper(true, false, callback);
98+
});
99+
100+
gulp.task('scripts:test', function () {
101+
return webpackWrapper(false, true);
102+
});
103+
104+
gulp.task('scripts:test-watch', ['scripts'], function (callback) {
105+
return webpackWrapper(true, true, callback);
93106
});
94107
<% } -%>

app/templates/gulp/unit-tests.js renamed to app/templates/gulp/_unit-tests.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@ function runTests (singleRun, done) {
1616
});
1717
}
1818

19+
<% if (props.jsPreprocessor.srcExtension !== 'es6' && props.jsPreprocessor.key !== 'typescript') { -%>
1920
gulp.task('test', ['scripts'], function(done) {
2021
runTests(true, done);
2122
});
2223

2324
gulp.task('test:auto', ['watch'], function(done) {
2425
runTests(false, done);
2526
});
27+
<% } else { -%>
28+
gulp.task('test', ['scripts:test'], function(done) {
29+
runTests(true, done);
30+
});
31+
32+
gulp.task('test:auto', ['scripts:test-watch'], function(done) {
33+
runTests(false, done);
34+
});
35+
<% } -%>

app/templates/src/_index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<!doctype html>
2+
<% if (props.jsPreprocessor.srcExtension !== 'es6' && props.jsPreprocessor.key !== 'typescript') { -%>
23
<html<% if (includeModernizr) { %> class="no-js"<% } %> ng-app="<%- appName %>">
4+
<% } else { -%>
5+
<html<% if (includeModernizr) { %> class="no-js"<% } %> ng-app="<%- appName %>" ng-strict-di>
6+
<% } -%>
37
<head>
48
<meta charset="utf-8">
59
<title><%- appName %></title>

app/templates/src/app/_index.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export /** @ngInject */ function config($logProvider: ng.ILogProvider, toastrConfig) {
1+
/** @ngInject */
2+
export function config($logProvider: ng.ILogProvider, toastrConfig) {
23
// enable log
34
$logProvider.debugEnabled(true);
45
// set options third-party lib

app/templates/src/app/main/_main.controller.spec.es6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
describe('controllers', function(){
88

9-
beforeEach(module('<%- appName %>'));
9+
beforeEach(angular.mock.module('<%- appName %>'));
1010

1111
it('should define more than 5 awesome things', inject(function($controller) {
1212
var vm = $controller('MainController');

app/templates/src/app/main/_main.controller.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
describe('controllers', function(){
88

9-
beforeEach(module('<%- appName %>'));
9+
beforeEach(angular.mock.module('<%- appName %>'));
1010

1111
it('should define more than 5 awesome things', inject(function($controller) {
1212
var vm = $controller('MainController');

0 commit comments

Comments
 (0)