-
Notifications
You must be signed in to change notification settings - Fork 47.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve display of filenames in component stack (#12059)
* Improve display of filenames in component stack * Add explanatory comment * tests: add tests for component stack trace displaying * Tweak test * Rewrite test and revert implementation * Extract a variable * Rewrite implementation
- Loading branch information
1 parent
067cc24
commit 54d86eb
Showing
2 changed files
with
133 additions
and
13 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
packages/shared/__tests__/describeComponentFrame-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,111 @@ | ||
/** | ||
* Copyright (c) 2016-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let React; | ||
let ReactDOM; | ||
|
||
describe('Component stack trace displaying', () => { | ||
beforeEach(() => { | ||
React = require('react'); | ||
ReactDOM = require('react-dom'); | ||
}); | ||
|
||
it('should provide filenames in stack traces', () => { | ||
class Component extends React.Component { | ||
render() { | ||
return [<span>a</span>, <span>b</span>]; | ||
} | ||
} | ||
|
||
spyOnDev(console, 'error'); | ||
const container = document.createElement('div'); | ||
const fileNames = { | ||
'': '', | ||
'/': '', | ||
'\\': '', | ||
Foo: 'Foo', | ||
'Bar/Foo': 'Foo', | ||
'Bar\\Foo': 'Foo', | ||
'Baz/Bar/Foo': 'Foo', | ||
'Baz\\Bar\\Foo': 'Foo', | ||
|
||
'Foo.js': 'Foo.js', | ||
'Foo.jsx': 'Foo.jsx', | ||
'/Foo.js': 'Foo.js', | ||
'/Foo.jsx': 'Foo.jsx', | ||
'\\Foo.js': 'Foo.js', | ||
'\\Foo.jsx': 'Foo.jsx', | ||
'Bar/Foo.js': 'Foo.js', | ||
'Bar/Foo.jsx': 'Foo.jsx', | ||
'Bar\\Foo.js': 'Foo.js', | ||
'Bar\\Foo.jsx': 'Foo.jsx', | ||
'/Bar/Foo.js': 'Foo.js', | ||
'/Bar/Foo.jsx': 'Foo.jsx', | ||
'\\Bar\\Foo.js': 'Foo.js', | ||
'\\Bar\\Foo.jsx': 'Foo.jsx', | ||
'Bar/Baz/Foo.js': 'Foo.js', | ||
'Bar/Baz/Foo.jsx': 'Foo.jsx', | ||
'Bar\\Baz\\Foo.js': 'Foo.js', | ||
'Bar\\Baz\\Foo.jsx': 'Foo.jsx', | ||
'/Bar/Baz/Foo.js': 'Foo.js', | ||
'/Bar/Baz/Foo.jsx': 'Foo.jsx', | ||
'\\Bar\\Baz\\Foo.js': 'Foo.js', | ||
'\\Bar\\Baz\\Foo.jsx': 'Foo.jsx', | ||
'C:\\funny long (path)/Foo.js': 'Foo.js', | ||
'C:\\funny long (path)/Foo.jsx': 'Foo.jsx', | ||
|
||
'index.js': 'index.js', | ||
'index.jsx': 'index.jsx', | ||
'/index.js': 'index.js', | ||
'/index.jsx': 'index.jsx', | ||
'\\index.js': 'index.js', | ||
'\\index.jsx': 'index.jsx', | ||
'Bar/index.js': 'Bar/index.js', | ||
'Bar/index.jsx': 'Bar/index.jsx', | ||
'Bar\\index.js': 'Bar/index.js', | ||
'Bar\\index.jsx': 'Bar/index.jsx', | ||
'/Bar/index.js': 'Bar/index.js', | ||
'/Bar/index.jsx': 'Bar/index.jsx', | ||
'\\Bar\\index.js': 'Bar/index.js', | ||
'\\Bar\\index.jsx': 'Bar/index.jsx', | ||
'Bar/Baz/index.js': 'Baz/index.js', | ||
'Bar/Baz/index.jsx': 'Baz/index.jsx', | ||
'Bar\\Baz\\index.js': 'Baz/index.js', | ||
'Bar\\Baz\\index.jsx': 'Baz/index.jsx', | ||
'/Bar/Baz/index.js': 'Baz/index.js', | ||
'/Bar/Baz/index.jsx': 'Baz/index.jsx', | ||
'\\Bar\\Baz\\index.js': 'Baz/index.js', | ||
'\\Bar\\Baz\\index.jsx': 'Baz/index.jsx', | ||
'C:\\funny long (path)/index.js': 'funny long (path)/index.js', | ||
'C:\\funny long (path)/index.jsx': 'funny long (path)/index.jsx', | ||
}; | ||
Object.keys(fileNames).forEach((fileName, i) => { | ||
ReactDOM.render( | ||
<Component __source={{fileName, lineNumber: i}} />, | ||
container, | ||
); | ||
}); | ||
if (__DEV__) { | ||
let i = 0; | ||
expect(console.error.calls.count()).toBe(Object.keys(fileNames).length); | ||
for (let fileName in fileNames) { | ||
if (!fileNames.hasOwnProperty(fileName)) { | ||
continue; | ||
} | ||
const args = console.error.calls.argsFor(i); | ||
const stack = args[args.length - 1]; | ||
const expected = fileNames[fileName]; | ||
expect(stack).toContain(`at ${expected}:`); | ||
i++; | ||
} | ||
} | ||
}); | ||
}); |
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