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

Update to Jest 22 #11956

Merged
merged 14 commits into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from 7 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
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"babel-code-frame": "^6.26.0",
"babel-core": "^6.0.0",
"babel-eslint": "^7.1.0",
"babel-jest": "^21.3.0-beta.4",
"babel-jest": "^22.0.4",
"babel-plugin-check-es2015-constants": "^6.5.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
Expand Down Expand Up @@ -67,10 +67,7 @@
"gzip-js": "~0.3.2",
"gzip-size": "^3.0.0",
"jasmine-check": "^1.0.0-rc.0",
"jest": "^21.3.0-beta.4",
"jest-config": "^21.3.0-beta.4",
"jest-jasmine2": "^21.3.0-beta.4",
"jest-runtime": "^21.3.0-beta.4",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We weren't using these anymore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect is still in here in beta, is that used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not..

"jest": "^22.0.4",
"merge-stream": "^1.0.0",
"minimatch": "^3.0.4",
"minimist": "^1.2.0",
Expand Down
24 changes: 15 additions & 9 deletions packages/react-art/src/__tests__/ReactART-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ function testDOMNodeStructure(domNode, expectedStructure) {
}

describe('ReactART', () => {
let container;

beforeEach(() => {
container = document.createElement('div');
document.body.appendChild(container);

ARTCurrentMode.setCurrent(ARTSVGMode);

Group = ReactART.Group;
Expand Down Expand Up @@ -104,6 +109,11 @@ describe('ReactART', () => {
};
});

afterEach(() => {
document.body.removeChild(container);
container = null;
});

it('should have the correct lifecycle state', () => {
let instance = <TestComponent />;
instance = ReactTestUtils.renderIntoDocument(instance);
Expand Down Expand Up @@ -142,7 +152,6 @@ describe('ReactART', () => {
});

it('should be able to reorder components', () => {
const container = document.createElement('div');
const instance = ReactDOM.render(
<TestComponent flipped={false} />,
container,
Expand Down Expand Up @@ -189,8 +198,6 @@ describe('ReactART', () => {
});

it('should be able to reorder many components', () => {
const container = document.createElement('div');

class Component extends React.Component {
render() {
const chars = this.props.chars.split('');
Expand Down Expand Up @@ -296,17 +303,13 @@ describe('ReactART', () => {
);
}
}

const container = document.createElement('div');
ReactDOM.render(<Outer />, container);
expect(ref).not.toBeDefined();
ReactDOM.render(<Outer mountCustomShape={true} />, container);
expect(ref.constructor).toBe(CustomShape);
});

it('adds and updates event handlers', () => {
const container = document.createElement('div');

function render(onClick) {
return ReactDOM.render(
<Surface>
Expand All @@ -319,8 +322,11 @@ describe('ReactART', () => {
function doClick(instance) {
const path = ReactDOM.findDOMNode(instance).querySelector('path');

// ReactTestUtils.Simulate.click doesn't work with SVG elements
path.click();
path.dispatchEvent(
new MouseEvent('click', {
bubbles: true,
}),
);
}

const onClick1 = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`ReactARTComponents should generate a <Shape> with props for drawing the Circle 1`] = `
<Shape
d={
{
Object {
"_pivotX": 0,
"_pivotY": -10,
"path": Array [
Expand All @@ -28,7 +28,7 @@ exports[`ReactARTComponents should generate a <Shape> with props for drawing the
exports[`ReactARTComponents should generate a <Shape> with props for drawing the Rectangle 1`] = `
<Shape
d={
{
Object {
"_pivotX": 0,
"_pivotY": 0,
"path": Array [
Expand All @@ -54,7 +54,7 @@ exports[`ReactARTComponents should generate a <Shape> with props for drawing the
exports[`ReactARTComponents should generate a <Shape> with props for drawing the Wedge 1`] = `
<Shape
d={
{
Object {
"_pivotX": 0,
"_pivotY": 50,
"path": Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ describe('DOMPropertyOperations', () => {
});

it('should set values as namespace attributes if necessary', () => {
const container = document.createElement('svg');
const container = document.createElementNS(
'http://www.w3.org/2000/svg',
'svg',
);
ReactDOM.render(<image xlinkHref="about:blank" />, container);
expect(
container.firstChild.getAttributeNS(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,21 +488,36 @@ describe('ReactDOMServerIntegration', () => {
);

itRenders('badly cased SVG attribute with a warning', async render => {
const e = await render(<text textlength="10" />, 1);
expect(e.getAttribute('textLength')).toBe('10');
const e = await render(
<svg>
<text textlength="10" />
</svg>,
1,
);
expect(e.firstChild.getAttribute('textLength')).toBe('10');
});

itRenders('no badly cased aliased SVG attribute alias', async render => {
const e = await render(<text strokedasharray="10 10" />, 1);
expect(e.hasAttribute('stroke-dasharray')).toBe(false);
expect(e.getAttribute('strokedasharray')).toBe('10 10');
const e = await render(
<svg>
<text strokedasharray="10 10" />
</svg>,
1,
);
expect(e.firstChild.hasAttribute('stroke-dasharray')).toBe(false);
expect(e.firstChild.getAttribute('strokedasharray')).toBe('10 10');
});

itRenders(
'no badly cased original SVG attribute that is aliased',
async render => {
const e = await render(<text stroke-dasharray="10 10" />, 1);
expect(e.getAttribute('stroke-dasharray')).toBe('10 10');
const e = await render(
<svg>
<text stroke-dasharray="10 10" />
</svg>,
1,
);
expect(e.firstChild.getAttribute('stroke-dasharray')).toBe('10 10');
},
);
});
Expand Down
16 changes: 15 additions & 1 deletion scripts/jest/setupEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ global.cancelIdleCallback = function(callbackID) {
// for the few that specifically test the logging by shadowing this
// property. In real apps, it would usually not be defined at all.
Error.prototype.suppressReactErrorLogging = true;
if (typeof DOMException === 'function') {

if (typeof window !== 'undefined') {
// Same as above.
DOMException.prototype.suppressReactErrorLogging = true;

// Also prevent JSDOM from logging intentionally thrown errors.
// TODO: it might make sense to do it the other way around.
// https://github.com/facebook/react/issues/11098#issuecomment-355032539
window.addEventListener('error', event => {
if (event.error != null && event.error.suppressReactErrorLogging) {
event.preventDefault();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth ensuring these are logged somewhere. I noticed on RDL that errors thrown in event handlers where being swallowed by jsdom under mysterious circumstances...I guess there is already an issue for it tho: #8260

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thanks for highlighting that. They are logged now (by jsdom) but we should probably fail the build on them (?)

This issue (and related PR) is actually why I got curious about updating jsdom :P

});

// Mock for ReactART.
HTMLCanvasElement.prototype.getContext = () => ({});
}
Loading