-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Add auto pkg & run react runtimes tests against auto & transform runtimes #443
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
948e025
Update caniuse-lite
andrewiggins 1e1c94a
Add auto subpackage to signals-react
andrewiggins a1fca5e
Remove auto from allowed exports until next major release
andrewiggins 0e9f97d
Separate and duplicate tests for runtime & transform from auto tests
andrewiggins 9437403
Transform test files to test transform on react test files
andrewiggins f86cd73
Add note about how to test react-transform on some test files
andrewiggins 12bd862
Skip tests transform doesn't support
andrewiggins cfdc1a9
Fix mounting tests in SSR
andrewiggins 1304470
Add browser and SSR tests for auto and transform react runtimes
andrewiggins aa7ea2c
Improve testing naming & nesting
andrewiggins 907e043
Change ts-ignore to expect-error in test files
andrewiggins 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 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 @@ | ||
--- | ||
"@preact/signals-react": patch | ||
--- | ||
|
||
Setup internal infrastructure for upcoming major change |
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 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,25 @@ | ||
{ | ||
"name": "@preact/signals-react-auto", | ||
"description": "Sub package for @preact/signals-react that patches React to automatically update when signals change", | ||
"private": true, | ||
"amdName": "reactSignalsAuto", | ||
"main": "dist/auto.js", | ||
"module": "dist/auto.module.js", | ||
"unpkg": "dist/auto.min.js", | ||
"types": "dist/index.d.ts", | ||
"mangle": "../../../mangle.json", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"browser": "./dist/auto.module.js", | ||
"import": "./dist/auto.mjs", | ||
"require": "./dist/auto.js" | ||
} | ||
}, | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"@preact/signals-core": "workspace:^1.3.0", | ||
"@preact/signals-react": "workspace:*", | ||
"react": "^16.14.0 || 17.x || 18.x" | ||
} | ||
} |
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 @@ | ||
import { installAutoSignalTracking } from "@preact/signals-react/runtime"; | ||
installAutoSignalTracking(); |
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,42 @@ | ||
// @ts-expect-error | ||
globalThis.IS_REACT_ACT_ENVIRONMENT = true; | ||
|
||
import { mountSignalsTests } from "../../../test/shared/mounting"; | ||
import { | ||
act, | ||
getConsoleErrorSpy, | ||
checkConsoleErrorLogs, | ||
createRoot, | ||
type Root, | ||
} from "../../../test/shared/utils.js"; | ||
|
||
import "@preact/signals-react/auto"; | ||
|
||
describe("@preact/signals-react/auto", () => { | ||
describe("mounting", () => { | ||
let scratch: HTMLDivElement; | ||
let root: Root; | ||
|
||
async function render(element: JSX.Element): Promise<string> { | ||
await act(() => { | ||
root.render(element); | ||
}); | ||
return scratch.innerHTML; | ||
} | ||
|
||
beforeEach(async () => { | ||
scratch = document.createElement("div"); | ||
document.body.appendChild(scratch); | ||
getConsoleErrorSpy().resetHistory(); | ||
|
||
root = await createRoot(scratch); | ||
}); | ||
|
||
afterEach(async () => { | ||
scratch.remove(); | ||
checkConsoleErrorLogs(); | ||
}); | ||
|
||
mountSignalsTests(render); | ||
}); | ||
}); |
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,12 @@ | ||
// @ts-expect-error | ||
globalThis.IS_REACT_ACT_ENVIRONMENT = true; | ||
|
||
import { updateSignalsTests } from "../../../test/shared/updates"; | ||
import "@preact/signals-react/auto"; | ||
|
||
describe("@preact/signals-react/auto", () => { | ||
describe("updating", () => { | ||
// calledOnce | ||
updateSignalsTests(); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/react/auto/test/node/renderToStaticMarkup.test.tsx
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,24 @@ | ||
import { signal, useSignalEffect } from "@preact/signals-react"; | ||
import { createElement } from "react"; | ||
import { renderToStaticMarkup } from "react-dom/server"; | ||
import { mountSignalsTests } from "../../../test/shared/mounting"; | ||
|
||
describe("@preact/signals-react/auto", () => { | ||
describe("renderToStaticMarkup", () => { | ||
mountSignalsTests(el => Promise.resolve(renderToStaticMarkup(el))); | ||
|
||
it("should not invoke useSignalEffect", async () => { | ||
const spy = sinon.spy(); | ||
const sig = signal("foo"); | ||
|
||
function App() { | ||
useSignalEffect(() => spy(sig.value)); | ||
return <p>{sig.value}</p>; | ||
} | ||
|
||
const html = await renderToStaticMarkup(<App />); | ||
expect(html).to.equal("<p>foo</p>"); | ||
expect(spy.called).to.be.false; | ||
}); | ||
}); | ||
}); |
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,40 @@ | ||
// @ts-expect-error | ||
globalThis.IS_REACT_ACT_ENVIRONMENT = true; | ||
|
||
import { mountSignalsTests } from "../../../test/shared/mounting"; | ||
import { | ||
act, | ||
getConsoleErrorSpy, | ||
checkConsoleErrorLogs, | ||
createRoot, | ||
type Root, | ||
} from "../../../test/shared/utils.js"; | ||
|
||
describe("@preact/signals-react/runtime", () => { | ||
describe("mounting", () => { | ||
let scratch: HTMLDivElement; | ||
let root: Root; | ||
|
||
async function render(element: JSX.Element): Promise<string> { | ||
await act(() => { | ||
root.render(element); | ||
}); | ||
return scratch.innerHTML; | ||
} | ||
|
||
beforeEach(async () => { | ||
scratch = document.createElement("div"); | ||
document.body.appendChild(scratch); | ||
getConsoleErrorSpy().resetHistory(); | ||
|
||
root = await createRoot(scratch); | ||
}); | ||
|
||
afterEach(async () => { | ||
scratch.remove(); | ||
checkConsoleErrorLogs(); | ||
}); | ||
|
||
mountSignalsTests(render); | ||
}); | ||
}); |
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,10 @@ | ||
// @ts-expect-error | ||
globalThis.IS_REACT_ACT_ENVIRONMENT = true; | ||
|
||
import { updateSignalsTests } from "../../../test/shared/updates"; | ||
|
||
describe("@preact/signals-react/runtime", () => { | ||
describe("updating", () => { | ||
updateSignalsTests(true); | ||
}); | ||
}); |
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
24 changes: 24 additions & 0 deletions
24
packages/react/runtime/test/node/renderToStaticMarkup.test.tsx
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,24 @@ | ||
import { signal, useSignalEffect } from "@preact/signals-react"; | ||
import { createElement } from "react"; | ||
import { renderToStaticMarkup } from "react-dom/server"; | ||
import { mountSignalsTests } from "../../../test/shared/mounting"; | ||
|
||
describe("@preact/signals-react/runtime", () => { | ||
describe("renderToStaticMarkup", () => { | ||
mountSignalsTests(el => Promise.resolve(renderToStaticMarkup(el))); | ||
|
||
it("should not invoke useSignalEffect", async () => { | ||
const spy = sinon.spy(); | ||
const sig = signal("foo"); | ||
|
||
function App() { | ||
useSignalEffect(() => spy(sig.value)); | ||
return <p>{sig.value}</p>; | ||
} | ||
|
||
const html = await renderToStaticMarkup(<App />); | ||
expect(html).to.equal("<p>foo</p>"); | ||
expect(spy.called).to.be.false; | ||
}); | ||
}); | ||
}); |
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 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 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This double import caused some duplicate code in the final bundle. Combining them is what caused this PR to reduce the overall bundle size shown in the size-bot comment.