Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6d132bd

Browse files
Make changes to support figbuild
The built version of this library that is downloaded when you run `npm install @testing-library/react-hooks` contains a few features that are not supported by `figbuild`. This forked version makes the following changes: - Output code that `figbuild` is set up to process. This was accomplished by adding a `.browserslistrc` file that lists IE 11 as a supported browser. While we don't actually support IE 11, this does mean the build won't try to use any fancy new language features. - Build with the `--bundle` option. This causes the build script to use Rollup to generate a single script file, instead of separate ES6 modules. This is also required to make the build script care about the `.browserslistrc` file. - Update the `main` and `types` fields of `package.json`. The `--bundle` option places the built file in a different location, under `dist` and with a new filename. - Update `tsconfig.json` to use an `ES5` target. I'm not sure if this does anything, since we're using Babel to build, not Typescript. But whatever, it can't hurt. - Remove "smart" dynamic `require` logic to [choose a renderer](https://react-hooks-testing-library.com/installation#renderer). `figbuild` does not support dynamic `require` statements. I also deleted tests for this logic. - Remove submodules structure. Since we're no longer doing dynamic requires, we also don't need to output `@testing-library/react-hooks/dom` and similar directories. If and when we move off of `figbuild`, we may be able to un-fork this library.
1 parent eff2ca6 commit 6d132bd

File tree

9 files changed

+50
-111
lines changed

9 files changed

+50
-111
lines changed

‎.browserslistrc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IE 11

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
node_modules
33

44
# build generated
5+
dist
56
lib
67
dom
78
native

‎README.md‎

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,29 @@
1919

2020
<hr />
2121

