-
Notifications
You must be signed in to change notification settings - Fork 232
feature/RHTL-68 – server-side-rendering #510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 53 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
3841db2
chore: move current config (react-test-renderer) to src/native
joshuaellis 40991cb
change: add eslint to avoid conflict & fix lint errors
joshuaellis e3b9104
feat: migrate previous server work
joshuaellis 8b11562
merge master to branch
joshuaellis b34000e
Merge branch 'beta' into feature/RHTL-68
joshuaellis 2cd41cb
feat: add global type file
joshuaellis d34245a
change: seperate helper funcs
joshuaellis 85b9fa2
feat: add types to createRenderer & createRenderHook
joshuaellis add0639
tests: fix tests with type assertions etc.
joshuaellis 785aa5c
fix: type assertion with RenderResult
joshuaellis b553441
test: fix errorHook type error.
joshuaellis 7edd623
change: try to solve WrapperComponent PropTypes for useContext test
joshuaellis 100c77c
fix: Wrapper type was breaking with spread operator
joshuaellis b5f6ced
feat: add server engine in typescript
joshuaellis 56be770
test: get coverage to 100
joshuaellis 8d35cac
change: remove rtr act & use own written
joshuaellis a4329dd
change: use relative paths & add react-dom to renderers
joshuaellis 0e296b7
feat: add custom renderer option
joshuaellis fdfe432
feat: add dom renderer
joshuaellis af079a4
change: extract toRender to be shared
joshuaellis ec732c5
feat: add dom types
joshuaellis 53a339e
test: formatting
joshuaellis 7be2c80
change: create overload for createRenderHook
joshuaellis 9b57e0d
change: update contributors
joshuaellis cfd3df0
change: dom should be default renderer for react-dom
joshuaellis 125c327
change: add dom to files
joshuaellis ae3f2f7
change: @types/react-dom should be >=16.9.0
joshuaellis 0e73e21
change: use generic RendererOptions instead of specific to renderer
joshuaellis 48af5ce
chore(deps-dev): bump eslint from 7.16.0 to 7.17.0
dependabot[bot] 3773938
chore(refactor): moved require into getRenderer
mpeyper 19d74ce
fix: improve error message when renderer can't be auto-detected
mpeyper bad29f9
feat: remove renderer specific types from core renderHook logic
mpeyper 5730f15
change: refactor auto cleanup into a separate function
mpeyper 50cdd55
feat: added render utility support for custom renderers
mpeyper ba99b1c
fix: type catch block errors to fixe lint error
mpeyper fcc8ba3
chore: ignore lint warning for purposely skipped tests
mpeyper 9ada181
chore: removed unnecessary lint disable comment
mpeyper 81ce711
Merge pull request #522 from testing-library/dependabot/npm_and_yarn/…
joshuaellis 785afd2
feat: renderHook options are now generic based on renderer
mpeyper a1fa12f
chore: rename file without tsx exension as it no longer contains any jsx
mpeyper 511cb33
fix: refactor type names and removed some unnecessary types
mpeyper b3ccb32
fix: remove server act login and just use basic act
mpeyper 3dfbbb7
fix: ensure react types are only imported if a react renderer is used
mpeyper e1d2153
fix: separate types into folders are export types for imports
mpeyper 137f50c
fix: remove unused types, cleanup types and format all files
mpeyper 89e678c
fix: update error message when a renderer cannot be auto-detected
mpeyper 36b81c0
chore: restructure code for better readability after formatting
mpeyper 1c6b9e5
fix: remove unnecessary structures to remove need to cast in renderHook
mpeyper b936962
fix: remove duplicate type from internal types
mpeyper 080d98a
fix: simplify type of RenderHook
mpeyper 816d312
Merge pull request #1 from testing-library/feature/RHTL-68-suggestions
joshuaellis 209619d
feat: generate submodules as part of build step
mpeyper e9fa116
fix: don't wait for already resolved promise in waitForNextUpdate
mpeyper fd00043
fix: ensure submodule directory is cleaned before generating files
mpeyper 16ba7e0
chore: remove unused custom module
mpeyper 6146121
fix: minor renaming of private members
mpeyper 1970833
Merge branch 'beta'
mpeyper c9460c5
Merge branch 'master' into feature/RHTL-68
mpeyper e315dce
chore: updated all-contributors to be more accurate
mpeyper 1e2cb37
Merge branch 'master' into feature/RHTL-68
mpeyper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,5 +1,9 @@ | ||
node_modules | ||
coverage | ||
lib | ||
dom | ||
native | ||
server | ||
pure | ||
.docz | ||
site |
This file contains hidden or 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 hidden or 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,5 +1,10 @@ | ||
node_modules | ||
coverage | ||
lib | ||
dom | ||
native | ||
server | ||
pure | ||
.docz | ||
site | ||
site | ||
.vscode |
This file contains hidden or 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 hidden or 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 hidden or 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 contains hidden or 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,63 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
type Template = (submodule: string) => string | ||
|
||
const templates = { | ||
index: { | ||
'.js': (submodule: string) => `module.exports = require('../lib/${submodule}')`, | ||
'.d.ts': (submodule: string) => `export * from '../lib/${submodule}'` | ||
}, | ||
pure: { | ||
'.js': (submodule: string) => `module.exports = require('../lib/${submodule}/pure')`, | ||
'.d.ts': (submodule: string) => `export * from '../lib/${submodule}/pure'` | ||
} | ||
} | ||
|
||
const submodules = ['dom', 'native', 'server', 'pure'] | ||
|
||
function cleanDirectory(directory: string) { | ||
const files = fs.readdirSync(directory) | ||
files.forEach((file) => fs.unlinkSync(path.join(directory, file))) | ||
} | ||
|
||
function makeDirectory(submodule: string) { | ||
const submoduleDir = path.join(process.cwd(), submodule) | ||
|
||
if (fs.existsSync(submoduleDir)) { | ||
cleanDirectory(submoduleDir) | ||
} else { | ||
fs.mkdirSync(submoduleDir) | ||
} | ||
|
||
return submoduleDir | ||
} | ||
|
||
function requiredFile(submodule: string) { | ||
return ([name]: [string, unknown]) => { | ||
return name !== submodule | ||
} | ||
} | ||
|
||
function makeFile(directory: string, submodule: string) { | ||
return ([name, extensions]: [string, Record<string, Template>]) => { | ||
Object.entries(extensions).forEach(([extension, template]) => { | ||
const fileName = `${name}${extension}` | ||
console.log(` - ${fileName}`) | ||
const filePath = path.join(directory, fileName) | ||
fs.writeFileSync(filePath, template(submodule)) | ||
}) | ||
} | ||
} | ||
|
||
function makeFiles(directory: string, submodule: string) { | ||
Object.entries(templates).filter(requiredFile(submodule)).forEach(makeFile(directory, submodule)) | ||
} | ||
|
||
function createSubmodule(submodule: string) { | ||
console.log(`Generating submodule: ${submodule}`) | ||
const submoduleDir = makeDirectory(submodule) | ||
makeFiles(submoduleDir, submodule) | ||
} | ||
|
||
submodules.forEach(createSubmodule) |
This file contains hidden or 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,8 @@ | ||
{ | ||
"extends": "../tsconfig", | ||
"compilerOptions": { | ||
"declaration": false | ||
}, | ||
"exclude": [], | ||
"include": ["./**/*.ts"] | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,78 @@ | ||
import { CreateRenderer, Renderer, RenderResult, RenderHook } from '../types' | ||
import { ResultContainer, RenderHookOptions } from '../types/internal' | ||
|
||
import asyncUtils from './asyncUtils' | ||
import { cleanup, addCleanup, removeCleanup } from './cleanup' | ||
|
||
function resultContainer<TValue>(): ResultContainer<TValue> { | ||
const results: Array<{ value?: TValue; error?: Error }> = [] | ||
const resolvers: Array<() => void> = [] | ||
|
||
const result: RenderResult<TValue> = { | ||
get all() { | ||
return results.map(({ value, error }) => error ?? value) | ||
}, | ||
get current() { | ||
const { value, error } = results[results.length - 1] | ||
if (error) { | ||
throw error | ||
} | ||
return value as TValue | ||
}, | ||
get error() { | ||
const { error } = results[results.length - 1] | ||
return error | ||
} | ||
} | ||
|
||
const updateResult = (value?: TValue, error?: Error) => { | ||
results.push({ value, error }) | ||
resolvers.splice(0, resolvers.length).forEach((resolve) => resolve()) | ||
} | ||
|
||
return { | ||
result, | ||
addResolver: (resolver: () => void) => { | ||
resolvers.push(resolver) | ||
}, | ||
setValue: (value: TValue) => updateResult(value), | ||
setError: (error: Error) => updateResult(undefined, error) | ||
} | ||
} | ||
|
||
const createRenderHook = <TProps, TResult, TOptions extends {}, TRenderer extends Renderer<TProps>>( | ||
createRenderer: CreateRenderer<TProps, TResult, TOptions, TRenderer> | ||
) => ( | ||
callback: (props: TProps) => TResult, | ||
options: RenderHookOptions<TProps, TOptions> = {} as RenderHookOptions<TProps, TOptions> | ||
): RenderHook<TProps, TResult, TRenderer> => { | ||
const { result, setValue, setError, addResolver } = resultContainer<TResult>() | ||
const renderProps = { callback, setValue, setError } | ||
let hookProps = options.initialProps | ||
|
||
const { render, rerender, unmount, act, ...renderUtils } = createRenderer(renderProps, options) | ||
|
||
render(hookProps) | ||
|
||
function rerenderHook(newProps = hookProps) { | ||
hookProps = newProps | ||
rerender(hookProps) | ||
} | ||
|
||
function unmountHook() { | ||
removeCleanup(unmountHook) | ||
unmount() | ||
} | ||
|
||
addCleanup(unmountHook) | ||
|
||
return { | ||
result, | ||
rerender: rerenderHook, | ||
unmount: unmountHook, | ||
...asyncUtils(act, addResolver), | ||
...renderUtils | ||
} | ||
} | ||
|
||
export { createRenderHook, cleanup, addCleanup, removeCleanup } |
This file contains hidden or 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 { autoRegisterCleanup } from '../core/cleanup' | ||
|
||
autoRegisterCleanup() | ||
|
||
export * from './pure' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.