-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular/cli): fix error handling on test
- Loading branch information
1 parent
303b2c0
commit 9cda847
Showing
6 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/@angular/cli/plugins/karma-webpack-emitless-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Don't emit anything when there are compilation errors. This is useful for preventing Karma | ||
// from re-running tests when there is a compilation error. | ||
// Workaround for https://github.com/webpack-contrib/karma-webpack/issues/49 | ||
|
||
export class KarmaWebpackEmitlessError { | ||
constructor() { } | ||
|
||
apply(compiler: any): void { | ||
compiler.plugin('done', (stats: any) => { | ||
if (stats.compilation.errors.length > 0) { | ||
stats.stats = [{ | ||
toJson: function () { | ||
return this; | ||
}, | ||
assets: [] | ||
}]; | ||
} | ||
}); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/@angular/cli/plugins/karma-webpack-throw-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Force Webpack to throw compilation errors. Useful with karma-webpack when in single-run mode. | ||
// Workaround for https://github.com/webpack-contrib/karma-webpack/issues/66 | ||
|
||
export class KarmaWebpackThrowError { | ||
constructor() { } | ||
|
||
apply(compiler: any): void { | ||
compiler.plugin('done', (stats: any) => { | ||
if (stats.compilation.errors.length > 0) { | ||
throw new Error(stats.compilation.errors.map((err: any) => err.message || err)); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ng } from '../../utils/process'; | ||
import { writeFile } from '../../utils/fs'; | ||
import { expectToFail } from '../../utils/utils'; | ||
|
||
|
||
export default function () { | ||
// Fails on single run with broken compilation. | ||
return writeFile('src/app.component.spec.ts', '<p> definitely not typescript </p>') | ||
.then(() => expectToFail(() => ng('test', '--single-run'))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
killAllProcesses, | ||
waitForAnyProcessOutputToMatch, | ||
silentExecAndWaitForOutputToMatch | ||
} from '../../utils/process'; | ||
import { expectToFail } from '../../utils/utils'; | ||
import { readFile, writeFile } from '../../utils/fs'; | ||
|
||
|
||
// Karma is only really finished with a run when it shows a non-zero total time in the first slot. | ||
const karmaGoodRegEx = /Executed 3 of 3 SUCCESS \(\d+\.\d+ secs/; | ||
|
||
export default function () { | ||
let originalSpec: string; | ||
return silentExecAndWaitForOutputToMatch('ng', ['test', '--no-progress'], karmaGoodRegEx) | ||
.then(() => readFile('src/app/app.component.spec.ts')) | ||
.then((data) => originalSpec = data) | ||
// Trigger a failed rebuild, which shouldn't run tests again. | ||
.then(() => writeFile('src/app/app.component.spec.ts', '<p> definitely not typescript </p>')) | ||
.then(() => expectToFail(() => waitForAnyProcessOutputToMatch(karmaGoodRegEx, 10000))) | ||
// Restore working spec. | ||
.then(() => writeFile('src/app/app.component.spec.ts', originalSpec)) | ||
.then(() => waitForAnyProcessOutputToMatch(karmaGoodRegEx, 10000)) | ||
.then(() => killAllProcesses(), (err: any) => { | ||
killAllProcesses(); | ||
throw err; | ||
}); | ||
} |