Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze committed Apr 13, 2017
0 parents commit 3b87107
Show file tree
Hide file tree
Showing 16 changed files with 3,648 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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
*.js text eol=lf
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dependencies
node_modules

# Build
lib
.merlin

# Logs
*.log

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

language: node_js

node_js:
- 7
- 6
- 4

cache:
directories:
- $HOME/.cache
26 changes: 26 additions & 0 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "bs-react-test-renderer",
"reason": {
"react-jsx": true
},
"bs-dependencies": [
"reason-react"
],
"bs-dev-dependencies": [
"bs-jest"
],
"sources": [
{
"dir": "src",
"subdirs": [
{
"dir": "__tests__",
"subdirs": [
"fixtures"
],
"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
21 changes: 21 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Neil Kistner <neil.kistner@gmail.com> (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.
52 changes: 52 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "bs-react-test-renderer",
"version": "0.0.0",
"description": "BuckleScript bindings for react-test-renderer.",
"repository": "BuckleTypes/bs-react-test-renderer",
"author": {
"name": "Neil Kistner",
"email": "neil.kistner@gmail.com",
"url": "neilkistner.com"
},
"license": "MIT",
"files": [
"src/*.re",
"bsconfig.json"
],
"scripts": {
"build": "bsb -make-world",
"changelog": "changelog-maker --filter-release -- BuckleTypes bs-react-test-renderer",
"clean": "npm-run-all clean:*",
"clean:bsb": "bsb -clean-world",
"clean:project": "rimraf lib .merlin",
"jest": "jest",
"prebuild": "npm run clean",
"test": "npm-run-all build jest",
"version": "node scripts/version.js"
},
"dependencies": {
"react-test-renderer": "^15.5.4"
},
"peerDependencies": {
"reason-react": "^0.1.0"
},
"devDependencies": {
"bs-jest": "git+https://github.com/BuckleTypes/bs-jest.git",
"bs-platform": "git+https://github.com/bloomberg/bucklescript.git",
"changelog-maker": "^2.2.5",
"execa": "^0.6.3",
"jest": "^19.0.2",
"np": "^2.13.1",
"npm-run-all": "^4.0.2",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"read-pkg": "^2.0.0",
"reason-react": "^0.1.0",
"rimraf": "^2.6.1"
},
"jest": {
"testPathIgnorePatterns": [
"fixtures"
]
}
}
95 changes: 95 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# bs-react-test-renderer

[![Build Status][travis-image]][travis-url]
[![npm][npm-image]][npm-url]
[![dependencies][deps-image]][deps-url]
[![devDependencies][depsdev-image]][depsdev-url]

> [BuckleScript](//github.com/bloomberg/bucklescript) bindings for [react-test-renderer](//github.com/facebook/react/tree/master/packages/react-test-renderer).
## Installation

```sh
$ yarn add --dev bs-react-test-renderer

# or..

$ npm install --save-dev bs-react-test-renderer
```

## Usage

#### Add to `bsconfig.json`

```json
{
"bs-dev-dependencies": [
"bs-react-test-renderer"
]
}
```

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

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

## Examples

See [`src/__tests__`](//github.com/BuckleTypes/bs-react-test-renderer/tree/master/src/__tests__) for some examples.

For examples with Snapshot testing with [`bs-jest`](//github.com/BuckleTypes/bs-jest), see [`reason-calculator`](//github.com/wyze/reason-calculator).

## Development

```sh
$ git clone https://github.com/BuckleTypes/bs-react-test-renderer.git
$ cd bs-react-test-renderer
$ 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/BuckleTypes/bs-react-test-renderer.svg?style=flat-square
[travis-url]: https://travis-ci.org/BuckleTypes/bs-react-test-renderer

[npm-image]: https://img.shields.io/npm/v/bs-react-test-renderer.svg?style=flat-square
[npm-url]: https://npm.im/bs-react-test-renderer

[deps-image]: https://img.shields.io/david/BuckleTypes/bs-react-test-renderer.svg?style=flat-square
[deps-url]: https://david-dm.org/BuckleTypes/bs-react-test-renderer

[depsdev-image]: https://img.shields.io/david/dev/BuckleTypes/bs-react-test-renderer.svg?style=flat-square
[depsdev-url]: https://david-dm.org/BuckleTypes/bs-react-test-renderer?type=dev
67 changes: 67 additions & 0 deletions scripts/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const execa = require('execa')
const readFile = require('fs').readFileSync
const readPkg = require('read-pkg')
const writeFile = require('fs').writeFileSync

// get version from pkg.json
const getVersionAndUrl =
({ repository: { url }, version }) => ({ url, version })

// npm run changelog (and grab output)
const getChanges = ({ url, version }) => {
const { stdout } = execa.sync('npm', [ 'run', 'changelog', '--silent' ])
const changes = stdout.trim().split(' \n')

return { changes, url, version }
}

// modify changelog.md
const updateChangelog = ({ changes, url, version }) => {
const file = 'changelog.md'
const changelog = readFile(file).toString().split('\n')
const date = new Date().toJSON().split('T').shift()
const tag = `v${version}`
const repo = url.replace(/\.?git(?!hub)\+?/g, '')
const header = `### [${tag}](${repo}/releases/tag/${tag}) (${date})`
const formatted = [ header, '', ...changes ]

writeFile(
file,
[
...changelog.slice(0, 2),
...formatted,
...changelog.slice(1),
].join('\n')
)

return formatted
}

// modify readme.md
const updateReadme = formatted => {
const file = 'readme.md'
const readme = readFile(file).toString().split('\n')
const start = '> [Full Change Log](changelog.md)'
const end = '## License'

writeFile(
file,
[
...readme.slice(0, readme.indexOf(start) + 2),
...formatted,
...readme.slice(readme.indexOf(end) - 1),
].join('\n')
)
}

// git add
const runGitAdd = () => {
execa.sync('git', [ 'add', '--all' ])
}

readPkg()
.then(getVersionAndUrl)
.then(getChanges)
.then(updateChangelog)
.then(updateReadme)
.then(runGitAdd)
15 changes: 15 additions & 0 deletions src/ReactShallowRenderer.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type t;

external createRenderer :
unit => t = "" [@@bs.val] [@@bs.module "react-test-renderer/shallow"];

external render :
t => ReactRe.reactElement => option ReactRe.reactElement = "" [@@bs.send];

external getRenderOutput :
t => option ReactRe.reactElement = "" [@@bs.send];

external unmount :
t => unit = "" [@@bs.send];

let renderWithRenderer = render (createRenderer ());
7 changes: 7 additions & 0 deletions src/ReactTestRenderer.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type t;

external create :
ReactRe.reactElement => t = "" [@@bs.val] [@@bs.module "react-test-renderer"];

external toJSON :
t => Js.Json.t = "" [@@bs.send];
Loading

0 comments on commit 3b87107

Please sign in to comment.