Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Migrate to Relay Modern #616

Merged
merged 78 commits into from
Sep 7, 2017
Merged

Migrate to Relay Modern #616

merged 78 commits into from
Sep 7, 2017

Conversation

alloy
Copy link
Contributor

@alloy alloy commented Jun 13, 2017

This depends on these Relay patches https://github.com/alloy/relay/pull/4

@artsy-peril
Copy link
Contributor

artsy-peril bot commented Aug 24, 2017

Warnings
⚠️

Could not get info from npm on @playlyfe/gql

⚠️

Could not get info from npm on @types/react

New dependencies added: relay-runtime, @playlyfe/gql, @types/react, babel-plugin-relay, babel-preset-es2015, babel-preset-react, babel-preset-stage-0, jest-styled-components and relay-compiler.

relay-runtime

Author: Unknown

Description: A core runtime for building GraphQL-driven applications.

Homepage: https://facebook.github.io/relay/

Created6 months ago
Last Updated11 days ago
LicenseBSD-3-Clause
Maintainers3
Releases14
Direct Dependenciesbabel-runtime, fbjs and relay-debugger-react-native-runtime
Keywordsgraphql and relay
README

ERROR: No README data found!

yarn why relay-runtime output

yarn why @playlyfe/gql output

yarn why @types/react output

babel-plugin-relay

Author: Unknown

Description: A Babel Plugin for use with Relay applications.

Homepage: https://facebook.github.io/relay/

Createdabout 2 years ago
Last Updated11 days ago
LicenseBSD-3-Clause
Maintainers6
Releases15
Direct Dependenciesgraphql, babel-runtime and babel-types
Keywordsgraphql, relay, babel and babel-plugin
README

ERROR: No README data found!

yarn why babel-plugin-relay output

babel-preset-es2015

Author: Sebastian McKenzie

Description: Babel preset for all es2015 plugins.

Homepage: https://babeljs.io/

Createdalmost 2 years ago
Last Updated4 days ago
LicenseMIT
Maintainers5
Releases40
Direct Dependenciesbabel-plugin-check-es2015-constants, babel-plugin-transform-es2015-arrow-functions, babel-plugin-transform-es2015-block-scoped-functions, babel-plugin-transform-es2015-block-scoping, babel-plugin-transform-es2015-classes, babel-plugin-transform-es2015-computed-properties, babel-plugin-transform-es2015-destructuring, babel-plugin-transform-es2015-duplicate-keys, babel-plugin-transform-es2015-for-of, babel-plugin-transform-es2015-function-name, babel-plugin-transform-es2015-literals, babel-plugin-transform-es2015-modules-amd, babel-plugin-transform-es2015-modules-commonjs, babel-plugin-transform-es2015-modules-systemjs, babel-plugin-transform-es2015-modules-umd, babel-plugin-transform-es2015-object-super, babel-plugin-transform-es2015-parameters, babel-plugin-transform-es2015-shorthand-properties, babel-plugin-transform-es2015-spread, babel-plugin-transform-es2015-sticky-regex, babel-plugin-transform-es2015-template-literals, babel-plugin-transform-es2015-typeof-symbol, babel-plugin-transform-es2015-unicode-regex and babel-plugin-transform-regenerator
README

babel-preset-es2015

Babel preset for all es2015 plugins.

Install

npm install --save-dev babel-preset-es2015

Usage

Via .babelrc (Recommended)

.babelrc

{
  "presets": ["es2015"]
}

Via CLI

babel script.js --presets es2015

Via Node API

require("babel-core").transform("code", {
  presets: ["es2015"]
});

Options

loose

boolean, defaults to false.

Enable "loose" transformations for any plugins in this preset that allow them.

modules

"amd" | "umd" | "systemjs" | "commonjs" | false, defaults to "commonjs".

Enable transformation of ES6 module syntax to another module type.

Setting this to false will not transform modules.

spec

boolean, defaults to false.

Enable "spec" transformations for any plugins in this preset that allow them.

yarn why babel-preset-es2015 output

  • Has been hoisted to "babel-preset-es2015"
  • This module exists because it's specified in "dependencies".
  • Disk size without dependencies: "24kB"
  • Disk size with unique dependencies: "644kB"
  • Disk size with transitive dependencies: "15.27MB"
  • Number of shared dependencies: 53

babel-preset-react

Author: Sebastian McKenzie

Description: Babel preset for all React plugins.

Homepage: https://babeljs.io/

Createdalmost 2 years ago
Last Updated6 days ago
LicenseMIT
Maintainers5
Releases33
Direct Dependenciesbabel-preset-flow, babel-plugin-syntax-jsx, babel-plugin-transform-react-display-name, babel-plugin-transform-react-jsx, babel-plugin-transform-react-jsx-source and babel-plugin-transform-react-jsx-self
README

babel-preset-react

Babel preset for all React plugins.

This preset includes the following plugins/presets:

Install

You can also check out the React Getting Started page

For more info, check out the setup page on the cli and the usage docs.

Install the CLI and this preset

npm install --save-dev babel-cli babel-preset-react

