tungsten 0.2.6 → 0.2.8

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.
Files changed (75) hide show
  1. package/dist/Components.d.ts +3 -1
  2. package/dist/Components.d.ts.map +1 -1
  3. package/dist/Components.js +100 -51
  4. package/dist/DomNodes.js +2 -2
  5. package/dist/FrameworkConfig.d.ts +2 -0
  6. package/dist/FrameworkConfig.d.ts.map +1 -1
  7. package/dist/FunctionComponentStandIn.d.ts +2 -0
  8. package/dist/FunctionComponentStandIn.d.ts.map +1 -1
  9. package/dist/FunctionComponentStandIn.js +16 -3
  10. package/dist/Instance/ClientRuntimeContext.d.ts +8 -0
  11. package/dist/Instance/ClientRuntimeContext.d.ts.map +1 -0
  12. package/dist/Instance/ClientRuntimeContext.js +1 -0
  13. package/dist/Instance/Instance.d.ts +20 -1
  14. package/dist/Instance/Instance.d.ts.map +1 -1
  15. package/dist/Instance/Instance.js +59 -11
  16. package/dist/Servers/loadEnvsDev.d.ts +1 -1
  17. package/dist/Servers/loadEnvsDev.d.ts.map +1 -1
  18. package/dist/Servers/loadEnvsDev.js +18 -3
  19. package/dist/Store/makeStore.d.ts.map +1 -1
  20. package/dist/Store/makeStore.js +7 -14
  21. package/dist/babelPlugins/BabelTransformPackageImports.d.ts +2 -0
  22. package/dist/babelPlugins/BabelTransformPackageImports.d.ts.map +1 -1
  23. package/dist/babelPlugins/BabelTransformPackageImports.js +111 -72
  24. package/dist/bin/commands/compile.d.ts.map +1 -1
  25. package/dist/bin/commands/compile.js +87 -13
  26. package/dist/bin/commands/compile.sxyt.d.ts +2 -0
  27. package/dist/bin/commands/compile.sxyt.d.ts.map +1 -0
  28. package/dist/bin/commands/compile.sxyt.js +136 -0
  29. package/dist/build/compileJavascript.d.ts +11 -1
  30. package/dist/build/compileJavascript.d.ts.map +1 -1
  31. package/dist/build/compileJavascript.js +89 -31
  32. package/dist/build/createClientFiles.d.ts +1 -1
  33. package/dist/build/createClientFiles.d.ts.map +1 -1
  34. package/dist/build/createClientFiles.js +7 -7
  35. package/dist/build/createInstanceConfigFile.d.ts +1 -1
  36. package/dist/build/createInstanceConfigFile.d.ts.map +1 -1
  37. package/dist/build/createInstanceConfigFile.js +3 -3
  38. package/dist/build/makeBabelUserDevConfig.d.ts +1 -1
  39. package/dist/build/makeBabelUserDevConfig.d.ts.map +1 -1
  40. package/dist/build/makeBabelUserDevConfig.js +3 -1
  41. package/dist/findUserConfig.d.ts +1 -1
  42. package/dist/findUserConfig.d.ts.map +1 -1
  43. package/dist/findUserConfig.js +2 -2
  44. package/dist/frameworkConfigSchema.d.ts +4 -0
  45. package/dist/frameworkConfigSchema.d.ts.map +1 -1
  46. package/dist/frameworkConfigSchema.js +1 -0
  47. package/dist/getUserConfig.d.ts +1 -1
  48. package/dist/getUserConfig.d.ts.map +1 -1
  49. package/dist/getUserConfig.js +2 -2
  50. package/dist/hooks/useState.js +1 -1
  51. package/dist/indexInner.d.ts +0 -1
  52. package/dist/indexInner.d.ts.map +1 -1
  53. package/dist/indexInner.js +1 -1
  54. package/dist/postcssPlugins/parseSelectorsRich.sxyt.js +5 -2
  55. package/dist/testing/createTestApp.sxyt.d.ts +2 -0
  56. package/dist/testing/createTestApp.sxyt.d.ts.map +1 -0
  57. package/dist/testing/createTestApp.sxyt.js +424 -0
  58. package/dist/testing/ensureTestEnvLoaded.d.ts +2 -0
  59. package/dist/testing/ensureTestEnvLoaded.d.ts.map +1 -0
  60. package/dist/testing/ensureTestEnvLoaded.js +19 -0
  61. package/dist/testing/index.d.ts +36 -0
  62. package/dist/testing/index.d.ts.map +1 -0
  63. package/dist/testing/index.js +156 -0
  64. package/dist/update/UpdateScheduler.d.ts +17 -0
  65. package/dist/update/UpdateScheduler.d.ts.map +1 -0
  66. package/dist/update/UpdateScheduler.js +113 -0
  67. package/dist/update/integrateUpdateVdom.d.ts +11 -1
  68. package/dist/update/integrateUpdateVdom.d.ts.map +1 -1
  69. package/dist/update/integrateUpdateVdom.js +117 -59
  70. package/dist/{react-zone.d.ts → zones/react.d.ts} +5 -5
  71. package/dist/zones/react.d.ts.map +1 -0
  72. package/dist/{react-zone.js → zones/react.js} +3 -3
  73. package/package.json +4 -2
  74. package/readme.md +102 -1
  75. package/dist/react-zone.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tungsten",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,7 +9,8 @@
