test(ivy): improve error message for the compiler compliance test (#25291)

before:

```
Expected to find features 'import * as i0 from "@angular/core";
import { Directive, Input } from '@angular/core';

```

after:

```
Failed to find "template" after "...Component_Factory() { return new
MyComponent(); }," in:
'import * as i0 from "@angular/core";
import { Directive, Input } from '@angular/core';```

```

PR Close #25291
This commit is contained in:
Victor Berchet 2018-08-03 15:32:08 -07:00 committed by Kara Erickson
parent aea8832243
commit 795e1e8a38
2 changed files with 8 additions and 2 deletions

View File

@ -74,8 +74,14 @@ export function expectEmit(
const m = source.match(regexp);
const expectedPiece = pieces[i - 1] == IDENTIFIER ? '<IDENT>' : pieces[i - 1];
if (!m) {
// display at most `contextLength` characters of the line preceding the error location
const contextLength = 50;
const fullContext = source.substring(source.lastIndexOf('\n', last) + 1, last);
const context = fullContext.length > contextLength ?
`...${fullContext.substr(-contextLength)}` :
fullContext;
fail(
`${description}: Expected to find ${expectedPiece} '${source.substr(0,last)}[<---HERE expected "${expectedPiece}"]${source.substr(last)}'`);
`${description}: Failed to find "${expectedPiece}" after "${context}" in:\n'${source.substr(0,last)}[<---HERE expected "${expectedPiece}"]${source.substr(last)}'`);
return;
} else {
last = (m.index || 0) + m[0].length;

View File

@ -7,7 +7,7 @@
*/
import {MockDirectory, setup} from '@angular/compiler/test/aot/test_util';
import {setup} from '@angular/compiler/test/aot/test_util';
import {compile, expectEmit} from './mock_compile';
describe('mock_compiler', () => {