Make a .babelrc config file with the preset

echo '{ "presets": ["react"] }' > .babelrc

Create a file to run on

echo '<h1>Hello, world!</h1>' > index.js

View the output

./node_modules/.bin/babel index.js

Usage

Via .babelrc (Recommended)

.babelrc

{
  "presets": ["react"]
}

Via CLI

babel script.js --presets react 

Via Node API

require("babel-core").transform("code", {
  presets: ["react"]
});
yarn why babel-preset-react output

babel-preset-stage-0

Author: Sebastian McKenzie

Description: Babel preset for stage 0 plugins

Homepage: https://babeljs.io/

Createdalmost 2 years ago
Last Updated9 days ago
LicenseMIT
Maintainers5
Releases27
Direct Dependenciesbabel-plugin-transform-do-expressions, babel-plugin-transform-function-bind and babel-preset-stage-1
README

babel-preset-stage-0

Babel preset for stage 0 plugins.

Install

npm install --save-dev babel-preset-stage-0

Usage

Via .babelrc (Recommended)

.babelrc

{
  "presets": ["stage-0"]
}

Via CLI

babel script.js --presets stage-0

Via Node API

require("babel-core").transform("code", {
  presets: ["stage-0"]
});
yarn why babel-preset-stage-0 output

jest-styled-components

Author: Michele Bertoli

Description: Jest utilities for Styled Components

Homepage: https://github.com/styled-components/jest-styled-components#readme

Created6 months ago
Last Updated3 days ago
LicenseMIT
Maintainers2
Releases60
Direct Dependenciescss
README

NPM version
Join the community on Spectrum

Build Status
tested with jest
styled with prettier

Jest Styled Components

A set of utilities for testing Styled Components with Jest.
This package improves the snapshot testing experience and provides a brand new matcher to make expectations on the style rules.

Quick Start

Installation

yarn add --dev jest-styled-components

Usage

import React from 'react'
import styled from 'styled-components'
import renderer from 'react-test-renderer'
import 'jest-styled-components'

const Button = styled.button`
  color: red;
`

test('it works', () => {
  const tree = renderer.create(<Button />).toJSON()
  expect(tree).toMatchSnapshot()
  expect(tree).toHaveStyleRule('color', 'red')
})

Snapshot Testing

Jest snapshot testing is an excellent way to test React components (or any serializable value) and make sure things don't change unexpectedly.
It works with Styled Components but there are a few problems that this package addresses and solves.

For example, suppose we create this styled Button:

import styled from 'styled-components'

const Button = styled.button`
  color: red;
`

Which we cover with the following test:

import React from 'react'
import renderer from 'react-test-renderer'

test('it works', () => {
  const tree = renderer.create(<Button />).toJSON()
  expect(tree).toMatchSnapshot()
})

