File tree 6 files changed +81
-1
lines changed
6 files changed +81
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import * as webpack from 'webpack';
4
4
5
5
import { CliConfig } from '../config' ;
6
6
import { WebpackTestOptions } from '../webpack-test-config' ;
7
+ import { KarmaWebpackEmitlessError } from '../../plugins/karma-webpack-emitless-error' ;
7
8
8
9
/**
9
10
* Enumerate loaders and their dependencies from this file to let the dependency validator
@@ -57,7 +58,8 @@ export function getTestConfig(testConfig: WebpackTestOptions) {
57
58
new webpack . SourceMapDevToolPlugin ( {
58
59
filename : null , // if no value is provided the sourcemap is inlined
59
60
test : / \. ( t s | j s ) ( $ | \? ) / i // process .js and .ts files only
60
- } )
61
+ } ) ,
62
+ new KarmaWebpackEmitlessError ( )
61
63
]
62
64
} ;
63
65
}
Original file line number Diff line number Diff line change
1
+ // Don't emit anything when there are compilation errors. This is useful for preventing Karma
2
+ // from re-running tests when there is a compilation error.
3
+ // Workaround for https://github.com/webpack-contrib/karma-webpack/issues/49
4
+
5
+ export class KarmaWebpackEmitlessError {
6
+ constructor ( ) { }
7
+
8
+ apply ( compiler : any ) : void {
9
+ compiler . plugin ( 'done' , ( stats : any ) => {
10
+ if ( stats . compilation . errors . length > 0 ) {
11
+ stats . stats = [ {
12
+ toJson : function ( ) {
13
+ return this ;
14
+ } ,
15
+ assets : [ ]
16
+ } ] ;
17
+ }
18
+ } ) ;
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ // Force Webpack to throw compilation errors. Useful with karma-webpack when in single-run mode.
2
+ // Workaround for https://github.com/webpack-contrib/karma-webpack/issues/66
3
+
4
+ export class KarmaWebpackThrowError {
5
+ constructor ( ) { }
6
+
7
+ apply ( compiler : any ) : void {
8
+ compiler . plugin ( 'done' , ( stats : any ) => {
9
+ if ( stats . compilation . errors . length > 0 ) {
10
+ throw new Error ( stats . compilation . errors . map ( ( err : any ) => err . message || err ) ) ;
11
+ }
12
+ } ) ;
13
+ }
14
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import * as glob from 'glob';
5
5
import { Pattern } from './glob-copy-webpack-plugin' ;
6
6
import { extraEntryParser } from '../models/webpack-configs/utils' ;
7
7
import { WebpackTestConfig , WebpackTestOptions } from '../models/webpack-test-config' ;
8
+ import { KarmaWebpackThrowError } from './karma-webpack-throw-error' ;
8
9
9
10
const getAppFromConfig = require ( '../utilities/app-utils' ) . getAppFromConfig ;
10
11
@@ -102,6 +103,11 @@ const init: any = (config: any) => {
102
103
}
103
104
} ;
104
105
106
+ // If Karma is being ran in single run mode, throw errors.
107
+ if ( config . singleRun ) {
108
+ webpackConfig . plugins . push ( new KarmaWebpackThrowError ( ) ) ;
109
+ }
110
+
105
111
config . webpack = Object . assign ( webpackConfig , config . webpack ) ;
106
112
config . webpackMiddleware = Object . assign ( webpackMiddlewareConfig , config . webpackMiddleware ) ;
107
113
Original file line number Diff line number Diff line change
1
+ import { ng } from '../../utils/process' ;
2
+ import { writeFile } from '../../utils/fs' ;
3
+ import { expectToFail } from '../../utils/utils' ;
4
+
5
+
6
+ export default function ( ) {
7
+ // Fails on single run with broken compilation.
8
+ return writeFile ( 'src/app.component.spec.ts' , '<p> definitely not typescript </p>' )
9
+ . then ( ( ) => expectToFail ( ( ) => ng ( 'test' , '--single-run' ) ) ) ;
10
+ }
Original file line number Diff line number Diff line change
1
+ import {
2
+ killAllProcesses ,
3
+ waitForAnyProcessOutputToMatch ,
4
+ silentExecAndWaitForOutputToMatch
5
+ } from '../../utils/process' ;
6
+ import { expectToFail } from '../../utils/utils' ;
7
+ import { readFile , writeFile } from '../../utils/fs' ;
8
+
9
+
10
+ const karmaGoodRegEx = / E x e c u t e d 3 o f 3 / ;
11
+
12
+ export default function ( ) {
13
+ let originalSpec : string ;
14
+ return silentExecAndWaitForOutputToMatch ( 'ng' , [ 'test' ] , karmaGoodRegEx )
15
+ . then ( ( ) => readFile ( 'src/app.component.spec.ts' ) )
16
+ . then ( ( data ) => originalSpec = data )
17
+ // Trigger a failed rebuild, which shouldn't run tests again.
18
+ . then ( ( ) => writeFile ( 'src/app.component.spec.ts' , '<p> definitely not typescript </p>' ) )
19
+ . then ( ( ) => expectToFail ( ( ) => waitForAnyProcessOutputToMatch ( karmaGoodRegEx , 10000 ) ) )
20
+ // Restore working spec.
21
+ . then ( ( ) => writeFile ( 'src/app.component.spec.ts' , originalSpec ) )
22
+ . then ( ( ) => waitForAnyProcessOutputToMatch ( karmaGoodRegEx , 10000 ) )
23
+ . then ( ( ) => killAllProcesses ( ) , ( err : any ) => {
24
+ killAllProcesses ( ) ;
25
+ throw err ;
26
+ } ) ;
27
+ }
28
+
You can’t perform that action at this time.
0 commit comments