22-
<!-- prettier-ignore-start -->
23-
[![Build Status](https://img.shields.io/github/workflow/status/testing-library/react-hooks-testing-library/validate?logo=github&style=flat-square)](https://github.com/testing-library/react-hooks-testing-library/actions?query=workflow%3Avalidate)
24-
[![codecov](https://img.shields.io/codecov/c/github/testing-library/react-hooks-testing-library.svg?style=flat-square)](https://codecov.io/gh/testing-library/react-hooks-testing-library)
25-
[![version](https://img.shields.io/npm/v/@testing-library/react-hooks.svg?style=flat-square)](https://www.npmjs.com/package/@testing-library/react-hooks)
26-
[![downloads](https://img.shields.io/npm/dm/@testing-library/react-hooks.svg?style=flat-square)](http://www.npmtrends.com/@testing-library/react-hooks)
27-
[![MIT License](https://img.shields.io/npm/l/@testing-library/react-hooks.svg?style=flat-square)](https://github.com/testing-library/react-hooks-testing-library/blob/main/LICENSE.md)
28-
29-
[![All Contributors](https://img.shields.io/github/all-contributors/testing-library/react-hooks-testing-library?color=orange&style=flat-square)](#contributors)
30-
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
31-
[![Code of Conduct](https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square)](https://github.com/testing-library/react-hooks-testing-library/blob/main/CODE_OF_CONDUCT.md)
32-
[![Netlify Status](https://api.netlify.com/api/v1/badges/9a8f27a5-df38-4910-a248-4908b1ba29a7/deploy-status)](https://app.netlify.com/sites/react-hooks-testing-library/deploys)
33-
[![Discord](https://img.shields.io/discord/723559267868737556.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square)](https://discord.gg/testing-library)
34-
35-
[![Watch on GitHub](https://img.shields.io/github/watchers/testing-library/react-hooks-testing-library.svg?style=social)](https://github.com/testing-library/react-hooks-testing-library/watchers)
36-
[![Star on GitHub](https://img.shields.io/github/stars/testing-library/react-hooks-testing-library.svg?style=social)](https://github.com/testing-library/react-hooks-testing-library/stargazers)
37-
[![Tweet](https://img.shields.io/twitter/url/https/github.com/testing-library/react-hooks-testing-library.svg?style=social)](https://twitter.com/intent/tweet?text=Check%20out%20react-hooks-testing-library%20by%20%40testing-library%20https%3A%2F%2Fgithub.com%2Ftesting-library%2Freact-hooks-testing-library%20%F0%9F%91%8D)
38-
<!-- prettier-ignore-end -->
22+
## Why did we fork this?
23+
24+
The built version of this library that is downloaded when you run
25+
`npm install @testing-library/react-hooks` contains a few features that are not supported by
26+
`figbuild`. **This forked version makes the following changes:**
27+
28+
- Output code that `figbuild` is set up to process. This was accomplished by adding a
29+
`.browserslistrc` file that lists IE 11 as a supported browser. While we don't actually support IE
30+
11, this does mean the build won't try to use any fancy new language features.
31+
- Build with the `--bundle` option. This causes the build script to use Rollup to generate a single
32+
script file, instead of separate ES6 modules. This is also required to make the build script care
33+
about the `.browserslistrc` file.
34+
- Update the `main` and `types` fields of `package.json`. The `--bundle` option places the built
35+
file in a different location, under `dist` and with a new filename.
36+
- Update `tsconfig.json` to use an `ES5` target. I'm not sure if this does anything, since we're
37+
using Babel to build, not Typescript. But whatever, it can't hurt.
38+
- Remove "smart" dynamic `require` logic to
39+
[choose a renderer](https://react-hooks-testing-library.com/installation#renderer). `figbuild`
40+
does not support dynamic `require` statements. I also deleted tests for this logic.
41+
- Remove submodules structure. Since we're no longer doing dynamic requires, we also don't need to
42+
output `@testing-library/react-hooks/dom` and similar directories.
43+
44+
If and when we move off of `figbuild`, we may be able to un-fork this library.
3945

4046
## Table of Contents
4147

‎package.json‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "@testing-library/react-hooks",
2+
"name": "@figma/testing-library-react-hooks",
33
"version": "0.0.0-semantically-released",
44
"description": "Simple and complete React hooks testing utilities that encourage good testing practices.",
5-
"main": "lib/index.js",
6-
"types": "lib/index.d.ts",
5+
"main": "dist/@figma/testing-library-react-hooks.cjs.js",
6+
"types": "dist/index.d.ts",
77
"engines": {
88
"node": ">=12"
99
},
@@ -15,6 +15,7 @@
1515
"integration"
1616
],
1717
"files": [
18+
"dist",
1819
"lib",
1920
"src",
2021
"dom",
@@ -27,15 +28,14 @@
2728
"author": "Michael Peyper <mpeyper7@gmail.com>",
2829
"repository": {
2930
"type": "git",
30-
"url": "https://github.com/testing-library/react-hooks-testing-library.git"
31+
"url": "https://github.com/figma/react-hooks-testing-library.git"
3132
},
3233
"license": "MIT",
3334
"scripts": {
3435
"setup": "npm install && npm run validate -s",
3536
"validate": "kcd-scripts validate",
3637
"prepare": "npm run build",
37-
"build": "kcd-scripts build --out-dir lib && npm run generate:submodules",
38-
"generate:submodules": "ts-node scripts/generate-submodules.ts",
38+
"build": "kcd-scripts build --bundle",
3939
"test": "kcd-scripts test",
4040
"typecheck": "kcd-scripts typecheck",
4141
"lint": "kcd-scripts lint",

‎scripts/tsconfig.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "../tsconfig",
33
"compilerOptions": {
4-
"declaration": false
4+
"declaration": false,
5+
"target": "ES5"
56
},
67
"exclude": [],
78
"include": ["./**/*.ts"]

‎src/__tests__/defaultRenderer.pure.test.ts‎

Lines changed: 0 additions & 41 deletions
This file was deleted.

‎src/__tests__/defaultRenderer.test.ts‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎src/pure.ts‎

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,15 @@
1-
import { ReactHooksRenderer } from './types/react'
2-
3-
const renderers = [
4-
{ required: 'react-test-renderer', renderer: './native/pure' },
5-
{ required: 'react-dom', renderer: './dom/pure' }
6-
]
7-
8-
function hasDependency(name: string) {
9-
try {
10-
require(name)
11-
return true
12-
} catch {
13-
return false
14-
}
15-
}
16-
17-
function getRenderer() {
18-
const validRenderer = renderers.find(({ required }) => hasDependency(required))
19-
20-
if (validRenderer) {
21-
// eslint-disable-next-line @typescript-eslint/no-var-requires
22-
return require(validRenderer.renderer) as ReactHooksRenderer
23-
} else {
24-
const options = renderers
25-
.map(({ required }) => ` - ${required}`)
26-
.sort((a, b) => a.localeCompare(b))
27-
.join('\n')
28-
29-
throw new Error(
30-
`Could not auto-detect a React renderer. Are you sure you've installed one of the following\n${options}\nIf you are using a bundler, please update your imports to use a specific renderer.\nFor instructions see: https://react-hooks-testing-library.com/installation#being-specific`
31-
)
32-
}
33-
}
34-
35-
const { renderHook, act, cleanup, addCleanup, removeCleanup, suppressErrorOutput } = getRenderer()
36-
37-
export { renderHook, act, cleanup, addCleanup, removeCleanup, suppressErrorOutput }
1+
// This file normally contains logic for selecting which renderer to use.
2+
// This uses dynamic require statements, which are not supported by `figbuild`.
3+
// Instead, I've hard-coded it to always use the DOM renderer, since we use Jasmine
4+
// and run our unit tests in the browser.
5+
6+
export {
7+
renderHook,
8+
act,
9+
cleanup,
10+
addCleanup,
11+
removeCleanup,
12+
suppressErrorOutput
13+
} from './dom/pure'
3814

3915
export * from './types/react'

‎tsconfig.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"extends": "./node_modules/kcd-scripts/shared-tsconfig.json",
33
"compilerOptions": {
4-
"target": "ES6"
4+
"target": "ES5",
5+
"module": "commonjs",
6+
"isolatedModules": true,
7+
"moduleResolution": "node"
58
}
69
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /