acrylblends 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/docs/framework/README.md +2 -2
- package/docs/framework/UPSTREAM.md +1 -1
- package/docs/framework/guides/jsx.md +24 -0
- package/docs/framework/helpers/ssg.md +3 -6
- package/docs/framework/middleware/builtin/jsx-renderer.md +0 -3
- package/docs/framework/upstream.json +2 -2
- package/lib/accepts.d.ts +1 -1
- package/lib/acryl-base.d.ts +1 -1
- package/lib/adapter.d.ts +1 -1
- package/lib/{app-wFwpg-bt.d.ts → app-D8riatvv.d.ts} +1 -1
- package/lib/basic-auth.d.ts +1 -1
- package/lib/bearer-auth.d.ts +1 -1
- package/lib/body-limit.d.ts +1 -1
- package/lib/cache.d.ts +1 -1
- package/lib/cache.js +4 -4
- package/lib/{client-BHTr318g.js → client-DDLXwhBo.js} +2 -125
- package/lib/client.d.ts +2 -2
- package/lib/client.js +2 -1
- package/lib/combine.d.ts +1 -1
- package/lib/{components-Ce5FRyHU.js → components-0o0CBYNv.js} +2 -2
- package/lib/{components-DYZdxJIJ.js → components-DdI7-ns7.js} +1 -1
- package/lib/compress.d.ts +1 -1
- package/lib/conninfo.d.ts +2 -2
- package/lib/{context-DVQBjuns.d.ts → context-DS3fYyG-.d.ts} +1 -1
- package/lib/context-storage.d.ts +1 -1
- package/lib/cookie.d.ts +1 -1
- package/lib/cors.d.ts +1 -1
- package/lib/csrf.d.ts +1 -1
- package/lib/dev.d.ts +2 -2
- package/lib/etag.d.ts +1 -1
- package/lib/factory.d.ts +2 -2
- package/lib/{hooks-Bq5q9IMl.js → hooks-BMw6BAyP.js} +5 -5
- package/lib/{index-CUTfU69R.d.ts → index-Bb7YJKCq.d.ts} +2 -2
- package/lib/{index-CsvB-F9j.d.ts → index-BvFh1Gfx.d.ts} +1 -1
- package/lib/{index-Cqcdluyn.d.ts → index-CTy4N7ng.d.ts} +2 -2
- package/lib/index.d.ts +4 -4
- package/lib/ip-restriction.d.ts +2 -2
- package/lib/jsx/dom/client.js +1 -1
- package/lib/jsx/dom/jsx-dev-runtime.js +1 -1
- package/lib/jsx/dom/jsx-runtime.js +1 -1
- package/lib/jsx/dom/server.js +1 -1
- package/lib/jsx/dom.js +3 -3
- package/lib/jsx/streaming.js +1 -1
- package/lib/{jsx-dev-runtime-kAhR_4C7.js → jsx-dev-runtime-D18Y35TI.js} +1 -1
- package/lib/jsx-renderer.d.ts +75 -0
- package/lib/jsx-renderer.js +99 -0
- package/lib/jsx.js +3 -3
- package/lib/jwk.d.ts +1 -1
- package/lib/jwt.d.ts +1 -1
- package/lib/language.d.ts +1 -1
- package/lib/logger.d.ts +1 -1
- package/lib/loopback-only.d.ts +1 -1
- package/lib/method-not-allowed.d.ts +2 -2
- package/lib/method-override.d.ts +2 -2
- package/lib/mount.d.ts +1 -1
- package/lib/node-server/conninfo.d.ts +1 -1
- package/lib/node-server/serve-static.d.ts +1 -1
- package/lib/node-server/serve-static.js +1 -1
- package/lib/node-server.d.ts +1 -1
- package/lib/node-server.js +1 -1
- package/lib/powered-by.d.ts +1 -1
- package/lib/pretty-json.d.ts +1 -1
- package/lib/quick.d.ts +1 -1
- package/lib/request-id.d.ts +1 -1
- package/lib/request.d.ts +1 -1
- package/lib/route.d.ts +1 -1
- package/lib/schema-validator.d.ts +1 -1
- package/lib/secure-headers.d.ts +1 -1
- package/lib/{serve-static-Cw23shXv.js → serve-static-B14MF1Va.js} +1 -0
- package/lib/serve-static.d.ts +1 -1
- package/lib/ssg-BwjcA-Ge.js +389 -0
- package/lib/ssg.d.ts +156 -0
- package/lib/ssg.js +2 -0
- package/lib/streaming.d.ts +1 -1
- package/lib/testing.d.ts +3 -3
- package/lib/testing.js +1 -1
- package/lib/timeout.d.ts +1 -1
- package/lib/timing.d.ts +1 -1
- package/lib/tiny.d.ts +1 -1
- package/lib/trailing-slash.d.ts +1 -1
- package/lib/{types-nEL8VPDC.d.ts → types-Dv_nV2cv.d.ts} +1 -1
- package/lib/{types-CQiGmsWW.d.ts → types-zNxyEpG2.d.ts} +2 -2
- package/lib/types.d.ts +1 -1
- package/lib/utils/body.d.ts +1 -1
- package/lib/utils/ipaddr.d.ts +1 -1
- package/lib/utils-Cx61GFMC.js +125 -0
- package/lib/validator.d.ts +1 -1
- package/lib/ws.d.ts +1 -1
- package/package.json +9 -1
- package/plugins/acryl-inspect/upstream.json +1 -1
- package/plugins/acryl-node-server/upstream.json +1 -1
- package/plugins/acryl-router/src/core/helper/ssg/index.ts +14 -0
- package/plugins/acryl-router/src/core/helper/ssg/middleware.ts +83 -0
- package/plugins/acryl-router/src/core/helper/ssg/plugins.ts +72 -0
- package/plugins/acryl-router/src/core/helper/ssg/ssg.ts +471 -0
- package/plugins/acryl-router/src/core/helper/ssg/utils.ts +118 -0
- package/plugins/acryl-router/src/core/jsx/dom/render.ts +6 -6
- package/plugins/acryl-router/src/core/middleware/cache/index.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/jsx-renderer/index.ts +162 -0
- package/plugins/acryl-router/src/helpers/index.ts +1 -0
- package/plugins/acryl-router/src/middleware/index.ts +1 -0
- package/plugins/acryl-router/upstream.json +2 -2
- package/plugins/acryl-router-http/upstream.json +1 -1
- package/plugins/acryl-state/upstream.json +1 -1
- package/plugins/desktop/upstream.json +1 -1
- package/plugins/desktop-web/upstream.json +1 -1
- package/plugins/extensions/resolve.ts +4 -0
- package/shared/AGENTS.core.md +4 -0
- package/templates/agent/tsconfig.json +7 -1
- package/templates/todo/upstream.json +1 -1
- package/plugins/acryl-inspect/tests/report.spec.ts +0 -69
- package/plugins/acryl-inspect/tests/service.spec.ts +0 -121
- package/plugins/acryl-node-server/tests/adapter/app.ts +0 -76
- package/plugins/acryl-node-server/tests/adapter/assets/.static/plain.txt +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/favicon.ico +0 -0
- package/plugins/acryl-node-server/tests/adapter/assets/secret.txt +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static/acryl.html +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static/admin/secret.txt +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static/data.json +0 -5
- package/plugins/acryl-node-server/tests/adapter/assets/static/extensionless +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static/foo..bar.txt +0 -0
- package/plugins/acryl-node-server/tests/adapter/assets/static/index.html +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static/plain.txt +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-context-path/plain.txt +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-precompressed/hello.bin +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-precompressed/hello.bin.br +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-precompressed/hello.txt +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-precompressed/hello.txt.br +0 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static-with-precompressed/hello.txt.zst +0 -1
- package/plugins/acryl-node-server/tests/adapter/conninfo.test.ts +0 -34
- package/plugins/acryl-node-server/tests/adapter/content-length.test.ts +0 -248
- package/plugins/acryl-node-server/tests/adapter/early-hints.test.ts +0 -457
- package/plugins/acryl-node-server/tests/adapter/fixtures/keys/agent1-cert.pem +0 -23
- package/plugins/acryl-node-server/tests/adapter/fixtures/keys/agent1-key.pem +0 -27
- package/plugins/acryl-node-server/tests/adapter/headers.test.ts +0 -252
- package/plugins/acryl-node-server/tests/adapter/helpers/request.ts +0 -190
- package/plugins/acryl-node-server/tests/adapter/listener.test.ts +0 -727
- package/plugins/acryl-node-server/tests/adapter/request-client-disconnect.test.ts +0 -189
- package/plugins/acryl-node-server/tests/adapter/request.test.ts +0 -1230
- package/plugins/acryl-node-server/tests/adapter/response.test.ts +0 -285
- package/plugins/acryl-node-server/tests/adapter/serve-static.test.ts +0 -849
- package/plugins/acryl-node-server/tests/adapter/server-socket.test.ts +0 -790
- package/plugins/acryl-node-server/tests/adapter/server.test.ts +0 -1312
- package/plugins/acryl-node-server/tests/adapter/setup.ts +0 -16
- package/plugins/acryl-node-server/tests/adapter/url.test.ts +0 -76
- package/plugins/acryl-node-server/tests/adapter/utils/response.test.ts +0 -23
- package/plugins/acryl-node-server/tests/adapter/utils/stream.test.ts +0 -75
- package/plugins/acryl-node-server/tests/adapter/utils.test.ts +0 -235
- package/plugins/acryl-node-server/tests/adapter/websocket.test.ts +0 -260
- package/plugins/acryl-node-server/tests/server.spec.ts +0 -141
- package/plugins/acryl-router/src/core/app.test.ts +0 -3833
- package/plugins/acryl-router/src/core/client/client.test.ts +0 -2313
- package/plugins/acryl-router/src/core/client/types.test.ts +0 -149
- package/plugins/acryl-router/src/core/client/utils.test.ts +0 -405
- package/plugins/acryl-router/src/core/compose.test.ts +0 -751
- package/plugins/acryl-router/src/core/context.test.ts +0 -629
- package/plugins/acryl-router/src/core/helper/accepts/accepts.test.ts +0 -344
- package/plugins/acryl-router/src/core/helper/adapter/index.test.ts +0 -55
- package/plugins/acryl-router/src/core/helper/cookie/index.test.ts +0 -510
- package/plugins/acryl-router/src/core/helper/css/common.case.test.tsx +0 -506
- package/plugins/acryl-router/src/core/helper/css/index.test.tsx +0 -678
- package/plugins/acryl-router/src/core/helper/dev/index.test.ts +0 -181
- package/plugins/acryl-router/src/core/helper/factory/index.test.ts +0 -434
- package/plugins/acryl-router/src/core/helper/html/index.test.ts +0 -78
- package/plugins/acryl-router/src/core/helper/proxy/index.test.ts +0 -356
- package/plugins/acryl-router/src/core/helper/route/index.test.ts +0 -259
- package/plugins/acryl-router/src/core/helper/streaming/sse.test.tsx +0 -557
- package/plugins/acryl-router/src/core/helper/streaming/stream.test.ts +0 -128
- package/plugins/acryl-router/src/core/helper/streaming/text.test.ts +0 -34
- package/plugins/acryl-router/src/core/helper/testing/index.test.ts +0 -42
- package/plugins/acryl-router/src/core/helper/websocket/index.test.ts +0 -124
- package/plugins/acryl-router/src/core/http-exception.test.ts +0 -45
- package/plugins/acryl-router/src/core/jsx/base.test.tsx +0 -97
- package/plugins/acryl-router/src/core/jsx/children.test.ts +0 -52
- package/plugins/acryl-router/src/core/jsx/components.test.tsx +0 -936
- package/plugins/acryl-router/src/core/jsx/context-isolation.test.ts +0 -655
- package/plugins/acryl-router/src/core/jsx/dom/client.test.tsx +0 -128
- package/plugins/acryl-router/src/core/jsx/dom/components.test.tsx +0 -330
- package/plugins/acryl-router/src/core/jsx/dom/context.test.tsx +0 -184
- package/plugins/acryl-router/src/core/jsx/dom/css.test.tsx +0 -149
- package/plugins/acryl-router/src/core/jsx/dom/hooks/index.test.tsx +0 -172
- package/plugins/acryl-router/src/core/jsx/dom/index.test.tsx +0 -3681
- package/plugins/acryl-router/src/core/jsx/dom/intrinsic-element/components.test.tsx +0 -1344
- package/plugins/acryl-router/src/core/jsx/dom/server.test.tsx +0 -199
- package/plugins/acryl-router/src/core/jsx/hooks/dom.test.tsx +0 -859
- package/plugins/acryl-router/src/core/jsx/hooks/string.test.tsx +0 -40
- package/plugins/acryl-router/src/core/jsx/index.test.tsx +0 -1744
- package/plugins/acryl-router/src/core/jsx/intrinsic-element/components.test.tsx +0 -666
- package/plugins/acryl-router/src/core/jsx/jsx-runtime.test.tsx +0 -85
- package/plugins/acryl-router/src/core/jsx/streaming.test.tsx +0 -1281
- package/plugins/acryl-router/src/core/jsx/utils.test.ts +0 -366
- package/plugins/acryl-router/src/core/middleware/basic-auth/index.test.ts +0 -434
- package/plugins/acryl-router/src/core/middleware/bearer-auth/index.test.ts +0 -1018
- package/plugins/acryl-router/src/core/middleware/body-limit/index.test.ts +0 -273
- package/plugins/acryl-router/src/core/middleware/cache/index.test.ts +0 -1211
- package/plugins/acryl-router/src/core/middleware/combine/index.test.ts +0 -355
- package/plugins/acryl-router/src/core/middleware/compress/index.test.ts +0 -535
- package/plugins/acryl-router/src/core/middleware/context-storage/index.test.ts +0 -43
- package/plugins/acryl-router/src/core/middleware/cors/index.test.ts +0 -532
- package/plugins/acryl-router/src/core/middleware/csrf/index.test.ts +0 -534
- package/plugins/acryl-router/src/core/middleware/etag/digest.test.ts +0 -21
- package/plugins/acryl-router/src/core/middleware/etag/index.test.ts +0 -503
- package/plugins/acryl-router/src/core/middleware/ip-restriction/index.test.ts +0 -217
- package/plugins/acryl-router/src/core/middleware/jwk/index.test.ts +0 -1135
- package/plugins/acryl-router/src/core/middleware/jwk/keys.test.json +0 -48
- package/plugins/acryl-router/src/core/middleware/jwt/index.test.ts +0 -802
- package/plugins/acryl-router/src/core/middleware/language/index.test.ts +0 -552
- package/plugins/acryl-router/src/core/middleware/logger/index.test.ts +0 -204
- package/plugins/acryl-router/src/core/middleware/method-not-allowed/index.test.ts +0 -292
- package/plugins/acryl-router/src/core/middleware/method-override/index.test.ts +0 -221
- package/plugins/acryl-router/src/core/middleware/mount/index.test.ts +0 -334
- package/plugins/acryl-router/src/core/middleware/powered-by/index.test.ts +0 -37
- package/plugins/acryl-router/src/core/middleware/pretty-json/index.test.ts +0 -218
- package/plugins/acryl-router/src/core/middleware/request-id/index.test.ts +0 -168
- package/plugins/acryl-router/src/core/middleware/secure-headers/index.test.ts +0 -671
- package/plugins/acryl-router/src/core/middleware/serve-static/index.test.ts +0 -450
- package/plugins/acryl-router/src/core/middleware/serve-static/path.test.ts +0 -50
- package/plugins/acryl-router/src/core/middleware/timeout/index.test.ts +0 -70
- package/plugins/acryl-router/src/core/middleware/timing/index.test.ts +0 -310
- package/plugins/acryl-router/src/core/middleware/trailing-slash/index.test.ts +0 -381
- package/plugins/acryl-router/src/core/preset/quick.test.ts +0 -42
- package/plugins/acryl-router/src/core/preset/tiny.test.ts +0 -42
- package/plugins/acryl-router/src/core/request.test.ts +0 -751
- package/plugins/acryl-router/src/core/router/common.case.test.ts +0 -1132
- package/plugins/acryl-router/src/core/router/linear-router/router.test.ts +0 -80
- package/plugins/acryl-router/src/core/router/pattern-router/router.test.ts +0 -46
- package/plugins/acryl-router/src/core/router/reg-exp-router/prepared-router.test.ts +0 -154
- package/plugins/acryl-router/src/core/router/reg-exp-router/router.test.ts +0 -265
- package/plugins/acryl-router/src/core/router/smart-router/router.test.ts +0 -13
- package/plugins/acryl-router/src/core/router/trie-router/node.test.ts +0 -896
- package/plugins/acryl-router/src/core/router/trie-router/router.test.ts +0 -8
- package/plugins/acryl-router/src/core/types.test.ts +0 -4134
- package/plugins/acryl-router/src/core/utils/accept.test.ts +0 -299
- package/plugins/acryl-router/src/core/utils/basic-auth.test.ts +0 -56
- package/plugins/acryl-router/src/core/utils/body.test.ts +0 -496
- package/plugins/acryl-router/src/core/utils/buffer.test.ts +0 -147
- package/plugins/acryl-router/src/core/utils/color.test.ts +0 -23
- package/plugins/acryl-router/src/core/utils/concurrent.test.ts +0 -69
- package/plugins/acryl-router/src/core/utils/cookie.test.ts +0 -460
- package/plugins/acryl-router/src/core/utils/crypto.test.ts +0 -43
- package/plugins/acryl-router/src/core/utils/encode.test.ts +0 -61
- package/plugins/acryl-router/src/core/utils/filepath.test.ts +0 -78
- package/plugins/acryl-router/src/core/utils/html.test.ts +0 -16
- package/plugins/acryl-router/src/core/utils/ipaddr.test.ts +0 -149
- package/plugins/acryl-router/src/core/utils/jwt/jwa.test.ts +0 -86
- package/plugins/acryl-router/src/core/utils/jwt/jwt.test.ts +0 -1788
- package/plugins/acryl-router/src/core/utils/mime.test.ts +0 -64
- package/plugins/acryl-router/src/core/utils/stream.test.ts +0 -212
- package/plugins/acryl-router/src/core/utils/types.test.ts +0 -295
- package/plugins/acryl-router/src/core/utils/url.test.ts +0 -384
- package/plugins/acryl-router/src/core/validator/utils.test.ts +0 -82
- package/plugins/acryl-router/src/core/validator/validator.test.ts +0 -1488
- package/plugins/acryl-router/tests/docs-examples.spec.ts +0 -152
- package/plugins/acryl-router/tests/jsx.spec.tsx +0 -63
- package/plugins/acryl-router/tests/live-install.spec.ts +0 -64
- package/plugins/acryl-router/tests/loader.spec.ts +0 -72
- package/plugins/acryl-router/tests/loopback-only.spec.ts +0 -80
- package/plugins/acryl-router/tests/no-dom/consumer.ts +0 -11
- package/plugins/acryl-router/tests/no-dom/tsconfig.json +0 -13
- package/plugins/acryl-router/tests/service.spec.ts +0 -426
- package/plugins/acryl-router/tests/shadow-state.spec.ts +0 -79
- package/plugins/acryl-router-http/tests/adapter.spec.ts +0 -174
- package/plugins/acryl-router-http/tests/stream.spec.ts +0 -133
- package/plugins/acryl-router-http/tests/surfaces.spec.ts +0 -101
- package/plugins/acryl-state/src/react.ts +0 -11
- package/plugins/acryl-state/tests/cell.spec.ts +0 -71
- package/plugins/acryl-state/tests/react.spec.ts +0 -39
- package/plugins/acryl-state/tests/service.spec.ts +0 -132
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource ../ */
|
|
2
|
-
import { JSDOM } from 'jsdom'
|
|
3
|
-
import { useEffect } from './index.ts'
|
|
4
|
-
import DefaultExport, { createRoot, hydrateRoot } from './client.ts'
|
|
5
|
-
|
|
6
|
-
describe('createRoot', () => {
|
|
7
|
-
beforeAll(() => {
|
|
8
|
-
global.requestAnimationFrame = (cb) => setTimeout(cb)
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
let dom: JSDOM
|
|
12
|
-
let rootElement: HTMLElement
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
dom = new JSDOM('<html><body><div id="root"></div></body></html>', {
|
|
15
|
-
runScripts: 'dangerously',
|
|
16
|
-
})
|
|
17
|
-
global.document = dom.window.document
|
|
18
|
-
global.HTMLElement = dom.window.HTMLElement
|
|
19
|
-
global.SVGElement = dom.window.SVGElement
|
|
20
|
-
global.Text = dom.window.Text
|
|
21
|
-
rootElement = document.getElementById('root') as HTMLElement
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('render / unmount', async () => {
|
|
25
|
-
const cleanup = vi.fn()
|
|
26
|
-
const App = () => {
|
|
27
|
-
useEffect(() => cleanup, [])
|
|
28
|
-
return <h1>Hello</h1>
|
|
29
|
-
}
|
|
30
|
-
const root = createRoot(rootElement)
|
|
31
|
-
root.render(<App />)
|
|
32
|
-
expect(rootElement.innerHTML).toBe('<h1>Hello</h1>')
|
|
33
|
-
await new Promise((resolve) => setTimeout(resolve))
|
|
34
|
-
root.unmount()
|
|
35
|
-
await Promise.resolve()
|
|
36
|
-
expect(rootElement.innerHTML).toBe('')
|
|
37
|
-
expect(cleanup).toHaveBeenCalled()
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('call render twice', async () => {
|
|
41
|
-
const App = <h1>Hello</h1>
|
|
42
|
-
const App2 = <h1>World</h1>
|
|
43
|
-
const root = createRoot(rootElement)
|
|
44
|
-
root.render(App)
|
|
45
|
-
expect(rootElement.innerHTML).toBe('<h1>Hello</h1>')
|
|
46
|
-
|
|
47
|
-
const createElementSpy = vi.spyOn(dom.window.document, 'createElement')
|
|
48
|
-
|
|
49
|
-
root.render(App2)
|
|
50
|
-
await Promise.resolve()
|
|
51
|
-
expect(rootElement.innerHTML).toBe('<h1>World</h1>')
|
|
52
|
-
|
|
53
|
-
expect(createElementSpy).not.toHaveBeenCalled()
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('call render after unmount', async () => {
|
|
57
|
-
const App = <h1>Hello</h1>
|
|
58
|
-
const App2 = <h1>World</h1>
|
|
59
|
-
const root = createRoot(rootElement)
|
|
60
|
-
root.render(App)
|
|
61
|
-
expect(rootElement.innerHTML).toBe('<h1>Hello</h1>')
|
|
62
|
-
root.unmount()
|
|
63
|
-
expect(() => root.render(App2)).toThrow('Cannot update an unmounted root')
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
describe('hydrateRoot', () => {
|
|
68
|
-
let dom: JSDOM
|
|
69
|
-
let rootElement: HTMLElement
|
|
70
|
-
beforeEach(() => {
|
|
71
|
-
dom = new JSDOM('<html><body><div id="root"></div></body></html>', {
|
|
72
|
-
runScripts: 'dangerously',
|
|
73
|
-
})
|
|
74
|
-
global.document = dom.window.document
|
|
75
|
-
global.HTMLElement = dom.window.HTMLElement
|
|
76
|
-
global.SVGElement = dom.window.SVGElement
|
|
77
|
-
global.Text = dom.window.Text
|
|
78
|
-
rootElement = document.getElementById('root') as HTMLElement
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
it('should return root object', async () => {
|
|
82
|
-
const cleanup = vi.fn()
|
|
83
|
-
const App = () => {
|
|
84
|
-
useEffect(() => cleanup, [])
|
|
85
|
-
return <h1>Hello</h1>
|
|
86
|
-
}
|
|
87
|
-
const root = hydrateRoot(rootElement, <App />)
|
|
88
|
-
expect(rootElement.innerHTML).toBe('<h1>Hello</h1>')
|
|
89
|
-
await new Promise((resolve) => setTimeout(resolve))
|
|
90
|
-
root.unmount()
|
|
91
|
-
await Promise.resolve()
|
|
92
|
-
expect(rootElement.innerHTML).toBe('')
|
|
93
|
-
expect(cleanup).toHaveBeenCalled()
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('call render', async () => {
|
|
97
|
-
const App = <h1>Hello</h1>
|
|
98
|
-
const App2 = <h1>World</h1>
|
|
99
|
-
const root = hydrateRoot(rootElement, App)
|
|
100
|
-
expect(rootElement.innerHTML).toBe('<h1>Hello</h1>')
|
|
101
|
-
|
|
102
|
-
const createElementSpy = vi.spyOn(dom.window.document, 'createElement')
|
|
103
|
-
|
|
104
|
-
root.render(App2)
|
|
105
|
-
await Promise.resolve()
|
|
106
|
-
expect(rootElement.innerHTML).toBe('<h1>World</h1>')
|
|
107
|
-
|
|
108
|
-
expect(createElementSpy).not.toHaveBeenCalled()
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it('call render after unmount', async () => {
|
|
112
|
-
const App = <h1>Hello</h1>
|
|
113
|
-
const App2 = <h1>World</h1>
|
|
114
|
-
const root = hydrateRoot(rootElement, App)
|
|
115
|
-
expect(rootElement.innerHTML).toBe('<h1>Hello</h1>')
|
|
116
|
-
root.unmount()
|
|
117
|
-
expect(() => root.render(App2)).toThrow('Cannot update an unmounted root')
|
|
118
|
-
})
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
describe('default export', () => {
|
|
122
|
-
;['createRoot', 'hydrateRoot'].forEach((key) => {
|
|
123
|
-
it(key, () => {
|
|
124
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
125
|
-
expect((DefaultExport as any)[key]).toBeDefined()
|
|
126
|
-
})
|
|
127
|
-
})
|
|
128
|
-
})
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource ../ */
|
|
2
|
-
import { JSDOM } from 'jsdom'
|
|
3
|
-
import { ErrorBoundary as ErrorBoundaryDom, Suspense as SuspenseDom, render } from './index.ts' // for dom
|
|
4
|
-
import { ErrorBoundary as ErrorBoundaryCommon, Suspense as SuspenseCommon } from '../index.ts' // for common
|
|
5
|
-
// run tests by old style jsx default
|
|
6
|
-
// acryl-router/jsx/jsx-runtime and acryl-router/jsx/dom/jsx-runtime are tested in their respective settings
|
|
7
|
-
import { use, useState } from '../hooks/index.ts'
|
|
8
|
-
|
|
9
|
-
runner('Common', SuspenseCommon, ErrorBoundaryCommon)
|
|
10
|
-
runner('DOM', SuspenseDom, ErrorBoundaryDom)
|
|
11
|
-
|
|
12
|
-
function runner(
|
|
13
|
-
name: string,
|
|
14
|
-
Suspense: typeof SuspenseDom,
|
|
15
|
-
ErrorBoundary: typeof ErrorBoundaryDom
|
|
16
|
-
) {
|
|
17
|
-
describe(name, () => {
|
|
18
|
-
beforeAll(() => {
|
|
19
|
-
global.requestAnimationFrame = (cb) => setTimeout(cb)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
describe('Suspense', () => {
|
|
23
|
-
let dom: JSDOM
|
|
24
|
-
let root: HTMLElement
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
dom = new JSDOM('<html><body><div id="root"></div></body></html>', {
|
|
27
|
-
runScripts: 'dangerously',
|
|
28
|
-
})
|
|
29
|
-
global.document = dom.window.document
|
|
30
|
-
global.HTMLElement = dom.window.HTMLElement
|
|
31
|
-
global.Text = dom.window.Text
|
|
32
|
-
root = document.getElementById('root') as HTMLElement
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('has no lazy load content', async () => {
|
|
36
|
-
const App = <Suspense fallback={<div>Loading...</div>}>Hello</Suspense>
|
|
37
|
-
render(App, root)
|
|
38
|
-
expect(root.innerHTML).toBe('Hello')
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('with use()', async () => {
|
|
42
|
-
let resolve: (value: number) => void = () => {}
|
|
43
|
-
const promise = new Promise<number>((_resolve) => (resolve = _resolve))
|
|
44
|
-
const Content = () => {
|
|
45
|
-
const num = use(promise)
|
|
46
|
-
return <p>{num}</p>
|
|
47
|
-
}
|
|
48
|
-
const Component = () => {
|
|
49
|
-
return (
|
|
50
|
-
<Suspense fallback={<div>Loading...</div>}>
|
|
51
|
-
<Content />
|
|
52
|
-
</Suspense>
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
const App = <Component />
|
|
56
|
-
render(App, root)
|
|
57
|
-
expect(root.innerHTML).toBe('<div>Loading...</div>')
|
|
58
|
-
resolve(1)
|
|
59
|
-
await new Promise((resolve) => setTimeout(resolve))
|
|
60
|
-
expect(root.innerHTML).toBe('<p>1</p>')
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('with use() update', async () => {
|
|
64
|
-
const counterMap: Record<number, Promise<number>> = {}
|
|
65
|
-
const getCounter = (count: number) => (counterMap[count] ||= Promise.resolve(count + 1))
|
|
66
|
-
const Content = ({ count }: { count: number }) => {
|
|
67
|
-
const num = use(getCounter(count))
|
|
68
|
-
return (
|
|
69
|
-
<>
|
|
70
|
-
<div>{num}</div>
|
|
71
|
-
</>
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
const Component = () => {
|
|
75
|
-
const [count, setCount] = useState(0)
|
|
76
|
-
return (
|
|
77
|
-
<Suspense fallback={<div>Loading...</div>}>
|
|
78
|
-
<Content count={count} />
|
|
79
|
-
<button onClick={() => setCount(count + 1)}>Increment</button>
|
|
80
|
-
</Suspense>
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
const App = <Component />
|
|
84
|
-
render(App, root)
|
|
85
|
-
expect(root.innerHTML).toBe('<div>Loading...</div>')
|
|
86
|
-
await Promise.resolve()
|
|
87
|
-
await Promise.resolve()
|
|
88
|
-
expect(root.innerHTML).toBe('<div>1</div><button>Increment</button>')
|
|
89
|
-
root.querySelector('button')?.click()
|
|
90
|
-
await Promise.resolve()
|
|
91
|
-
expect(root.innerHTML).toBe('<div>Loading...</div>')
|
|
92
|
-
await Promise.resolve()
|
|
93
|
-
await Promise.resolve()
|
|
94
|
-
expect(root.innerHTML).toBe('<div>2</div><button>Increment</button>')
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('with use() nested', async () => {
|
|
98
|
-
let resolve: (value: number) => void = () => {}
|
|
99
|
-
const promise = new Promise<number>((_resolve) => (resolve = _resolve))
|
|
100
|
-
const Content = () => {
|
|
101
|
-
const num = use(promise)
|
|
102
|
-
return <p>{num}</p>
|
|
103
|
-
}
|
|
104
|
-
let resolve2: (value: number) => void = () => {}
|
|
105
|
-
const promise2 = new Promise<number>((_resolve) => (resolve2 = _resolve))
|
|
106
|
-
const Content2 = () => {
|
|
107
|
-
const num = use(promise2)
|
|
108
|
-
return <p>{num}</p>
|
|
109
|
-
}
|
|
110
|
-
const Component = () => {
|
|
111
|
-
return (
|
|
112
|
-
<Suspense fallback={<div>Loading...</div>}>
|
|
113
|
-
<Content />
|
|
114
|
-
<Suspense fallback={<div>More...</div>}>
|
|
115
|
-
<Content2 />
|
|
116
|
-
</Suspense>
|
|
117
|
-
</Suspense>
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
const App = <Component />
|
|
121
|
-
render(App, root)
|
|
122
|
-
expect(root.innerHTML).toBe('<div>Loading...</div>')
|
|
123
|
-
resolve(1)
|
|
124
|
-
await new Promise((resolve) => setTimeout(resolve))
|
|
125
|
-
expect(root.innerHTML).toBe('<p>1</p><div>More...</div>')
|
|
126
|
-
resolve2(2)
|
|
127
|
-
await new Promise((resolve) => setTimeout(resolve))
|
|
128
|
-
expect(root.innerHTML).toBe('<p>1</p><p>2</p>')
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('race condition', async () => {
|
|
132
|
-
let resolve: (value: number) => void = () => {}
|
|
133
|
-
const promise = new Promise<number>((_resolve) => (resolve = _resolve))
|
|
134
|
-
const Content = () => {
|
|
135
|
-
const num = use(promise)
|
|
136
|
-
return <p>{num}</p>
|
|
137
|
-
}
|
|
138
|
-
const Component = () => {
|
|
139
|
-
const [show, setShow] = useState(false)
|
|
140
|
-
return (
|
|
141
|
-
<div>
|
|
142
|
-
<button onClick={() => setShow((s) => !s)}>{show ? 'Hide' : 'Show'}</button>
|
|
143
|
-
{show && (
|
|
144
|
-
<Suspense fallback={<div>Loading...</div>}>
|
|
145
|
-
<Content />
|
|
146
|
-
</Suspense>
|
|
147
|
-
)}
|
|
148
|
-
</div>
|
|
149
|
-
)
|
|
150
|
-
}
|
|
151
|
-
const App = <Component />
|
|
152
|
-
render(App, root)
|
|
153
|
-
expect(root.innerHTML).toBe('<div><button>Show</button></div>')
|
|
154
|
-
root.querySelector('button')?.click()
|
|
155
|
-
await Promise.resolve()
|
|
156
|
-
expect(root.innerHTML).toBe('<div><button>Hide</button><div>Loading...</div></div>')
|
|
157
|
-
root.querySelector('button')?.click()
|
|
158
|
-
await Promise.resolve()
|
|
159
|
-
expect(root.innerHTML).toBe('<div><button>Show</button></div>')
|
|
160
|
-
root.querySelector('button')?.click()
|
|
161
|
-
await Promise.resolve()
|
|
162
|
-
expect(root.innerHTML).toBe('<div><button>Hide</button><div>Loading...</div></div>')
|
|
163
|
-
resolve(2)
|
|
164
|
-
await Promise.resolve()
|
|
165
|
-
await Promise.resolve()
|
|
166
|
-
expect(root.innerHTML).toBe('<div><button>Hide</button><p>2</p></div>')
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
it('Suspense at child', async () => {
|
|
170
|
-
let resolve: (value: number) => void = () => {}
|
|
171
|
-
const promise = new Promise<number>((_resolve) => (resolve = _resolve))
|
|
172
|
-
const Content = () => {
|
|
173
|
-
const num = use(promise)
|
|
174
|
-
return <p>{num}</p>
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const Component = () => {
|
|
178
|
-
return (
|
|
179
|
-
<Suspense fallback={<div>Loading...</div>}>
|
|
180
|
-
<Content />
|
|
181
|
-
</Suspense>
|
|
182
|
-
)
|
|
183
|
-
}
|
|
184
|
-
const App = () => {
|
|
185
|
-
const [show, setShow] = useState(false)
|
|
186
|
-
return (
|
|
187
|
-
<div>
|
|
188
|
-
{show && <Component />}
|
|
189
|
-
<button onClick={() => setShow(true)}>Show</button>
|
|
190
|
-
</div>
|
|
191
|
-
)
|
|
192
|
-
}
|
|
193
|
-
render(<App />, root)
|
|
194
|
-
expect(root.innerHTML).toBe('<div><button>Show</button></div>')
|
|
195
|
-
root.querySelector('button')?.click()
|
|
196
|
-
await Promise.resolve()
|
|
197
|
-
expect(root.innerHTML).toBe('<div><div>Loading...</div><button>Show</button></div>')
|
|
198
|
-
resolve(2)
|
|
199
|
-
await Promise.resolve()
|
|
200
|
-
await Promise.resolve()
|
|
201
|
-
expect(root.innerHTML).toBe('<div><p>2</p><button>Show</button></div>')
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
it('Suspense at child counter', async () => {
|
|
205
|
-
const promiseMap: Record<number, Promise<number>> = {}
|
|
206
|
-
const Counter = () => {
|
|
207
|
-
const [count, setCount] = useState(0)
|
|
208
|
-
const promise = (promiseMap[count] ||= Promise.resolve(count))
|
|
209
|
-
const value = use(promise)
|
|
210
|
-
return (
|
|
211
|
-
<>
|
|
212
|
-
<p>{value}</p>
|
|
213
|
-
<button onClick={() => setCount(count + 1)}>Increment</button>
|
|
214
|
-
</>
|
|
215
|
-
)
|
|
216
|
-
}
|
|
217
|
-
const Component = () => {
|
|
218
|
-
return (
|
|
219
|
-
<Suspense fallback={<div>Loading...</div>}>
|
|
220
|
-
<Counter />
|
|
221
|
-
</Suspense>
|
|
222
|
-
)
|
|
223
|
-
}
|
|
224
|
-
const App = () => {
|
|
225
|
-
return (
|
|
226
|
-
<div>
|
|
227
|
-
<Component />
|
|
228
|
-
</div>
|
|
229
|
-
)
|
|
230
|
-
}
|
|
231
|
-
render(<App />, root)
|
|
232
|
-
expect(root.innerHTML).toBe('<div><div>Loading...</div></div>')
|
|
233
|
-
await Promise.resolve()
|
|
234
|
-
await Promise.resolve()
|
|
235
|
-
expect(root.innerHTML).toBe('<div><p>0</p><button>Increment</button></div>')
|
|
236
|
-
root.querySelector('button')?.click()
|
|
237
|
-
await Promise.resolve()
|
|
238
|
-
expect(root.innerHTML).toBe('<div><div>Loading...</div></div>')
|
|
239
|
-
await Promise.resolve()
|
|
240
|
-
await Promise.resolve()
|
|
241
|
-
expect(root.innerHTML).toBe('<div><p>1</p><button>Increment</button></div>')
|
|
242
|
-
})
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
describe('ErrorBoundary', () => {
|
|
246
|
-
let dom: JSDOM
|
|
247
|
-
let root: HTMLElement
|
|
248
|
-
beforeEach(() => {
|
|
249
|
-
dom = new JSDOM('<html><body><div id="root"></div></body></html>', {
|
|
250
|
-
runScripts: 'dangerously',
|
|
251
|
-
})
|
|
252
|
-
global.document = dom.window.document
|
|
253
|
-
global.HTMLElement = dom.window.HTMLElement
|
|
254
|
-
global.Text = dom.window.Text
|
|
255
|
-
root = document.getElementById('root') as HTMLElement
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
it('has no error', async () => {
|
|
259
|
-
const App = (
|
|
260
|
-
<ErrorBoundary fallback={<div>Error</div>}>
|
|
261
|
-
<div>OK</div>
|
|
262
|
-
</ErrorBoundary>
|
|
263
|
-
)
|
|
264
|
-
render(App, root)
|
|
265
|
-
expect(root.innerHTML).toBe('<div>OK</div>')
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
it('has error', async () => {
|
|
269
|
-
const Component = () => {
|
|
270
|
-
throw new Error('error')
|
|
271
|
-
}
|
|
272
|
-
const App = (
|
|
273
|
-
<ErrorBoundary fallback={<div>Error</div>}>
|
|
274
|
-
<Component />
|
|
275
|
-
</ErrorBoundary>
|
|
276
|
-
)
|
|
277
|
-
render(App, root)
|
|
278
|
-
expect(root.innerHTML).toBe('<div>Error</div>')
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
it('has no error with Suspense', async () => {
|
|
282
|
-
let resolve: (value: number) => void = () => {}
|
|
283
|
-
const promise = new Promise<number>((_resolve) => (resolve = _resolve))
|
|
284
|
-
const Content = () => {
|
|
285
|
-
const num = use(promise)
|
|
286
|
-
return <p>{num}</p>
|
|
287
|
-
}
|
|
288
|
-
const Component = () => {
|
|
289
|
-
return (
|
|
290
|
-
<ErrorBoundary fallback={<div>Error</div>}>
|
|
291
|
-
<Suspense fallback={<div>Loading...</div>}>
|
|
292
|
-
<Content />
|
|
293
|
-
</Suspense>
|
|
294
|
-
</ErrorBoundary>
|
|
295
|
-
)
|
|
296
|
-
}
|
|
297
|
-
const App = <Component />
|
|
298
|
-
render(App, root)
|
|
299
|
-
expect(root.innerHTML).toBe('<div>Loading...</div>')
|
|
300
|
-
resolve(1)
|
|
301
|
-
await new Promise((resolve) => setTimeout(resolve))
|
|
302
|
-
expect(root.innerHTML).toBe('<p>1</p>')
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
it('has error with Suspense', async () => {
|
|
306
|
-
let resolve: (value: number) => void = () => {}
|
|
307
|
-
const promise = new Promise<number>((_resolve) => (resolve = _resolve))
|
|
308
|
-
const Content = () => {
|
|
309
|
-
use(promise)
|
|
310
|
-
throw new Error('error')
|
|
311
|
-
}
|
|
312
|
-
const Component = () => {
|
|
313
|
-
return (
|
|
314
|
-
<ErrorBoundary fallback={<div>Error</div>}>
|
|
315
|
-
<Suspense fallback={<div>Loading...</div>}>
|
|
316
|
-
<Content />
|
|
317
|
-
</Suspense>
|
|
318
|
-
</ErrorBoundary>
|
|
319
|
-
)
|
|
320
|
-
}
|
|
321
|
-
const App = <Component />
|
|
322
|
-
render(App, root)
|
|
323
|
-
expect(root.innerHTML).toBe('<div>Loading...</div>')
|
|
324
|
-
resolve(1)
|
|
325
|
-
await new Promise((resolve) => setTimeout(resolve))
|
|
326
|
-
expect(root.innerHTML).toBe('<div>Error</div>')
|
|
327
|
-
})
|
|
328
|
-
})
|
|
329
|
-
})
|
|
330
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource ../ */
|
|
2
|
-
import { JSDOM } from 'jsdom'
|
|
3
|
-
// run tests by old style jsx default
|
|
4
|
-
// acryl-router/jsx/jsx-runtime and acryl-router/jsx/dom/jsx-runtime are tested in their respective settings
|
|
5
|
-
import { createContext as createContextDom, render, useContext as useContextDom, useState } from './index.ts' // for dom
|
|
6
|
-
import {
|
|
7
|
-
Suspense,
|
|
8
|
-
createContext as createContextCommon,
|
|
9
|
-
use,
|
|
10
|
-
useContext as useContextCommon,
|
|
11
|
-
} from '../index.ts' // for common
|
|
12
|
-
|
|
13
|
-
runner('Common', createContextCommon, useContextCommon)
|
|
14
|
-
runner('DOM', createContextDom, useContextDom)
|
|
15
|
-
|
|
16
|
-
function runner(
|
|
17
|
-
name: string,
|
|
18
|
-
createContext: typeof createContextCommon,
|
|
19
|
-
useContext: typeof useContextCommon
|
|
20
|
-
) {
|
|
21
|
-
describe(name, () => {
|
|
22
|
-
beforeAll(() => {
|
|
23
|
-
global.requestAnimationFrame = (cb) => setTimeout(cb)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
describe('Context', () => {
|
|
27
|
-
let dom: JSDOM
|
|
28
|
-
let root: HTMLElement
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
dom = new JSDOM('<html><body><div id="root"></div></body></html>', {
|
|
31
|
-
runScripts: 'dangerously',
|
|
32
|
-
})
|
|
33
|
-
global.document = dom.window.document
|
|
34
|
-
global.HTMLElement = dom.window.HTMLElement
|
|
35
|
-
global.Text = dom.window.Text
|
|
36
|
-
root = document.getElementById('root') as HTMLElement
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('simple context', async () => {
|
|
40
|
-
const Context = createContext(0)
|
|
41
|
-
const Content = () => {
|
|
42
|
-
const num = useContext(Context)
|
|
43
|
-
return <p>{num}</p>
|
|
44
|
-
}
|
|
45
|
-
const Component = () => {
|
|
46
|
-
return (
|
|
47
|
-
<Context.Provider value={1}>
|
|
48
|
-
<Content />
|
|
49
|
-
</Context.Provider>
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
const App = <Component />
|
|
53
|
-
render(App, root)
|
|
54
|
-
expect(root.innerHTML).toBe('<p>1</p>')
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('<Context> as a provider ', async () => {
|
|
58
|
-
const Context = createContext(0)
|
|
59
|
-
const Content = () => {
|
|
60
|
-
const num = useContext(Context)
|
|
61
|
-
return <p>{num}</p>
|
|
62
|
-
}
|
|
63
|
-
const Component = () => {
|
|
64
|
-
return (
|
|
65
|
-
<Context value={1}>
|
|
66
|
-
<Content />
|
|
67
|
-
</Context>
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
const App = <Component />
|
|
71
|
-
render(App, root)
|
|
72
|
-
expect(root.innerHTML).toBe('<p>1</p>')
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('simple context with state', async () => {
|
|
76
|
-
const Context = createContext(0)
|
|
77
|
-
const Content = () => {
|
|
78
|
-
const [count, setCount] = useState(0)
|
|
79
|
-
const num = useContext(Context)
|
|
80
|
-
return (
|
|
81
|
-
<>
|
|
82
|
-
<p>
|
|
83
|
-
{num} - {count}
|
|
84
|
-
</p>
|
|
85
|
-
<button onClick={() => setCount(count + 1)}>+</button>
|
|
86
|
-
</>
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
const Component = () => {
|
|
90
|
-
return (
|
|
91
|
-
<Context.Provider value={1}>
|
|
92
|
-
<Content />
|
|
93
|
-
</Context.Provider>
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
const App = <Component />
|
|
97
|
-
render(App, root)
|
|
98
|
-
expect(root.innerHTML).toBe('<p>1 - 0</p><button>+</button>')
|
|
99
|
-
root.querySelector('button')?.click()
|
|
100
|
-
await Promise.resolve()
|
|
101
|
-
expect(root.innerHTML).toBe('<p>1 - 1</p><button>+</button>')
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
it('multiple provider', async () => {
|
|
105
|
-
const Context = createContext(0)
|
|
106
|
-
const Content = () => {
|
|
107
|
-
const num = useContext(Context)
|
|
108
|
-
return <p>{num}</p>
|
|
109
|
-
}
|
|
110
|
-
const Component = () => {
|
|
111
|
-
return (
|
|
112
|
-
<>
|
|
113
|
-
<Context.Provider value={1}>
|
|
114
|
-
<Content />
|
|
115
|
-
</Context.Provider>
|
|
116
|
-
<Context.Provider value={2}>
|
|
117
|
-
<Content />
|
|
118
|
-
</Context.Provider>
|
|
119
|
-
</>
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
const App = <Component />
|
|
123
|
-
render(App, root)
|
|
124
|
-
expect(root.innerHTML).toBe('<p>1</p><p>2</p>')
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
it('nested provider', async () => {
|
|
128
|
-
const Context = createContext(0)
|
|
129
|
-
const Content = () => {
|
|
130
|
-
const num = useContext(Context)
|
|
131
|
-
return <p>{num}</p>
|
|
132
|
-
}
|
|
133
|
-
const Component = () => {
|
|
134
|
-
return (
|
|
135
|
-
<>
|
|
136
|
-
<Context.Provider value={1}>
|
|
137
|
-
<Content />
|
|
138
|
-
<Context.Provider value={3}>
|
|
139
|
-
<Content />
|
|
140
|
-
</Context.Provider>
|
|
141
|
-
<Content />
|
|
142
|
-
</Context.Provider>
|
|
143
|
-
</>
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
const App = <Component />
|
|
147
|
-
render(App, root)
|
|
148
|
-
expect(root.innerHTML).toBe('<p>1</p><p>3</p><p>1</p>')
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it('inside Suspense', async () => {
|
|
152
|
-
const promise = Promise.resolve(2)
|
|
153
|
-
const AsyncComponent = () => {
|
|
154
|
-
const num = use(promise)
|
|
155
|
-
return <p>{num}</p>
|
|
156
|
-
}
|
|
157
|
-
const Context = createContext(0)
|
|
158
|
-
const Content = () => {
|
|
159
|
-
const num = useContext(Context)
|
|
160
|
-
return <p>{num}</p>
|
|
161
|
-
}
|
|
162
|
-
const Component = () => {
|
|
163
|
-
return (
|
|
164
|
-
<>
|
|
165
|
-
<Context.Provider value={1}>
|
|
166
|
-
<Content />
|
|
167
|
-
<Suspense fallback={<div>Loading...</div>}>
|
|
168
|
-
<Context.Provider value={3}>
|
|
169
|
-
<Content />
|
|
170
|
-
<AsyncComponent />
|
|
171
|
-
</Context.Provider>
|
|
172
|
-
</Suspense>
|
|
173
|
-
<Content />
|
|
174
|
-
</Context.Provider>
|
|
175
|
-
</>
|
|
176
|
-
)
|
|
177
|
-
}
|
|
178
|
-
const App = <Component />
|
|
179
|
-
render(App, root)
|
|
180
|
-
expect(root.innerHTML).toBe('<p>1</p><div>Loading...</div><p>1</p>')
|
|
181
|
-
})
|
|
182
|
-
})
|
|
183
|
-
})
|
|
184
|
-
}
|