When we run our test command, Jest generates a snapshot containing a few class names (which we didn't set) and no information about the style rules:

exports[`it works 1`] = `
<button
  className="sc-bdVaJa rOCEJ"
/>
`;

Consequently, changing the color to green:

const Button = styled.button`
  color: green;
`

Results in the following diff, where Jest can only tell us that the class names are changed.
Although we can assume that if the class names are changed the style rules are also changed, this is not optimal (and is not always true).

- Snapshot
+ Received

 <button
-  className="sc-bdVaJa rOCEJ"
+  className="sc-bdVaJa hUzqNt"
 />

Here's where Jest Styled Components comes to rescue.

We just import the package into our test file:

import 'jest-styled-components'

When we rerun the test, the output is different: the style rules are included in the snapshot, and the hashed class names are substituted with placeholders that make the diffs less noisy:

- Snapshot
+ Received

+.c0 {
+  color: green;
+}
+
 <button
-  className="sc-bdVaJa rOCEJ"
+  className="c0"
 />

This is the resulting snapshot:

exports[`it works 1`] = `
.c0 {
  color: green;
}

<button
  className="c0"
/>
`;

Now, suppose we change the color again to blue:

const Button = styled.button`
  color: blue;
`

Thanks to Jest Styled Components, Jest is now able to provide the exact information and make our testing experience even more delightful 💖:

- Snapshot
+ Received

 .c0 {
-  color: green;
+  color: blue;
 }

 <button
   className="c0"
 />

Enzyme

enzyme-to-json is necessary to generate snapshots using Enzyme's shallow or full DOM rendering.

yarn add --dev enzyme-to-json

It can be enabled globally in the package.json:

"jest": {
  "snapshotSerializers": [
    "enzyme-to-json/serializer"
  ]
}

Or imported in each test:

import toJson from 'enzyme-to-json'

// ...

expect(toJson(wrapper)).toMatchSnapshot()

Jest Styled Components works with shallow rendering:

import { shallow } from 'enzyme'

test('it works', () => {
  const wrapper = shallow(<Button />)
  expect(wrapper).toMatchSnapshot()
})

And full DOM rendering as well:

import { mount } from 'enzyme'

test('it works', () => {
  const wrapper = mount(<Button />)
  expect(wrapper).toMatchSnapshot()
})

toHaveStyleRule

The toHaveStyleRule matcher is useful to test if a given rule is applied to a component.
The first argument is the expected property, the second is the expected value (string or RegExp).

test('it works', () => {
  const tree = renderer.create(<Button />).toJSON()
  expect(tree).toHaveStyleRule('color', 'red')
})

The matcher supports a third options parameter which makes it possible to search for rules nested within an At-rule (media and supports) or to add modifiers to the class selector. This feature is supported in React only, and more options are coming soon.

const Button = styled.button`
  @media (max-width: 640px) {
    &:hover {
      color: red;
    }
  }
`

test('it works', () => {
  const tree = renderer.create(<Button />).toJSON()
  expect(tree).toHaveStyleRule('color', 'red', {
    media: '(max-width: 640px)',
    modifier: ':hover',
  })
})

This matcher works with trees serialized with react-test-renderer and shallow renderered or mounted with Enzyme.
It checks the style rules applied to the root component it receives, therefore to make assertions on components further in the tree they must be provided separately (Enzyme's find might help).

To use the toHaveStyleRule matcher with React Native, change the import statement to:

import 'jest-styled-components/native'

Global installation

It is possibile to setup this package for all the tests using the setupTestFrameworkScriptFile option:

"jest": {
  "setupTestFrameworkScriptFile": "./setupTest.js"
}

And import the library once in the setupTest.js as follows:

import 'jest-styled-components'

styled-components < v2

To use this package with styled-components < v2 (e.g. v1.4.6) the following annotation must be added at the top of the test files.
Consequently, it won't be possible to use Enzyme's full DOM rendering.

/**
 * @jest-environment node
 */

Contributing

Please open an issue and discuss with us before submitting a PR.

yarn why jest-styled-components output

Generated by 🚫 dangerJS

@ArtsyOpenSource
Copy link

ArtsyOpenSource commented Sep 1, 2017

Fails
🚫

Please assign someone to merge this PR, and optionally include people who should review.

🚫

Missing Test Files:

  • src/lib/Components/Artist/Articles/__tests__/index-tests.tsx
  • src/lib/Components/Artist/Artworks/__tests__/index-tests.tsx
  • src/lib/Components/Artist/Shows/__tests__/index-tests.tsx
  • src/lib/Components/ArtworkGrids/__tests__/GenericGrid-tests.tsx
  • src/lib/Components/Consignments/Components/__tests__/DoneButton-tests.tsx
  • src/lib/Components/Consignments/Typography/__tests__/index-tests.tsx
  • src/lib/Components/Home/ArtistRails/__tests__/ArtistRail-tests.tsx
  • src/lib/Components/Home/ArtworkRails/__tests__/ArtworkRailHeader-tests.tsx
  • src/lib/Components/Home/__tests__/HeroUnits-tests.tsx
  • src/lib/Components/Inbox/ActiveBids/__tests__/index-tests.tsx
  • src/lib/Components/Inbox/Conversations/Preview/Attachment/__tests__/AttachmentPreview-tests.tsx
  • src/lib/Components/Inbox/Conversations/__tests__/index-tests.tsx
  • src/lib/Components/Inbox/Typography/__tests__/index-tests.tsx
  • src/lib/Components/__tests__/OpaqueImageView-tests.tsx
  • src/lib/Components/RelatedArtists/__tests__/RelatedArtist-tests.tsx
  • src/lib/Components/RelatedArtists/__tests__/index-tests.tsx
  • src/lib/Components/Text/__tests__/Headline-tests.tsx
  • src/lib/__tests__/metaphysics-tests.ts
  • src/lib/Components/ArtworkGrids/RelayConnections/__tests__/ArtistForSaleArtworksGrid-tests.tsx
  • src/lib/Components/ArtworkGrids/RelayConnections/__tests__/ArtistNotForSaleArtworksGrid-tests.tsx

If these files are supposed to not exist, please update your PR body to include "Skip New Tests".

Generated by 🚫 dangerJS

@orta
Copy link
Contributor

orta commented Sep 1, 2017

I wonder what it is about this PR that breaks danger

@alloy alloy changed the title [WIP] Migrate to Relay Modern Migrate to Relay Modern Sep 5, 2017
@orta
Copy link
Contributor

orta commented Sep 6, 2017

RN 0.48 has issues with node 8.4 - it's not our official emission node version - but worth a mention facebook/react-native#15810 if anyone else has this error: TypeError: Cannot read property 'BLOB_URI_SCHEME' of undefined

@l2succes
Copy link
Contributor

l2succes commented Sep 7, 2017

🚨 Alrighty merging! 🚨

@sarahscott @alloy We got all tests and build green (aside from the travis-ci/pr which is timing out but that should fix itself in master). We still some remaining tasks in this PR description that we can handle in separate PR.

@l2succes l2succes merged commit 633ef31 into master Sep 7, 2017
@orta orta deleted the relay-modern branch September 7, 2017 21:00
@orta
Copy link
Contributor

orta commented Sep 7, 2017

Congrats

@alloy
Copy link
Contributor Author

alloy commented Sep 8, 2017

SO. HAPPY! 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants