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:
parent
aea8832243
commit
795e1e8a38
|
@ -74,8 +74,14 @@ export function expectEmit(
|
||||||
const m = source.match(regexp);
|
const m = source.match(regexp);
|
||||||
const expectedPiece = pieces[i - 1] == IDENTIFIER ? '<IDENT>' : pieces[i - 1];
|
const expectedPiece = pieces[i - 1] == IDENTIFIER ? '<IDENT>' : pieces[i - 1];
|
||||||
if (!m) {
|
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(
|
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;
|
return;
|
||||||
} else {
|
} else {
|
||||||
last = (m.index || 0) + m[0].length;
|
last = (m.index || 0) + m[0].length;
|
||||||
|
|
|
@ -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';
|
import {compile, expectEmit} from './mock_compile';
|
||||||
|
|
||||||
describe('mock_compiler', () => {
|
describe('mock_compiler', () => {
|
||||||
|
|
Loading…
Reference in New Issue