Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include columns in stack frames #5889

Merged
merged 4 commits into from
Apr 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
mode. ([#5861](https://github.com/facebook/jest/pull/5861))
* `[jest-mock]` Extend .toHaveBeenCalled return message with outcome
([#5951](https://github.com/facebook/jest/pull/5951))
* `[jest-message-util]` Include column in stack frames
([#5889](https://github.com/facebook/jest/pull/5889))
* `[jest-runner]` Assign `process.env.JEST_WORKER_ID="1"` when in runInBand mode
([#5860](https://github.com/facebook/jest/pull/5860))
* `[jest-cli]` Add descriptive error message when trying to use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports[`works with custom matchers 1`] = `
43 | const bar = () => baz();
44 | const baz = () => {
> 45 | throw Error('qux');
| ^
46 | };
47 |
48 | // This expecation fails due to an error we throw (intentionally)
Expand Down
22 changes: 22 additions & 0 deletions integration-tests/__tests__/__snapshots__/failures.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ exports[`not throwing Error objects 4`] = `
11 | const throws = () => {
12 | expect.assertions(2);
> 13 | expect(false).toBeTruthy();
| ^
14 | };
15 | const redeclare = () => {
16 | expect.assertions(1);
Expand All @@ -55,6 +56,7 @@ exports[`not throwing Error objects 4`] = `
15 | const redeclare = () => {
16 | expect.assertions(1);
> 17 | expect(false).toBeTruthy();
| ^
18 | expect.assertions(2);
19 | };
20 |
Expand Down Expand Up @@ -116,6 +118,7 @@ exports[`not throwing Error objects 5`] = `
26 | test('Error during test', () => {
27 | // eslint-disable-next-line no-undef
> 28 | doesNotExist.alsoThisNot;
| ^
29 | });
30 |
31 | test('done(Error)', done => {
Expand All @@ -129,6 +132,7 @@ exports[`not throwing Error objects 5`] = `
30 |
31 | test('done(Error)', done => {
> 32 | done(new Error('this is an error'));
| ^
33 | });
34 |
35 | test('done(non-error)', done => {
Expand All @@ -149,6 +153,7 @@ exports[`not throwing Error objects 5`] = `
34 |
35 | test('done(non-error)', done => {
> 36 | done(deepObject);
| ^
37 | });
38 |

Expand All @@ -174,6 +179,7 @@ exports[`works with assertions in separate files 1`] = `
10 |
11 | module.exports = (one: any, two: any) => {
> 12 | expect(one).toEqual(two);
| ^
13 | };
14 |

Expand Down Expand Up @@ -242,6 +248,7 @@ exports[`works with node assert 1`] = `
13 |
14 | test('assert', () => {
> 15 | assert(false);
| ^
16 | });
17 |
18 | test('assert with a message', () => {
Expand All @@ -263,6 +270,7 @@ exports[`works with node assert 1`] = `
17 |
18 | test('assert with a message', () => {
> 19 | assert(false, 'this is a message');
| ^
20 | });
21 |
22 | test('assert.ok', () => {
Expand All @@ -281,6 +289,7 @@ exports[`works with node assert 1`] = `
21 |
22 | test('assert.ok', () => {
> 23 | assert.ok(false);
| ^
24 | });
25 |
26 | test('assert.ok with a message', () => {
Expand All @@ -302,6 +311,7 @@ exports[`works with node assert 1`] = `
25 |
26 | test('assert.ok with a message', () => {
> 27 | assert.ok(false, 'this is a message');
| ^
28 | });
29 |
30 | test('assert.equal', () => {
Expand All @@ -320,6 +330,7 @@ exports[`works with node assert 1`] = `
29 |
30 | test('assert.equal', () => {
> 31 | assert.equal(1, 2);
| ^
32 | });
33 |
34 | test('assert.notEqual', () => {
Expand All @@ -342,6 +353,7 @@ exports[`works with node assert 1`] = `
33 |
34 | test('assert.notEqual', () => {
> 35 | assert.notEqual(1, 1);
| ^
36 | });
37 |
38 | test('assert.deepEqual', () => {
Expand Down Expand Up @@ -374,6 +386,7 @@ exports[`works with node assert 1`] = `
37 |
38 | test('assert.deepEqual', () => {
> 39 | assert.deepEqual({a: {b: {c: 5}}}, {a: {b: {c: 6}}});
| ^
40 | });
41 |
42 | test('assert.deepEqual with a message', () => {
Expand Down Expand Up @@ -409,6 +422,7 @@ exports[`works with node assert 1`] = `
41 |
42 | test('assert.deepEqual with a message', () => {
> 43 | assert.deepEqual({a: {b: {c: 5}}}, {a: {b: {c: 7}}}, 'this is a message');
| ^
44 | });
45 |
46 | test('assert.notDeepEqual', () => {
Expand All @@ -431,6 +445,7 @@ exports[`works with node assert 1`] = `
45 |
46 | test('assert.notDeepEqual', () => {
> 47 | assert.notDeepEqual({a: 1}, {a: 1});
| ^
48 | });
49 |
50 | test('assert.strictEqual', () => {
Expand All @@ -449,6 +464,7 @@ exports[`works with node assert 1`] = `
49 |
50 | test('assert.strictEqual', () => {
> 51 | assert.strictEqual(1, NaN);
| ^
52 | });
53 |
54 | test('assert.notStrictEqual', () => {
Expand All @@ -474,6 +490,7 @@ exports[`works with node assert 1`] = `
53 |
54 | test('assert.notStrictEqual', () => {
> 55 | assert.notStrictEqual(1, 1, 'My custom error message');
| ^
56 | });
57 |
58 | test('assert.deepStrictEqual', () => {
Expand Down Expand Up @@ -502,6 +519,7 @@ exports[`works with node assert 1`] = `
57 |
58 | test('assert.deepStrictEqual', () => {
> 59 | assert.deepStrictEqual({a: 1}, {a: 2});
| ^
60 | });
61 |
62 | test('assert.notDeepStrictEqual', () => {
Expand All @@ -524,6 +542,7 @@ exports[`works with node assert 1`] = `
61 |
62 | test('assert.notDeepStrictEqual', () => {
> 63 | assert.notDeepStrictEqual({a: 1}, {a: 1});
| ^
64 | });
65 |
66 | test('assert.ifError', () => {
Expand All @@ -550,6 +569,7 @@ exports[`works with node assert 1`] = `
69 |
70 | test('assert.doesNotThrow', () => {
> 71 | assert.doesNotThrow(() => {
| ^
72 | throw Error('err!');
73 | });
74 | });
Expand All @@ -569,6 +589,7 @@ exports[`works with node assert 1`] = `
75 |
76 | test('assert.throws', () => {
> 77 | assert.throws(() => {});
| ^
78 | });
79 |

Expand All @@ -593,6 +614,7 @@ exports[`works with snapshot failures 1`] = `
10 |
11 | test('failing snapshot', () => {
> 12 | expect('foo').toMatchSnapshot();
| ^
13 | });
14 |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ exports[`cannot test with no implementation 1`] = `
1 |
2 | it('it', () => {});
> 3 | it('it, no implementation');
| ^
4 | test('test, no implementation');
5 |

Expand Down Expand Up @@ -56,6 +57,7 @@ exports[`cannot test with no implementation with expand arg 1`] = `
1 |
2 | it('it', () => {});
> 3 | it('it, no implementation');
| ^
4 | test('test, no implementation');
5 |

Expand Down
1 change: 1 addition & 0 deletions integration-tests/__tests__/failures.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ test('works with node assert', () => {
69 |
70 | test('assert.doesNotThrow', () => {
> 71 | assert.doesNotThrow(() => {
| ^
72 | throw Error('err!');
73 | });
74 | });
Expand Down
14 changes: 11 additions & 3 deletions packages/jest-message-util/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ const trim = string => (string || '').trim();
const trimPaths = string =>
string.match(STACK_PATH_REGEXP) ? trim(string) : string;

const getRenderedCallsite = (fileContent: string, line: number) => {
const getRenderedCallsite = (
fileContent: string,
line: number,
column?: number,
) => {
let renderedCallsite = codeFrameColumns(
fileContent,
{start: {line}},
{start: {column, line}},
{highlightCode: true},
);

Expand Down Expand Up @@ -258,7 +262,11 @@ export const formatStackTrace = (
// TODO: check & read HasteFS instead of reading the filesystem:
// see: https://github.com/facebook/jest/pull/5405#discussion_r164281696
fileContent = fs.readFileSync(filename, 'utf8');
renderedCallsite = getRenderedCallsite(fileContent, topFrame.line);
renderedCallsite = getRenderedCallsite(
fileContent,
topFrame.line,
topFrame.column,
);
} catch (e) {
// the file does not exist or is inaccessible, we ignore
}
Expand Down