-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stack traces and runtime error reporting.
- Loading branch information
Showing
16 changed files
with
219 additions
and
87 deletions.
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
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,107 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
const runJest = require('../runJest'); | ||
|
||
describe('Stack Trace', () => { | ||
|
||
it('prints a stack trace for runtime errors', () => { | ||
const result = runJest('stack_trace', ['runtime-error-test.js']); | ||
const stdout = result.stdout.toString(); | ||
|
||
expect(stdout).toMatch( | ||
/1 test suite failed, 0 tests passed/ | ||
); | ||
expect(result.status).toBe(1); | ||
expect(stdout).toMatch( | ||
/ReferenceError: thisIsARuntimeError is not defined/ | ||
); | ||
expect(stdout).toMatch( | ||
/\s+at\s(?:.+?)\s\(__integration_tests__\/runtime-error-test\.js/ | ||
); | ||
}); | ||
|
||
it('does not print a stack trace for runtime errors when --noStackTrace is given', () => { | ||
const result = runJest('stack_trace', [ | ||
'runtime-error-test.js', | ||
'--noStackTrace', | ||
]); | ||
const stdout = result.stdout.toString(); | ||
|
||
expect(stdout).toMatch( | ||
/1 test suite failed, 0 tests passed/ | ||
); | ||
expect(result.status).toBe(1); | ||
|
||
expect(stdout).toMatch( | ||
/ReferenceError: thisIsARuntimeError is not defined/ | ||
); | ||
expect(stdout).not.toMatch( | ||
/\s+at\s(?:.+?)\s\(__integration_tests__\/runtime-error-test\.js/ | ||
); | ||
}); | ||
|
||
it('prints a stack trace for matching errors', () => { | ||
const result = runJest('stack_trace', ['stack-trace-test.js']); | ||
const stdout = result.stdout.toString(); | ||
|
||
expect(stdout).toMatch(/1 test failed, 0 tests passed/); | ||
expect(result.status).toBe(1); | ||
|
||
expect(stdout).toMatch( | ||
/\s+at\s(?:.+?)\s\(__integration_tests__\/stack-trace-test\.js/ | ||
); | ||
}); | ||
|
||
it('does not print a stack trace for matching errors when --noStackTrace is given', () => { | ||
const result = runJest('stack_trace', [ | ||
'stack-trace-test.js', | ||
'--noStackTrace', | ||
]); | ||
const stdout = result.stdout.toString(); | ||
|
||
expect(stdout).toMatch(/1 test failed, 0 tests passed/); | ||
expect(result.status).toBe(1); | ||
|
||
expect(stdout).not.toMatch( | ||
/\s+at\s(?:.+?)\s\(__integration_tests__\/stack-trace-test\.js/ | ||
); | ||
}); | ||
|
||
it('prints a stack trace for errors', () => { | ||
const result = runJest('stack_trace', ['test-error-test.js']); | ||
const stdout = result.stdout.toString(); | ||
|
||
expect(stdout).toMatch(/2 tests failed, 0 tests passed/); | ||
expect(result.status).toBe(1); | ||
|
||
expect(stdout).toMatch(/Error: this is unexpected\./); | ||
expect(stdout).toMatch(/this is a string\. thrown/); | ||
|
||
expect(stdout).toMatch( | ||
/\s+at\s(?:.+?)\s\(__integration_tests__\/test-error-test\.js/ | ||
); | ||
}); | ||
|
||
it('does not print a stack trace for errors when --noStackTrace is given', () => { | ||
const result = runJest('stack_trace', [ | ||
'test-error-test.js', | ||
'--noStackTrace', | ||
]); | ||
const stdout = result.stdout.toString(); | ||
|
||
expect(stdout).toMatch(/2 tests failed, 0 tests passed/); | ||
expect(result.status).toBe(1); | ||
|
||
expect(stdout).not.toMatch( | ||
/\s+at\s(?:.+?)\s\(__integration_tests__\/test-error-test\.js/ | ||
); | ||
}); | ||
|
||
}); |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"jest": { | ||
"testPathIgnorePatterns": [ | ||
"__integration_tests__/(?!__tests__).*" | ||
] | ||
"unmockedModulePathPatterns": [ | ||
"<rootDir>/runJest.js$" | ||
] | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
integration_tests/stack_trace/__integration_tests__/runtime-error-test.js
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 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
thisIsARuntimeError(); |
14 changes: 14 additions & 0 deletions
14
integration_tests/stack_trace/__integration_tests__/stack-trace-test.js
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 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
describe('stack trace', () => { | ||
it('fails', () => { | ||
expect(1).toBe(3); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
integration_tests/stack_trace/__integration_tests__/test-error-test.js
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,19 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
/* eslint-disable no-throw-literal */ | ||
'use strict'; | ||
|
||
describe('error stack trace', () => { | ||
it('fails', () => { | ||
throw new Error('this is unexpected.'); | ||
}); | ||
|
||
it('fails strings', () => { | ||
throw 'this is a string.'; | ||
}); | ||
}); |
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,5 @@ | ||
{ | ||
"jest": { | ||
"testDirectoryName": "__integration_tests__" | ||
} | ||
} |
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
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
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
Oops, something went wrong.