Skip to content

Gray box end-to-end testing and automation library for mobile apps in Reason

License

Notifications You must be signed in to change notification settings

alltonp/reason-detox

Repository files navigation

reason-detox

what

Reasonml/Rescript bindings for the Detox end-to-end testing framework. See here for a complete example project using this library.

why

  • you are using reason-react-native and want to write end-to-end test's without introducing js
  • you are using plain old React Native and want to try introducing Reasonml in a lightweight way

status

  • experimental but definitely usable, building blocks are there just needs a few more primitives adding

how

pre-installation

  • install detox for jest as per the standard instructions
  • ensure you can successfully run a standard detox test before continuing

installation

  1. install reason-detox
    yarn add --dev jest @glennsl/bs-jest bs-let https://github.com/alltonp/reason-detox
  2. in bsconfig.json
    1. add "@glennsl/bs-jest", "reason-detox" to "bs-dependencies"
    2. add "ppx-flags": ["bs-let/ppx"]
    3. add to "sources":
    {
      "dir": "e2e",
      "type": "dev"
    }
  3. update e2e/config.json with:
      "testRegex": "\\Test\\.bs.js$",
      "transformIgnorePatterns": [
        "node_modules/(?!(jest-)?react-native|react-(native|universal|navigation)-(.*)|@react-native-community/(.*)|@react-navigation/(.*)|bs-platform|(@[a-zA-Z]+/)?(bs|reason|rescript)-(.*)+)"
      ]
  4. that's it!

creating a test

  • save the following in e2e/firstTest.re
open Jest;
open ReasonDetox;

describe("The Test", () => {
  testPromise("example", _ => {
  
    //TIP: everything that returns a Promise must use let%Await 
    let%Await _ = expect(Id("count")) |> toHaveText("0");
    let%Await _ = tap(Text("+"));
    let%Await _ = expect(Id("count")) |> toHaveText("1");
    let%Await _ = tap(Text("-"));
    let%Await _ = expect(Id("count")) |> toHaveText("0");

    //TIP: must call this at the end to tell jest we are done, otherwise the test will run until timeout and then fail 
    Js.Promise.resolve(pass);
  })
});

run the test

  • detox test -f e2e/firstTest.bs.js

running all tests

  • detox test

About

Gray box end-to-end testing and automation library for mobile apps in Reason

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published