-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move test-renderers to own package
- Loading branch information
1 parent
bffe414
commit 124a586
Showing
27 changed files
with
232 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-typescript", | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "current" | ||
} | ||
} | ||
], | ||
"@babel/preset-react" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
test/fixtures/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Atanas Stoyanov | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Table of contents | ||
|
||
# Overview | ||
|
||
A collection of test renderers for react | ||
|
||
# Installation | ||
|
||
This package is usually installed as part of the @component-controls package, but you can also install it standalone: | ||
|
||
```bash | ||
$ npm install @component-controls/test-renderers --save-dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"name": "@component-controls/test-renderers", | ||
"version": "3.4.5", | ||
"description": "React test renderers: rtl, rtr and enzyme", | ||
"keywords": [ | ||
"react", | ||
"react-testing-library", | ||
"react-test-renderer", | ||
"enzyme", | ||
"testing" | ||
], | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist/", | ||
"package.json", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"build": "yarn cross-env NODE_ENV=production rollup -c", | ||
"dev": "yarn cross-env NODE_ENV=development rollup -cw", | ||
"docs": "ts-md", | ||
"fix": "yarn lint --fix", | ||
"lint": "yarn eslint . --ext mdx,ts,tsx", | ||
"prepare": "yarn build", | ||
"test": "yarn jest --passWithNoTests" | ||
}, | ||
"homepage": "https://github.com/ccontrols/component-controls", | ||
"bugs": { | ||
"url": "https://github.com/ccontrols/component-controls/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ccontrols/component-controls.git", | ||
"directory": "core/test-renderers" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@component-controls/core": "^3.4.2", | ||
"@testing-library/jest-dom": "^5.11.4", | ||
"@testing-library/react": "^10.4.9", | ||
"@wojtekmaj/enzyme-adapter-react-17": "^0.3.1", | ||
"enzyme": "^3.11.0", | ||
"enzyme-to-json": "^3.5.0", | ||
"rc-util": "^5.0.7", | ||
"react-test-renderer": "^16.13.1" | ||
}, | ||
"devDependencies": { | ||
"@types/enzyme": "^3.10.5", | ||
"@types/react-dom": "^16.9.8", | ||
"@types/react-test-renderer": "^16.9.3", | ||
"@types/testing-library__jest-dom": "^5.9.2", | ||
"jest": "^26.4.2", | ||
"react-dom": "^16.13.1", | ||
"typescript": "^4.0.5" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"authors": [ | ||
"Atanas Stoyanov" | ||
], | ||
"jest": { | ||
"testEnvironment": "node", | ||
"preset": "ts-jest", | ||
"roots": [ | ||
"./test" | ||
] | ||
}, | ||
"gitHead": "e30d62f101e104711a16261fce04785d58cac1eb" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { config } from '../../rollup-config'; | ||
|
||
export default config({ | ||
input: ['./src/index.ts'], | ||
}); |
4 changes: 3 additions & 1 deletion
4
plugins/jest-snapshots/src/renderers.ts → core/test-renderers/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { mount, configure, ReactWrapper } from 'enzyme'; | ||
import toJson from 'enzyme-to-json'; | ||
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; | ||
import { RendererFn, RendererFnResult } from '../types'; | ||
|
||
configure({ adapter: new Adapter() }); | ||
|
||
export const render: RendererFn = async ( | ||
{ story, doc, config }, | ||
options?: any, | ||
): Promise<(RendererFnResult & Partial<ReactWrapper>) | undefined> => { | ||
const renderFn = config.renderFn; | ||
if (renderFn) { | ||
const rendered = renderFn(story, doc, config); | ||
const component = mount(rendered, options); | ||
return { | ||
toJson: () => toJson(component, { mode: 'deep' }), | ||
...component, | ||
}; | ||
} | ||
return undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import renderer from 'react-test-renderer'; | ||
import { RendererFn, RendererFnResult, Json } from '../types'; | ||
|
||
export const render: RendererFn = async ( | ||
{ story, doc, config }, | ||
options, | ||
): Promise<(RendererFnResult & renderer.ReactTestRenderer) | undefined> => { | ||
const renderFn = config.renderFn; | ||
if (renderFn) { | ||
const rendered = renderFn(story, doc, config); | ||
const component = renderer.create(rendered, options); | ||
return { toJson: () => component.toJSON() as Json, ...component }; | ||
} | ||
return undefined; | ||
}; |
18 changes: 18 additions & 0 deletions
18
core/test-renderers/src/renderers/react-testing-library.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { render as rtlRender, RenderResult } from '@testing-library/react'; | ||
import { RendererFn, RendererFnResult } from '../types'; | ||
|
||
export const render: RendererFn = async ( | ||
{ story, doc, config }, | ||
options?: any, | ||
): Promise<(RendererFnResult & RenderResult) | undefined> => { | ||
const renderFn = config.renderFn; | ||
if (renderFn) { | ||
const rendered = renderFn(story, doc, config); | ||
const results = rtlRender(rendered, options); | ||
return { | ||
toJson: () => results.asFragment(), | ||
...results, | ||
}; | ||
} | ||
return undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Story, Document, RunConfiguration } from '@component-controls/core'; | ||
|
||
export type Json = | ||
| { | ||
type: string; | ||
props?: { [key: string]: any }; | ||
children: Array<Json> | null; | ||
} | ||
| DocumentFragment; | ||
|
||
export type RendererFnResult = { | ||
toJson: () => Json | null; | ||
}; | ||
|
||
export type RendererFn = ( | ||
props: { story: Story; doc: Document; config: RunConfiguration }, | ||
options?: any, | ||
) => Promise<RendererFnResult | undefined>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"declaration": true, | ||
"types": ["node", "jest"], | ||
"typeRoots": ["../../node_modules/@types", "node_modules/@types"] | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules/**", "test/**"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
import { config } from '../../rollup-config'; | ||
|
||
export default config({ | ||
input: [ | ||
'./src/index.ts', | ||
'./src/cli.ts', | ||
'./src/args.ts', | ||
'./src/renderers.ts', | ||
], | ||
input: ['./src/index.ts', './src/cli.ts', './src/args.ts'], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.