mirror of
https://github.com/facebook/react.git
synced 2026-02-26 18:58:05 +00:00
* Migrate conditional tests to gate pragma
I searched through the codebase for this pattern:
```js
describe('test suite', () => {
if (!__EXPERIMENTAL__) { // or some other condition
test("empty test so Jest doesn't complain", () => {});
return;
}
// Unless we're in experimental mode, none of the tests in this block
// will run.
})
```
and converted them to the `@gate` pragma instead.
The reason this pattern isn't preferred is because you end up disabling
more tests than you need to.
* Add flag for www release channels
Using a heuristic where I check a flag that is known to only be enabled
in www. I left a TODO to instead set the release channel explicitly in
each test config.
113 lines
3.3 KiB
JavaScript
113 lines
3.3 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* 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');
|
|
});
|
|
|
|
// @gate !enableComponentStackLocations || !__DEV__
|
|
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 (const 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++;
|
|
}
|
|
}
|
|
});
|
|
});
|