9
9
  "main": "dist/index.js",
10
10
  "exports": {
11
11
  ".": "./dist/index.js",
12
- "./react-zone": "./dist/react-zone.js",
12
+ "./react-zone": "./dist/zones/react.js",
13
+ "./testing": "./dist/testing/index.js",
13
14
  "./*": "./dist/*",
14
15
  "./types/*": "./types/*"
15
16
  },
@@ -123,6 +124,7 @@
123
124
  "eslint-import-resolver-typescript": "^2.7.1",
124
125
  "eslint-plugin-import": "^2.32.0",
125
126
  "eslint-plugin-no-type-assertion": "^1.3.0",
127
+ "happy-dom": "^20.10.6",
126
128
  "progress-webpack-plugin": "^1.0.16",
127
129
  "prop-types": "^15.8.1",
128
130
  "rimraf": "^5.0.10",
package/readme.md CHANGED
@@ -2,6 +2,71 @@
2
2
 
3
3
  [Docs](https://robertsandiford.co.uk/tungsten)
4
4
 
5
+ ## Component testing
6
+
7
+ Test-specific APIs are available from `tungsten/testing` and are not exported
8
+ from Tungsten's main entry point. A test project supplies its own DOM
9
+ implementation, such as happy-dom or jsdom:
10
+
11
+ ```tsx
12
+ import { Window } from 'happy-dom'
13
+ import { createTestApp } from 'tungsten/testing'
14
+
15
+ describe('RootComponent', () => {
16
+ it('responds to a button click', async () => {
17
+ const window = new Window()
18
+ const testApp = await createTestApp(RootComponent, {
19
+ document: window.document as unknown as Document,
20
+ props: { initialName: 'Robert' },
21
+ location: '/',
22
+ })
23
+
24
+ try {
25
+ const button = testApp.container.querySelector('button')
26
+ expect(button).not.toBeNull()
27
+
28
+ button!.dispatchEvent(new window.Event('click') as unknown as Event)
29
+ await testApp.resolved()
30
+
31
+ expect(testApp.container.textContent).toContain('Robert')
32
+ } finally {
33
+ await testApp.unmount()
34
+ }
35
+ })
36
+ })
37
+ ```
38
+
39
+ The casts are only needed when a DOM package publishes types which are not
40
+ structurally compatible with the TypeScript DOM library version used by the
41
+ test project.
42
+
43
+ `createTestApp()` completes the initial client render before returning.
44
+ `resolved()` subsequently waits for Tungsten updates, DOM reconciliation,
45
+ lifecycle-triggered updates, and promises returned by registered event
46
+ handlers. It does not wait for unrelated timers, network requests, or promises
47
+ which the application has not returned to Tungsten.
48
+
49
+ An automatically created container is appended to the supplied document body
50
+ and removed by `unmount()`. A caller-supplied container must be empty; it is
51
+ emptied but retained during unmount.
52
+
53
+ Registered stores are created independently for each test application. Use
54
+ `testStore()` to initialize one before the root component starts:
55
+
56
+ ```ts
57
+ import { createTestApp, testStore } from 'tungsten/testing'
58
+
59
+ const testApp = await createTestApp(RootComponent, {
60
+ document,
61
+ stores: [testStore(userStore, store => {
62
+ store.user.set(mockUser)
63
+ })],
64
+ })
65
+ ```
66
+
67
+ Tests containing Tungsten JSX must be compiled through `tungsten compile` so
68
+ they use Tungsten's JSX runtime and application transforms.
69
+
5
70
  ## Preparing code for tests
6
71
 
7
72
  Run a one-shot development compilation without starting a server:
@@ -16,6 +81,17 @@ transforms), stylesheets, client support files, assets, and public files into
16
81
  Each selected target's existing generated output is cleaned before the initial
