Giter VIP home page Giter VIP logo

fructose's Introduction

Build Status

Fructose - Functional React (native) UI Tester

Brought to you by The Times Tooling team ย ๐Ÿ› 

Fructose is a testing library that enables the loading of react native and react native web components on a device.

We have used this to

  • Enable automated functional black and grey box testing of components.
  • Enable automated visual regression of components with Dextrose

Swipe right to see the component list and manually load a component

Overview

Fructose has 3 components:

The App

The Fructose app allows for the loading of arbitrary components at runtime. Once the app is started you are able to load the components in either manual or automated fashions.

The Server

The fructose server is how we proxy commands from the client to the app via websockets.

The Client

The fructose client is how we communicate to the server via websockets

Getting Started

We are actively working on this to become easier.

Running and understanding the examples

The best way to see what fructose does is to run the end to end tests.

Running

From the root of the project run yarn and then either...

yarn e2e:test:web

yarn e2e:test:ios

yarn e2e:test:android

You will need a (simulator | emulator | chrome) to run these examples.

Understanding the examples

In the e2e Test folder you will find examples of how to consume fructose. We suggest first looking at the scripts folder to understand the steps required for running tests with Fructose.

Then look at the examples folder.

The .showcase file is a description of how a component should be rendered. Showcase files came around because originally fructose consumed storybook files. This eventually resulted in numerous issues so we created an abstraction layer which decouples components from storybook. You can see a working example of how showcase to storybook works here.

Times-Components-storybook

Showcase files are then loaded into the app index via react-native-showcase-loader function.

The test file is an example of how to load a component ready for grey or black box testing.

Finally, the fructose folder is where all of the different platform indexes live.

Below are examples of iOS and Web e2eTests running and asserting that the app emits the component has loaded:

React Native Web

React Native IOS

(The red screen is expected as we're catching a component that errors)

(Yes the tests are asserting that quick)

Consuming Fructose

From your project

yarn add @times-components/fructose --dev
yarn add react-native-showcase-loader --dev

Create a folder fructose in your project root directory.

Create an index.*.js in this folder for your platform of choice: ios, android, or web.

Register the component to the name that your app binary expects.

Use react native showcase loader function to require in your showcase files.

See the examples below:

Ios Index Example

Run Ios Tests.sh Example

Writing tests

In a before, hook import setup from fructose and await on.

fructose.hooks.mobile.setup();
fructose.hooks.web.setup();

Ios setup Example

Once the setup promise resolves a fructoseClient. Use this client to tell your app to load components defined in your showcase files.

fructoseClient.loadComponent('your component name')

Your component is now ready for interrogation by the testing library of your choice. We have successfully used both appium and detox

Notes

We currently have Fructose running in a CI environment with...

Future

  1. Fructose cli to initialise and run tests

fructose's People

Contributors

craigbilner avatar hem-brahmbhatt avatar kaliabadi avatar l0wry avatar markconway94 avatar milesillsley avatar rjanjua avatar times-tools avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fructose's Issues

If a showcase is causing an error - log out which showcase file is causing the error

component loader should be able to handle a showcase file without a default, and when a showcase file causes an error, we should be able to log this out somehow. I'd imagine we need to tell the client somehow

lib-904da1664780380f.js:1 Uncaught TypeError: Cannot read property 'filter' of undefined
at lib-904da1664780380f.js:1
at Array.forEach ()
at t.default (lib-904da1664780380f.js:1)
at lib-904da1664780380f.js:1
at _ (lib-904da1664780380f.js:1)
at R (lib-904da1664780380f.js:1)
at c (lib-904da1664780380f.js:1)
at f (lib-904da1664780380f.js:1)
at HTMLUnknownElement.l (lib-904da1664780380f.js:1)
at Object.Oo (lib-904da1664780380f.js:1)

ReadMe links broken

"We recommend looking at the examples for web and native as there are slight differences."

This line in your ReadMe has broken links.

ability to run in parallel

Fructose does not currently handle sending different messages to different app clients. This means it can't run parallel tests.

Use of ID for loading fructose components in app

Perhaps we could add a unique identifier as a property on the components and use that to pull up our components from within the fructose app.

I believe this is a more defensive method as we are not as reliant on the format of the react native components.

The down side of this is in the components them selves you will need to add some testing prop. Similar in concept to CSS ID tags.

logs are very noisy

screen shot 2017-11-30 at 11 24 53

Logs are logging all previous 'loaded components' as well as the currently loaded one. We only want the currently loaded one.

Non descriptive errors

The throw new Error("should be the hobbit!"); is only thrown when the text here eg. "The Hobbit" is different to that of a if (a !== "The Hobbit") {
If "The Hobbit" text is different here: <Text style={styles.title} fructoseID="hobbit">The Hobbit</Text>,
or here await driver.waitForVisible('//*[@text="The Hobbit"]', 6000);
or here const a = await driver.getText('//*[@text="The Hobbit"]');
then only a plain Error is shown, see the attached screenshots.
Should errors at these points have better descriptions?

withComponent(
  <Text style={styles.title} fructoseID="hobbit">The Hobbit</Text>,
  "basic text",
  fructose => {
    beforeEach(async () => {
      await fructose.loadComponent();
    });

    test("simple test", async () => {
      await driver.waitForVisible('//*[@text="The Hobbit"]', 6000);
      const a = await driver.getText('//*[@text="The Hobbit"]');
      if (a !== "The Hobbit") {
        throw new Error("should be the hobbit!");
      }
    });
  }
);

plain error
descriptive error

change web start.js to take absolute path

swap


const directory = program.buildDir ? program.buildDir : ".fructose";
const upperConfig = require( `../../../../../../${directory}/webpack.config.js`);// eslin

for
const upperConfig = require( ${directory}/webpack.config.js);

and fix broken things

Showcase without default export

If a showcase file has no default export defined then it will throw an error saying that it cannot find children of undefined.

Should be more defensive around this. ๐Ÿ‘

rename unit test

packages/client/client.test.js
FructoseClient
โœ“ e2e test (34ms)

Lower case showcase names when loading

In times components our ignored showcase file looks like this

const ignoredShowcases = [
  "Brightcove",
  "brightcove",
  "Provider",
  "provider",
  "Video",
  "video",
  "Tracking",
  "tracking",
  "Loading",
  "Pages/Long Article",
  "Pages/Default"
];

we should sanitize our component input before we use it

fructose-cli

Fructose should have a cli like mocha or jest so that we don't have to work around the idiosyncrasies of jest. With a custom cli we can make the fructose experience smoother.

Dependency Issue

Issue:
Web tests fail when dependencies are installed in a certain order.

Steps to reproduce:

  1. Yarn within the root fructose directory
  2. Change to the e2eTests directory
  3. Yarn again.
  4. Run the web tests yarn test:web

Expected:
Web tests to pass

Actual:
Web tests fail

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.