Skip to content

Commit

Permalink
fix(karma): error messages truncated due to custom formatter
Browse files Browse the repository at this point in the history
Currently error messages printed out by Karma will be truncated
sometimes. This can happen for example if a jasmine test assertion
contains parenthesis characters. For example:

```ts
expect(element.style.transform).toBe('translate3d(...)')
```

If such an assertion fails, the error message from the browser
looks like that:

```
        Error: Expected 'translate3d(50px, 100px, 0px)' to be 'translate3d(500px, 100px, 0px)'.
            at <Jasmine>
            at UserContext.eval (../../src/cdk/drag-drop/directives/drag.spec.ts:79:44 <- bin/src/cdk/drag-drop/directives/drag.spec.js:104:57)
```

Currently the format error function that is supposed to clean up paths in the error message, accidentally
matches the first path starting with `(50px, 100px, 0px` and ending with `drag.spec.ts:79:44`). Resulting in
a broken error message like:

```
        Error: Expected 'translate3d(../src/cdk/drag-drop/directives/drag.spec.ts:79:44 <- bin/src/cdk/drag-drop/directives/drag.spec.js:104:57)
            at UserContext.eval (external/npm/node_modules/zone.js/dist/zone-testing-bundle.js:4954:30)
            at ZoneDelegate.invoke (external/npm/node_modules/zone.js/dist/zone-testing-bundle.js:391:26)
```
  • Loading branch information
devversion authored and alexeagle committed Aug 26, 2019
1 parent 5551ab9 commit f871be6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/karma/src/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ try {
// This is a bazel specific formatError that removes the workspace
// name from stack traces.
// Look for filenames of the format "(<filename>:<row>:<column>"
const FILENAME_REGEX = /\(([^:]+)(:\d+:\d+)/gm;
const FILENAME_REGEX = /\(([^:\n\r]+)(:\d+:\d+)/gm;
msg = msg.replace(FILENAME_REGEX, (_, p1, p2) => {
if (p1.startsWith('../')) {
// Remove all leading "../"
Expand Down

0 comments on commit f871be6

Please sign in to comment.