17
82
  compilation, including when watch mode is used. Pass `--no-clean` to preserve
18
83
  existing output.
84
+
85
+ Use `--output` to select an independent output root. The layout below that root
86
+ is the same as `.tungsten/dev`, including `code`, `.client`, `.static`,
87
+ `.assets`, `.public`, `.componentCss`, and `.packages`:
88
+
89
+ ```sh
90
+ tungsten compile --output .tungsten/test
91
+ tungsten compile --output .tungsten/test --watch
92
+ ```
93
+
94
+ Cleaning and generated package-cache data are scoped to the selected output.
19
95
  Limit the work with one or more options:
20
96
 
21
97
  ```sh
@@ -27,7 +103,7 @@ tungsten compile --public
27
103
  tungsten compile --js --css
28
104
  ```
29
105
 
30
- `--all` explicitly selects all three targets.
106
+ `--all` explicitly selects all five targets.
31
107
 
32
108
  Add `--watch` to keep the JavaScript, stylesheet, asset, and/or public-file
33
109
  compiler running after the initial pass. Client support files are still
@@ -37,3 +113,28 @@ generated once:
37
113
  tungsten compile --watch
38
114
  tungsten compile --js --watch
39
115
  ```
116
+
117
+ For process orchestration, `--ready-file <file>` writes a small JSON file only
118
+ after the initial compilation succeeds. A failed JavaScript watch cycle removes
119
+ the file, and a later successful cycle recreates it. `--quiet` suppresses
120
+ per-file transformation messages while retaining errors and cycle status:
121
+
122
+ ```sh
123
+ tungsten compile --watch --output .tungsten/test \
124
+ --ready-file .tungsten/test.ready --quiet
125
+ ```
126
+
127
+ ## Preserving package imports in selected files
128
+
129
+ Use `skipPackageCompilation` in `tungsten.config.js` for files that should be
130
+ transformed and emitted without Tungsten traversing or copying their package
131
+ dependencies. Bare package imports in matching files are left unchanged:
132
+
133
+ ```js
134
+ export default {
135
+ skipPackageCompilation: '**/*.domTest.js'
136
+ }
137
+ ```
138
+
139
+ The option accepts one glob or an array of globs. Patterns match the actual
140
+ JavaScript files received by Tungsten; extensions are not translated.
@@ -1 +0,0 @@
1
- {"version":3,"file":"react-zone.d.ts","sourceRoot":"","sources":["../src/react-zone.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAoB,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD,MAAM,MAAM,kBAAkB,CAAC,KAAK,SAAS,MAAM,IAC7C,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,GAC3B,CAAC,KAAK,GAAG,IAAI,EAAE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