-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auto pkg & run react runtimes tests against auto & transform runt…
…imes (#443) * Update caniuse-lite * Add auto subpackage to signals-react * Remove auto from allowed exports until next major release * Separate and duplicate tests for runtime & transform from auto tests * Transform test files to test transform on react test files * Add note about how to test react-transform on some test files * Skip tests transform doesn't support * Fix mounting tests in SSR * Add browser and SSR tests for auto and transform react runtimes * Improve testing naming & nesting * Change ts-ignore to expect-error in test files
- Loading branch information
1 parent
76babcb
commit 020982d
Showing
20 changed files
with
309 additions
and
131 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
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.