Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze committed Jun 5, 2018
0 parents commit 7dd8119
Show file tree
Hide file tree
Showing 14 changed files with 4,200 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto
*.js text eol=lf
*.re linguist-language=OCaml
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Dependencies
node_modules

# Build
coverage
src/**/*.bs.js
lib
.bsb.lock
.merlin

# Logs
*.log

# macOS
.*DS_Store
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sudo: false

language: node_js

node_js:
- 10
- 8

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH="$HOME/.yarn/bin:$PATH"

cache:
yarn: true
directories:
- $HOME/.cache
- node_modules
34 changes: 34 additions & 0 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "bs-react-testing-library",
"bsc-flags": [
"-bs-no-version-header",
"-bs-super-errors"
],
"reason": {
"react-jsx": 2
},
"refmt": 3,
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
"bs-dom-testing-library",
"reason-react"
],
"bs-dev-dependencies": [
"bs-jest"
],
"sources": [
{
"dir": "src",
"subdirs": [
{
"dir": "__tests__",
"type": "dev"
}
]
}
]
}
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Change Log
9 changes: 9 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) Neil Kistner <[email protected]> (neilkistner.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49 changes: 49 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "bs-react-testing-library",
"version": "0.0.0",
"description": "BuckleScript bindings for react-testing-library.",
"repository": "wyze/bs-react-testing-library",
"author": {
"name": "Neil Kistner",
"email": "[email protected]",
"url": "neilkistner.com"
},
"license": "MIT",
"files": [
"src/*.re",
"src/*.rei",
"bsconfig.json"
],
"scripts": {
"build": "bsb -make-world",
"clean": "run-p clean:*",
"clean:bsb": "bsb -clean-world",
"clean:project": "rimraf lib .merlin",
"jest": "jest",
"prebuild": "yarn clean",
"pretest": "yarn build",
"test": "yarn jest",
"version": "write-changelog"
},
"keywords": [
"bucklescript",
"testing"
],
"dependencies": {
"bs-dom-testing-library": "^0.1.0",
"react-testing-library": "^3.1.3"
},
"peerDependencies": {
"reason-react": "^0.4.0 || ^0.3.0"
},
"devDependencies": {
"bs-jest": "^0.3.2",
"bs-platform": "^3.1.5",
"npm-run-all": "^4.1.3",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"reason-react": "^0.4.2",
"rimraf": "^2.6.2",
"write-changelog": "^1.1.0"
}
}
84 changes: 84 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# bs-react-testing-library

[![Build Status][travis-image]][travis-url]
[![npm][npm-image]][npm-url]

> [BuckleScript](//github.com/BuckleScript/bucklescript) bindings for [react-testing-library](//github.com/kentcdodds/react-testing-library).
## Installation

```sh
$ yarn add --dev bs-react-testing-library

# or..

$ npm install --save-dev bs-react-testing-library
```

## Usage

#### Add to `bsconfig.json`

```json
{
"bs-dev-dependencies": [
"bs-react-testing-library"
]
}
```

#### With [`bs-jest`](//github.com/reasonml-community/bs-jest)

```ocaml
/* Component_test.re */
open Jest;
describe("Component", () => {
open ExpectJs;
test("renders", () => {
let component = ReactShallowRenderer.renderWithRenderer(<Component />);
expect(Js.Undefined.return(component)) |> toBeDefined;
});
});
```

## Examples

See [`src/__tests__`](src/__tests__) for some examples.

## Development

```sh
$ git clone https://github.com/wyze/bs-react-testing-library.git
$ cd bs-react-testing-library
$ yarn # or `npm install`
```

## Build

```sh
$ yarn build
```

## Test

```sh
$ yarn test
```

## Change Log

> [Full Change Log](changelog.md)
## License

MIT © [Neil Kistner](https://neilkistner.com)

[travis-image]: https://img.shields.io/travis/wyze/bs-react-testing-library.svg?style=flat-square
[travis-url]: https://travis-ci.org/wyze/bs-react-testing-library

[npm-image]: https://img.shields.io/npm/v/bs-react-testing-library.svg?style=flat-square
[npm-url]: https://npm.im/bs-react-testing-library
33 changes: 33 additions & 0 deletions src/ReactTestingLibrary.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include DomTestingLibrary;

module Simulate = {
[@bs.module "react-testing-library"] [@bs.scope "Simulate"]
external click : Dom.element => unit = "";
};

type renderResult;
type renderOptions = {
.
"container": Js.undefined(Dom.element),
};

[@bs.module "react-testing-library"]
external cleanup : unit => unit = "";

[@bs.module "react-testing-library"]
external renderIntoDocument : ReasonReact.reactElement => renderResult = "";

[@bs.module "react-testing-library"]
external _render : (ReasonReact.reactElement, renderOptions) => renderResult = "render";

[@bs.get] external container : renderResult => Dom.element = "";

[@bs.send.pipe : renderResult] external debug : unit = "";

[@bs.send.pipe : renderResult] external unmount : unit => bool = "";

[@bs.send.pipe : renderResult] external rerender : ReasonReact.reactElement => unit = "";

let render = (~container=?, element) =>
_render(element, { "container": Js.Undefined.fromOption(container) });

59 changes: 59 additions & 0 deletions src/ReactTestingLibrary.rei
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module Query = DomTestingLibrary.Query;
module Wait = DomTestingLibrary.Wait;
module WaitForElement = DomTestingLibrary.WaitForElement;

let wait:
(~callback: unit => unit=?, ~options: Wait.options=?, unit) =>
Js.Promise.t('a);

let waitForElement:
(~callback: unit => 'a=?, ~options: WaitForElement.options=?, unit) =>
Js.Promise.t('a);

let prettyDOM: (~maxLength: int=?, Dom.element) => string;

[@bs.module "dom-testing-library"]
external getNodeText : Dom.element => string = "";

let getByTestId: (string, Dom.element) => Dom.element;

let getByText:
(
~matcher: [
| `Func((string, Dom.element) => bool)
| `RegExp(Js.Re.t)
| `Str(string)
],
~options: Query.options=?,
Dom.element
) =>
Dom.element;

module Simulate: {
[@bs.module "react-testing-library"] [@bs.scope "Simulate"]
external click : Dom.element => unit = "";
};

type renderResult;
type renderOptions = {. "container": Js.undefined(Dom.element)};

[@bs.module "react-testing-library"]
external cleanup : unit => unit = "";

[@bs.module "react-testing-library"]
external renderIntoDocument : ReasonReact.reactElement => renderResult = "";

[@bs.get]
external container : renderResult => Dom.element = "";

[@bs.send.pipe : renderResult]
external debug : unit = "";

[@bs.send.pipe : renderResult]
external unmount : unit => bool = "";

[@bs.send.pipe : renderResult]
external rerender : ReasonReact.reactElement => unit = "";

let render:
(~container: Dom.element=?, ReasonReact.reactElement) => renderResult;
Loading

0 comments on commit 7dd8119

Please sign in to comment.