tungsten 0.3.2 → 0.3.3
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/dist/.build-complete +1 -0
- package/dist/Framework.d.ts +2 -0
- package/dist/Framework.d.ts.map +1 -1
- package/dist/Framework.js +68 -57
- package/dist/FrameworkConfig.d.ts +2 -0
- package/dist/FrameworkConfig.d.ts.map +1 -1
- package/dist/Instance/Instance.d.ts.map +1 -1
- package/dist/Instance/Instance.js +18 -1
- package/dist/Instance/InstanceConfig.d.ts +1 -0
- package/dist/Instance/InstanceConfig.d.ts.map +1 -1
- package/dist/PopMessage.type.d.ts +6 -0
- package/dist/PopMessage.type.d.ts.map +1 -0
- package/dist/PopMessage.type.js +1 -0
- package/dist/Servers/DevServer.d.ts +2 -0
- package/dist/Servers/DevServer.d.ts.map +1 -1
- package/dist/Servers/DevServer.js +84 -8
- package/dist/Servers/MatchedRouteInfo.d.ts +1 -1
- package/dist/Servers/MatchedRouteInfo.d.ts.map +1 -1
- package/dist/Servers/ProdServer.d.ts +1 -0
- package/dist/Servers/ProdServer.d.ts.map +1 -1
- package/dist/Servers/ProdServer.js +79 -5
- package/dist/Servers/hono/DevServerHono.js +25 -29
- package/dist/Servers/hono/ProdServerHono.js +49 -142
- package/dist/Servers/hono/TungstenServerHono.d.ts +1 -1
- package/dist/Servers/hono/TungstenServerHono.d.ts.map +1 -1
- package/dist/Servers/hono/TungstenServerHono.js +12 -29
- package/dist/Servers/routing.d.ts.map +1 -1
- package/dist/Servers/routing.js +10 -6
- package/dist/Servers/tungstenCorePrivateEnvSchema.d.ts +0 -3
- package/dist/Servers/tungstenCorePrivateEnvSchema.d.ts.map +1 -1
- package/dist/Servers/tungstenCorePrivateEnvSchema.js +3 -3
- package/dist/Servers/tungstenCorePublicEnvSchema.d.ts +8 -0
- package/dist/Servers/tungstenCorePublicEnvSchema.d.ts.map +1 -0
- package/dist/Servers/tungstenCorePublicEnvSchema.js +14 -0
- package/dist/Store/InternalStoreSchema.d.ts +2 -0
- package/dist/Store/InternalStoreSchema.d.ts.map +1 -1
- package/dist/Store/InternalStoreSchema.js +1 -0
- package/dist/api/Request.d.ts +1 -1
- package/dist/api/Request.d.ts.map +1 -1
- package/dist/api/Response.d.ts +1 -1
- package/dist/api/Response.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTypes.d.ts +2 -2
- package/dist/babelPlugins/BabelTypes.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTypes.js +0 -1
- package/dist/bin/commands/build.d.ts.map +1 -1
- package/dist/bin/commands/build.js +3 -0
- package/dist/bin/commands/dev.d.ts.map +1 -1
- package/dist/bin/commands/dev.js +15 -4
- package/dist/bin/commands/devmon.d.ts +2 -0
- package/dist/bin/commands/devmon.d.ts.map +1 -0
- package/dist/bin/commands/devmon.js +66 -0
- package/dist/bin/index.d.ts.map +1 -1
- package/dist/bin/index.js +6 -0
- package/dist/booleanAttributeValue.d.ts +21 -0
- package/dist/booleanAttributeValue.d.ts.map +1 -0
- package/dist/booleanAttributeValue.js +23 -0
- package/dist/build/compileJavascript.js +1 -1
- package/dist/build/compileUserApp.d.ts +2 -1
- package/dist/build/compileUserApp.d.ts.map +1 -1
- package/dist/build/compileUserApp.js +8 -7
- package/dist/build/createInstanceConfigFile.js +1 -1
- package/dist/compat/types.d.ts +1 -1
- package/dist/compat/types.d.ts.map +1 -1
- package/dist/components/PopMessages.d.ts +12 -0
- package/dist/components/PopMessages.d.ts.map +1 -0
- package/dist/components/PopMessages.js +45 -0
- package/dist/defaultConfig.d.ts +1 -0
- package/dist/defaultConfig.d.ts.map +1 -1
- package/dist/defaultConfig.js +2 -1
- package/dist/env/Interfaces.d.ts +2 -1
- package/dist/env/Interfaces.d.ts.map +1 -1
- package/dist/env/getEnvSchemas.d.ts +1 -1
- package/dist/env/getEnvSchemas.d.ts.map +1 -1
- package/dist/env/publicEnv.d.ts.map +1 -1
- package/dist/env/publicEnv.js +4 -1
- package/dist/frameworkConfigSchema.d.ts +4 -0
- package/dist/frameworkConfigSchema.d.ts.map +1 -1
- package/dist/frameworkConfigSchema.js +2 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useInstance.d.ts +3 -0
- package/dist/hooks/useInstance.d.ts.map +1 -0
- package/dist/hooks/useInstance.js +4 -0
- package/dist/hydrate/hydrate.d.ts +6 -4
- package/dist/hydrate/hydrate.d.ts.map +1 -1
- package/dist/hydrate/hydrate.js +51 -13
- package/dist/hydrate/reconcileHydratedAttributes.d.ts.map +1 -1
- package/dist/hydrate/reconcileHydratedAttributes.js +4 -3
- package/dist/hydrate/renderHydrationMismatchBanner.d.ts +7 -0
- package/dist/hydrate/renderHydrationMismatchBanner.d.ts.map +1 -0
- package/dist/hydrate/renderHydrationMismatchBanner.js +69 -0
- package/dist/indexInner.d.ts +8 -0
- package/dist/indexInner.d.ts.map +1 -1
- package/dist/indexInner.js +7 -1
- package/dist/makeInstanceConfigFromFrameworkConfig.d.ts.map +1 -1
- package/dist/makeInstanceConfigFromFrameworkConfig.js +2 -1
- package/dist/pop.d.ts +10 -0
- package/dist/pop.d.ts.map +1 -0
- package/dist/pop.js +49 -0
- package/dist/rawHtml/filterContentNode.d.ts +20 -0
- package/dist/rawHtml/filterContentNode.d.ts.map +1 -0
- package/dist/rawHtml/filterContentNode.js +96 -0
- package/dist/rawHtml/parseHtml.d.ts +14 -0
- package/dist/rawHtml/parseHtml.d.ts.map +1 -1
- package/dist/rawHtml/parseHtml.js +4 -4
- package/dist/rawHtml/sanitizeHtml.d.ts +17 -0
- package/dist/rawHtml/sanitizeHtml.d.ts.map +1 -0
- package/dist/rawHtml/sanitizeHtml.js +19 -0
- package/dist/render/HeadData.d.ts +1 -0
- package/dist/render/HeadData.d.ts.map +1 -1
- package/dist/render/contentNodeToHtml.d.ts +18 -0
- package/dist/render/contentNodeToHtml.d.ts.map +1 -0
- package/dist/render/contentNodeToHtml.js +66 -0
- package/dist/render/contentToHtml.d.ts.map +1 -1
- package/dist/render/contentToHtml.js +2 -1
- package/dist/render/processHead.d.ts.map +1 -1
- package/dist/render/processHead.js +8 -2
- package/dist/render/renderingTreeToHtml.d.ts.map +1 -1
- package/dist/render/renderingTreeToHtml.js +8 -1
- package/dist/routing/ErrorRouteType.d.ts +6 -0
- package/dist/routing/ErrorRouteType.d.ts.map +1 -0
- package/dist/routing/ErrorRouteType.js +1 -0
- package/dist/routing/RouteTypes.d.ts +2 -1
- package/dist/routing/RouteTypes.d.ts.map +1 -1
- package/dist/routing/Routes.d.ts +5 -0
- package/dist/routing/Routes.d.ts.map +1 -1
- package/dist/routing/TungstenErrorInfo.d.ts +6 -0
- package/dist/routing/TungstenErrorInfo.d.ts.map +1 -0
- package/dist/routing/TungstenErrorInfo.js +6 -0
- package/dist/style/styleContentSxy.js +21 -0
- package/dist/testing/hydrateTestApp.d.ts +38 -0
- package/dist/testing/hydrateTestApp.d.ts.map +1 -0
- package/dist/testing/hydrateTestApp.js +242 -0
- package/dist/testing/index.d.ts +4 -3
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +16 -2
- package/dist/timeProfiler.d.ts +6 -0
- package/dist/timeProfiler.d.ts.map +1 -0
- package/dist/timeProfiler.js +31 -0
- package/dist/update/integrateUpdateVdom.d.ts +11 -0
- package/dist/update/integrateUpdateVdom.d.ts.map +1 -1
- package/dist/update/integrateUpdateVdom.js +9 -3
- package/dist/warnOnFrameworkChange.d.ts.map +1 -1
- package/dist/warnOnFrameworkChange.js +8 -8
- package/package.json +18 -16
- package/dist/FunctionComponentStandIn.sxyt.d.ts +0 -2
- package/dist/FunctionComponentStandIn.sxyt.d.ts.map +0 -1
- package/dist/FunctionComponentStandIn.sxyt.js +0 -52
- package/dist/Instance/gotoRedirect.sxyt.d.ts +0 -2
- package/dist/Instance/gotoRedirect.sxyt.d.ts.map +0 -1
- package/dist/Instance/gotoRedirect.sxyt.js +0 -148
- package/dist/Instance/runTrackedWork.sxyt.d.ts +0 -2
- package/dist/Instance/runTrackedWork.sxyt.d.ts.map +0 -1
- package/dist/Instance/runTrackedWork.sxyt.js +0 -35
- package/dist/Servers/devErrorPageAutoRetry.sxyt.d.ts +0 -2
- package/dist/Servers/devErrorPageAutoRetry.sxyt.d.ts.map +0 -1
- package/dist/Servers/devErrorPageAutoRetry.sxyt.js +0 -117
- package/dist/_client/cjsHelpers.sxyt.d.ts +0 -2
- package/dist/_client/cjsHelpers.sxyt.d.ts.map +0 -1
- package/dist/_client/cjsHelpers.sxyt.js +0 -45
- package/dist/auth/passwordHashing.sxyt.d.ts +0 -2
- package/dist/auth/passwordHashing.sxyt.d.ts.map +0 -1
- package/dist/auth/passwordHashing.sxyt.js +0 -46
- package/dist/auth/ref/checkPasswordResetToken.sxyt.d.ts +0 -2
- package/dist/auth/ref/checkPasswordResetToken.sxyt.d.ts.map +0 -1
- package/dist/auth/ref/checkPasswordResetToken.sxyt.js +0 -40
- package/dist/auth/ref/createPasswordResetToken.sxyt.d.ts +0 -2
- package/dist/auth/ref/createPasswordResetToken.sxyt.d.ts.map +0 -1
- package/dist/auth/ref/createPasswordResetToken.sxyt.js +0 -10
- package/dist/babelPlugins/BabelAddDevCacheBust.sxyt.d.ts +0 -2
- package/dist/babelPlugins/BabelAddDevCacheBust.sxyt.d.ts.map +0 -1
- package/dist/babelPlugins/BabelAddDevCacheBust.sxyt.js +0 -138
- package/dist/babelPlugins/fixImportsInSassErrorMessage.sxyt.d.ts +0 -2
- package/dist/babelPlugins/fixImportsInSassErrorMessage.sxyt.d.ts.map +0 -1
- package/dist/babelPlugins/fixImportsInSassErrorMessage.sxyt.js +0 -108
- package/dist/babelPlugins/transformPackageImports/resolveBareImport.sxyt.d.ts +0 -2
- package/dist/babelPlugins/transformPackageImports/resolveBareImport.sxyt.d.ts.map +0 -1
- package/dist/babelPlugins/transformPackageImports/resolveBareImport.sxyt.js +0 -104
- package/dist/bin/commands/compile.sxyt.d.ts +0 -2
- package/dist/bin/commands/compile.sxyt.d.ts.map +0 -1
- package/dist/bin/commands/compile.sxyt.js +0 -255
- package/dist/build/modifySassImports.sxyt.d.ts +0 -2
- package/dist/build/modifySassImports.sxyt.d.ts.map +0 -1
- package/dist/build/modifySassImports.sxyt.js +0 -55
- package/dist/build/sassImportParser.sxyt.d.ts +0 -2
- package/dist/build/sassImportParser.sxyt.d.ts.map +0 -1
- package/dist/build/sassImportParser.sxyt.js +0 -110
- package/dist/build/scssImportParserChatgpt.sxyt.d.ts +0 -2
- package/dist/build/scssImportParserChatgpt.sxyt.d.ts.map +0 -1
- package/dist/build/scssImportParserChatgpt.sxyt.js +0 -120
- package/dist/clone.sxyt.d.ts +0 -2
- package/dist/clone.sxyt.d.ts.map +0 -1
- package/dist/clone.sxyt.js +0 -24
- package/dist/componentProxyHandlers.sxyt.d.ts +0 -2
- package/dist/componentProxyHandlers.sxyt.d.ts.map +0 -1
- package/dist/componentProxyHandlers.sxyt.js +0 -130
- package/dist/components/RawHtml.sxyt.d.ts +0 -2
- package/dist/components/RawHtml.sxyt.d.ts.map +0 -1
- package/dist/components/RawHtml.sxyt.js +0 -104
- package/dist/components/bindable/BindableSelect.sxyt.d.ts +0 -2
- package/dist/components/bindable/BindableSelect.sxyt.d.ts.map +0 -1
- package/dist/components/bindable/BindableSelect.sxyt.js +0 -186
- package/dist/env/injectEnv.sxyt.d.ts +0 -2
- package/dist/env/injectEnv.sxyt.d.ts.map +0 -1
- package/dist/env/injectEnv.sxyt.js +0 -20
- package/dist/env/parseEnv.sxyt.d.ts +0 -2
- package/dist/env/parseEnv.sxyt.d.ts.map +0 -1
- package/dist/env/parseEnv.sxyt.js +0 -11
- package/dist/findProjectDir.sxyt.d.ts +0 -2
- package/dist/findProjectDir.sxyt.d.ts.map +0 -1
- package/dist/findProjectDir.sxyt.js +0 -82
- package/dist/hmr/applyHmrModule.sxyt.d.ts +0 -2
- package/dist/hmr/applyHmrModule.sxyt.d.ts.map +0 -1
- package/dist/hmr/applyHmrModule.sxyt.js +0 -182
- package/dist/hmr/instanceRegistry.sxyt.d.ts +0 -2
- package/dist/hmr/instanceRegistry.sxyt.d.ts.map +0 -1
- package/dist/hmr/instanceRegistry.sxyt.js +0 -24
- package/dist/hmr/refreshStylesheets.sxyt.d.ts +0 -2
- package/dist/hmr/refreshStylesheets.sxyt.d.ts.map +0 -1
- package/dist/hmr/refreshStylesheets.sxyt.js +0 -46
- package/dist/hydrate/hydrate.sxyt.d.ts +0 -2
- package/dist/hydrate/hydrate.sxyt.d.ts.map +0 -1
- package/dist/hydrate/hydrate.sxyt.js +0 -302
- package/dist/hydrate/reconcileHydratedAttributes.sxyt.d.ts +0 -2
- package/dist/hydrate/reconcileHydratedAttributes.sxyt.d.ts.map +0 -1
- package/dist/hydrate/reconcileHydratedAttributes.sxyt.js +0 -190
- package/dist/importDevModuleWithRetry.sxyt.d.ts +0 -2
- package/dist/importDevModuleWithRetry.sxyt.d.ts.map +0 -1
- package/dist/importDevModuleWithRetry.sxyt.js +0 -104
- package/dist/innerHtmlFromProps.sxyt.d.ts +0 -2
- package/dist/innerHtmlFromProps.sxyt.d.ts.map +0 -1
- package/dist/innerHtmlFromProps.sxyt.js +0 -99
- package/dist/postcssPlugins/parseSelectors.sxyt.d.ts +0 -2
- package/dist/postcssPlugins/parseSelectors.sxyt.d.ts.map +0 -1
- package/dist/postcssPlugins/parseSelectors.sxyt.js +0 -62
- package/dist/postcssPlugins/parseSelectorsRich.sxyt.d.ts +0 -2
- package/dist/postcssPlugins/parseSelectorsRich.sxyt.d.ts.map +0 -1
- package/dist/postcssPlugins/parseSelectorsRich.sxyt.js +0 -155
- package/dist/rawHtml/parseHtml.sxyt.d.ts +0 -2
- package/dist/rawHtml/parseHtml.sxyt.d.ts.map +0 -1
- package/dist/rawHtml/parseHtml.sxyt.js +0 -239
- package/dist/render/getFunctionBodyAsString.sxyt.d.ts +0 -2
- package/dist/render/getFunctionBodyAsString.sxyt.d.ts.map +0 -1
- package/dist/render/getFunctionBodyAsString.sxyt.js +0 -37
- package/dist/render/processHead.sxyt.d.ts +0 -2
- package/dist/render/processHead.sxyt.d.ts.map +0 -1
- package/dist/render/processHead.sxyt.js +0 -93
- package/dist/render/processProps.sxyt.d.ts +0 -2
- package/dist/render/processProps.sxyt.d.ts.map +0 -1
- package/dist/render/processProps.sxyt.js +0 -90
- package/dist/routing/compareRequestToRegex.sxyt.d.ts +0 -2
- package/dist/routing/compareRequestToRegex.sxyt.d.ts.map +0 -1
- package/dist/routing/compareRequestToRegex.sxyt.js +0 -65
- package/dist/routing/getPathPriority.sxyt.d.ts +0 -2
- package/dist/routing/getPathPriority.sxyt.d.ts.map +0 -1
- package/dist/routing/getPathPriority.sxyt.js +0 -24
- package/dist/routing/matchPath.sxyt.d.ts +0 -2
- package/dist/routing/matchPath.sxyt.d.ts.map +0 -1
- package/dist/routing/matchPath.sxyt.js +0 -41
- package/dist/routing/patternToRegex.sxyt.d.ts +0 -2
- package/dist/routing/patternToRegex.sxyt.d.ts.map +0 -1
- package/dist/routing/patternToRegex.sxyt.js +0 -69
- package/dist/routing/splitRequest.sxyt.d.ts +0 -2
- package/dist/routing/splitRequest.sxyt.d.ts.map +0 -1
- package/dist/routing/splitRequest.sxyt.js +0 -47
- package/dist/style/jssToCss.sxyt.d.ts +0 -2
- package/dist/style/jssToCss.sxyt.d.ts.map +0 -1
- package/dist/style/jssToCss.sxyt.js +0 -17
- package/dist/testing/createTestApp.sxyt.d.ts +0 -2
- package/dist/testing/createTestApp.sxyt.d.ts.map +0 -1
- package/dist/testing/createTestApp.sxyt.js +0 -470
- package/dist/testing/ensureTestEnvLoaded.sxyt.d.ts +0 -2
- package/dist/testing/ensureTestEnvLoaded.sxyt.d.ts.map +0 -1
- package/dist/testing/ensureTestEnvLoaded.sxyt.js +0 -20
- package/dist/update/hotSwap.sxyt.d.ts +0 -2
- package/dist/update/hotSwap.sxyt.d.ts.map +0 -1
- package/dist/update/hotSwap.sxyt.js +0 -252
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
|
-
import { expect } from 'chai';
|
|
5
|
-
import { Window } from 'happy-dom';
|
|
6
|
-
import { describe } from 'sxy-test-runner';
|
|
7
|
-
import { TungstenSimpleComponent } from "../Components.js";
|
|
8
|
-
import { Instance } from "../Instance/Instance.js";
|
|
9
|
-
import { initStores } from "../Servers/initStores.js";
|
|
10
|
-
import { UpdateScheduler } from "../update/UpdateScheduler.js";
|
|
11
|
-
import { contentTreeToRenderingTree } from "../render/contentTreeToRenderingTree.js";
|
|
12
|
-
import { renderingNodeToHtml } from "../render/renderingTreeToHtml.js";
|
|
13
|
-
import { DomPointer } from "../DomPointer.js";
|
|
14
|
-
import { hydrateRootComponent } from "./hydrate.js";
|
|
15
|
-
import { WideRenderedContentNodeIsComponent } from "../RenderedContentNode.js";
|
|
16
|
-
import { AnyComponentIsFunctionComponentStandIn } from "../AnyComponent.js";
|
|
17
|
-
import { hotSwapFunctionComponent } from "../update/integrateUpdateVdom.js";
|
|
18
|
-
import { setCurrentInstance } from "../hmr/instanceRegistry.js";
|
|
19
|
-
import { applyHmrModule } from "../hmr/applyHmrModule.js";
|
|
20
|
-
import { jsxs as _jsxs, jsx as _jsx } from "tungsten/jsxRuntime.js";
|
|
21
|
-
const Greeting = ({
|
|
22
|
-
name
|
|
23
|
-
}) => {
|
|
24
|
-
return _jsxs("button", {
|
|
25
|
-
children: ["Hello ", name]
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
Greeting.style = {
|
|
29
|
-
moduleName: 'Greeting',
|
|
30
|
-
tags: {
|
|
31
|
-
button: 'greeting-button'
|
|
32
|
-
},
|
|
33
|
-
classes: {}
|
|
34
|
-
};
|
|
35
|
-
class Root extends TungstenSimpleComponent {
|
|
36
|
-
constructor(...args) {
|
|
37
|
-
super(...args);
|
|
38
|
-
_defineProperty(this, "content", () => _jsx(Greeting, {
|
|
39
|
-
name: "Ada"
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function makeInstance(document, runtimeContext) {
|
|
44
|
-
const location = '/';
|
|
45
|
-
const globalData = {};
|
|
46
|
-
const matchedRouteInfo = {
|
|
47
|
-
key: null,
|
|
48
|
-
params: {},
|
|
49
|
-
content: null
|
|
50
|
-
};
|
|
51
|
-
const {
|
|
52
|
-
internalStore,
|
|
53
|
-
stores,
|
|
54
|
-
storeSubscriptions
|
|
55
|
-
} = initStores(location, null, globalData, matchedRouteInfo);
|
|
56
|
-
const instanceConfig = {
|
|
57
|
-
prod: false,
|
|
58
|
-
useRootComponent: true,
|
|
59
|
-
clientSideNav: false,
|
|
60
|
-
siteBasePath: '/',
|
|
61
|
-
staticSite: false
|
|
62
|
-
};
|
|
63
|
-
const emptyRoutes = {}; // eslint-disable-line no-type-assertion/no-type-assertion -- not exercised by this test
|
|
64
|
-
return new Instance(location, instanceConfig, null, emptyRoutes, emptyRoutes,
|
|
65
|
-
// eslint-disable-line no-type-assertion/no-type-assertion
|
|
66
|
-
internalStore, stores, storeSubscriptions, globalData, matchedRouteInfo, runtimeContext);
|
|
67
|
-
}
|
|
68
|
-
describe('hydrateRootComponent() - function component styling', ({
|
|
69
|
-
it
|
|
70
|
-
}) => {
|
|
71
|
-
it('keeps the server-rendered class attribute on a styled function component after hydration', async () => {
|
|
72
|
-
const window = new Window();
|
|
73
|
-
const document = window.document; // eslint-disable-line no-type-assertion/no-type-assertion -- happy-dom's Document is structurally compatible
|
|
74
|
-
const bridgedGlobals = globalThis; // eslint-disable-line no-type-assertion/no-type-assertion -- bridging happy-dom's globals onto the global scope
|
|
75
|
-
bridgedGlobals.Node = window.Node;
|
|
76
|
-
bridgedGlobals.Text = window.Text;
|
|
77
|
-
bridgedGlobals.Comment = window.Comment;
|
|
78
|
-
bridgedGlobals.Element = window.Element;
|
|
79
|
-
bridgedGlobals.HTMLElement = window.HTMLElement;
|
|
80
|
-
bridgedGlobals.Document = window.Document;
|
|
81
|
-
bridgedGlobals.document = document;
|
|
82
|
-
bridgedGlobals.window = window;
|
|
83
|
-
// navigation: false on both instances - this test never touches routing, and it sidesteps
|
|
84
|
-
// Instance's popstate listener setup, which reaches for the process-wide `window` global
|
|
85
|
-
// when no runtimeContext is given (isClient.ts caches typeof window at first import, and
|
|
86
|
-
// other test files in this same process import happy-dom, so relying on "no runtimeContext
|
|
87
|
-
// means server" here is not reliable the way it is in the real server/client bundle split)
|
|
88
|
-
const ssrScheduler = new UpdateScheduler();
|
|
89
|
-
const ssrInstance = makeInstance(document, {
|
|
90
|
-
document,
|
|
91
|
-
window: document.defaultView,
|
|
92
|
-
scheduler: ssrScheduler,
|
|
93
|
-
navigation: false
|
|
94
|
-
});
|
|
95
|
-
const tree = await contentTreeToRenderingTree(_jsx(Root, {}), null, ssrInstance, false);
|
|
96
|
-
const headData = {
|
|
97
|
-
found: false,
|
|
98
|
-
instance: ssrInstance,
|
|
99
|
-
clientImportAliases: {},
|
|
100
|
-
importAliases: {},
|
|
101
|
-
compilationLocation: '',
|
|
102
|
-
dev: false,
|
|
103
|
-
tungstenPublicEnv: undefined,
|
|
104
|
-
siteBasePath: '',
|
|
105
|
-
hmr: true
|
|
106
|
-
};
|
|
107
|
-
const html = await renderingNodeToHtml(tree, false, headData, null);
|
|
108
|
-
// styleContentSxy prefixes every tag match with componentBumpClass ('__c__')
|
|
109
|
-
expect(html).to.contain('class="__c__ greeting-button"');
|
|
110
|
-
document.body.innerHTML = html;
|
|
111
|
-
// hydrate exactly the way the client does
|
|
112
|
-
const scheduler = new UpdateScheduler();
|
|
113
|
-
const runtimeContext = {
|
|
114
|
-
document,
|
|
115
|
-
window: document.defaultView,
|
|
116
|
-
scheduler,
|
|
117
|
-
navigation: false
|
|
118
|
-
};
|
|
119
|
-
const hydrateInstance = makeInstance(document, runtimeContext);
|
|
120
|
-
const domPointer = new DomPointer(document.body, 0);
|
|
121
|
-
await hydrateRootComponent(hydrateInstance, Root, domPointer, {
|
|
122
|
-
insideForm: false
|
|
123
|
-
});
|
|
124
|
-
const button = document.body.querySelector('button');
|
|
125
|
-
expect(button?.getAttribute('class')).to.equal('__c__ greeting-button');
|
|
126
|
-
scheduler.dispose();
|
|
127
|
-
ssrScheduler.dispose();
|
|
128
|
-
});
|
|
129
|
-
it('sets __renderedNode during hydration, so a hot-swap can find and replace it', async () => {
|
|
130
|
-
// hydrateFunctionComponent builds its own wrapper independently of the reconciler's
|
|
131
|
-
// equivalent functions in integrateUpdateVdom.ts - those set element.__renderedNode, but
|
|
132
|
-
// hydration never did, so hotSwapPrepare() (which requires it) silently bailed out on
|
|
133
|
-
// every hydrated component in the real client, and applyHmrModule() counted the swap as
|
|
134
|
-
// successful anyway because it didn't check the swap functions' return value. Both are
|
|
135
|
-
// fixed; this reproduces the full round trip end to end.
|
|
136
|
-
const window = new Window();
|
|
137
|
-
const document = window.document; // eslint-disable-line no-type-assertion/no-type-assertion -- happy-dom's Document is structurally compatible
|
|
138
|
-
const bridgedGlobals = globalThis; // eslint-disable-line no-type-assertion/no-type-assertion -- bridging happy-dom's globals onto the global scope
|
|
139
|
-
bridgedGlobals.Node = window.Node;
|
|
140
|
-
bridgedGlobals.Text = window.Text;
|
|
141
|
-
bridgedGlobals.Comment = window.Comment;
|
|
142
|
-
bridgedGlobals.Element = window.Element;
|
|
143
|
-
bridgedGlobals.HTMLElement = window.HTMLElement;
|
|
144
|
-
bridgedGlobals.Document = window.Document;
|
|
145
|
-
bridgedGlobals.document = document;
|
|
146
|
-
bridgedGlobals.window = window;
|
|
147
|
-
const ssrScheduler = new UpdateScheduler();
|
|
148
|
-
const ssrInstance = makeInstance(document, {
|
|
149
|
-
document,
|
|
150
|
-
window: document.defaultView,
|
|
151
|
-
scheduler: ssrScheduler,
|
|
152
|
-
navigation: false
|
|
153
|
-
});
|
|
154
|
-
const tree = await contentTreeToRenderingTree(_jsx(Root, {}), null, ssrInstance, false);
|
|
155
|
-
const headData = {
|
|
156
|
-
found: false,
|
|
157
|
-
instance: ssrInstance,
|
|
158
|
-
clientImportAliases: {},
|
|
159
|
-
importAliases: {},
|
|
160
|
-
compilationLocation: '',
|
|
161
|
-
dev: false,
|
|
162
|
-
tungstenPublicEnv: undefined,
|
|
163
|
-
siteBasePath: '',
|
|
164
|
-
hmr: true
|
|
165
|
-
};
|
|
166
|
-
const html = await renderingNodeToHtml(tree, false, headData, null);
|
|
167
|
-
document.body.innerHTML = html;
|
|
168
|
-
const scheduler = new UpdateScheduler();
|
|
169
|
-
const runtimeContext = {
|
|
170
|
-
document,
|
|
171
|
-
window: document.defaultView,
|
|
172
|
-
scheduler,
|
|
173
|
-
navigation: false
|
|
174
|
-
};
|
|
175
|
-
const hydrateInstance = makeInstance(document, runtimeContext);
|
|
176
|
-
const domPointer = new DomPointer(document.body, 0);
|
|
177
|
-
const rootElement = await hydrateRootComponent(hydrateInstance, Root, domPointer, {
|
|
178
|
-
insideForm: false
|
|
179
|
-
});
|
|
180
|
-
const wrapper = rootElement.__currentContent;
|
|
181
|
-
if (!WideRenderedContentNodeIsComponent(wrapper) || !AnyComponentIsFunctionComponentStandIn(wrapper.element)) {
|
|
182
|
-
throw new Error('expected the hydrated root to directly wrap a single function component');
|
|
183
|
-
}
|
|
184
|
-
const hydratedElement = wrapper.element;
|
|
185
|
-
expect(hydratedElement.__renderedNode).to.not.equal(undefined);
|
|
186
|
-
const NewGreeting = ({
|
|
187
|
-
name
|
|
188
|
-
}) => {
|
|
189
|
-
return _jsxs("button", {
|
|
190
|
-
children: ["Hi there ", name]
|
|
191
|
-
});
|
|
192
|
-
};
|
|
193
|
-
NewGreeting.style = {
|
|
194
|
-
moduleName: 'Greeting',
|
|
195
|
-
tags: {
|
|
196
|
-
button: 'greeting-button'
|
|
197
|
-
},
|
|
198
|
-
classes: {}
|
|
199
|
-
};
|
|
200
|
-
const swapped = await hotSwapFunctionComponent(hydratedElement, NewGreeting);
|
|
201
|
-
expect(swapped).to.not.equal(null);
|
|
202
|
-
expect(document.body.innerHTML).to.contain('Hi there Ada');
|
|
203
|
-
expect(document.body.innerHTML).to.not.contain('Hello Ada');
|
|
204
|
-
scheduler.dispose();
|
|
205
|
-
ssrScheduler.dispose();
|
|
206
|
-
});
|
|
207
|
-
it('end-to-end: SSR -> hydrate -> a real dev-mode edit applies without a full reload', async () => {
|
|
208
|
-
// This is the high-level test for the actual, user-visible bug ("editing a component
|
|
209
|
-
// always triggers a full page reload instead of an in-place swap"). It goes through the
|
|
210
|
-
// real hydrate() -> applyHmrModule() pipeline exactly as the dev-mode reload script does
|
|
211
|
-
// (setCurrentInstance() + applyHmrModule(), not a lower-level helper like
|
|
212
|
-
// hotSwapFunctionComponent() called directly), so it catches applyHmrModule()
|
|
213
|
-
// miscounting a failed swap as successful and hydration never setting __renderedNode in
|
|
214
|
-
// one broad assertion (DOM shows the edited content) rather than two narrow ones.
|
|
215
|
-
//
|
|
216
|
-
// It does NOT cover the third cause (the registration gate checking
|
|
217
|
-
// runtimeContext !== undefined instead of isClient) - this test, like the others in this
|
|
218
|
-
// file, deliberately passes a real runtimeContext to sidestep isClient.ts's module-load-
|
|
219
|
-
// order flakiness in a shared test process, so runtimeContext is always defined here
|
|
220
|
-
// regardless of which gate the source uses. FunctionComponentStandIn.sxyt.ts covers that
|
|
221
|
-
// cause specifically, by forcing isClient directly instead of relying on either detection
|
|
222
|
-
// path.
|
|
223
|
-
const window = new Window();
|
|
224
|
-
const document = window.document; // eslint-disable-line no-type-assertion/no-type-assertion -- happy-dom's Document is structurally compatible
|
|
225
|
-
const bridgedGlobals = globalThis; // eslint-disable-line no-type-assertion/no-type-assertion -- bridging happy-dom's globals onto the global scope
|
|
226
|
-
bridgedGlobals.Node = window.Node;
|
|
227
|
-
bridgedGlobals.Text = window.Text;
|
|
228
|
-
bridgedGlobals.Comment = window.Comment;
|
|
229
|
-
bridgedGlobals.Element = window.Element;
|
|
230
|
-
bridgedGlobals.HTMLElement = window.HTMLElement;
|
|
231
|
-
bridgedGlobals.Document = window.Document;
|
|
232
|
-
bridgedGlobals.document = document;
|
|
233
|
-
bridgedGlobals.window = window;
|
|
234
|
-
const ssrScheduler = new UpdateScheduler();
|
|
235
|
-
const ssrInstance = makeInstance(document, {
|
|
236
|
-
document,
|
|
237
|
-
window: document.defaultView,
|
|
238
|
-
scheduler: ssrScheduler,
|
|
239
|
-
navigation: false
|
|
240
|
-
});
|
|
241
|
-
const tree = await contentTreeToRenderingTree(_jsx(Root, {}), null, ssrInstance, false);
|
|
242
|
-
const headData = {
|
|
243
|
-
found: false,
|
|
244
|
-
instance: ssrInstance,
|
|
245
|
-
clientImportAliases: {},
|
|
246
|
-
importAliases: {},
|
|
247
|
-
compilationLocation: '',
|
|
248
|
-
dev: false,
|
|
249
|
-
tungstenPublicEnv: undefined,
|
|
250
|
-
siteBasePath: '',
|
|
251
|
-
hmr: true
|
|
252
|
-
};
|
|
253
|
-
const html = await renderingNodeToHtml(tree, false, headData, null);
|
|
254
|
-
document.body.innerHTML = html;
|
|
255
|
-
const scheduler = new UpdateScheduler();
|
|
256
|
-
const runtimeContext = {
|
|
257
|
-
document,
|
|
258
|
-
window: document.defaultView,
|
|
259
|
-
scheduler,
|
|
260
|
-
navigation: false
|
|
261
|
-
};
|
|
262
|
-
const hydrateInstance = makeInstance(document, runtimeContext);
|
|
263
|
-
// exactly what hydrate.tsx's real hydrate() does right after constructing its Instance
|
|
264
|
-
setCurrentInstance(hydrateInstance);
|
|
265
|
-
const domPointer = new DomPointer(document.body, 0);
|
|
266
|
-
await hydrateRootComponent(hydrateInstance, Root, domPointer, {
|
|
267
|
-
insideForm: false
|
|
268
|
-
});
|
|
269
|
-
// stands in for "the file was edited and the browser re-imported it fresh" - a
|
|
270
|
-
// same-named export with different markup, exactly like applyHmrModule() receives from
|
|
271
|
-
// the dev-mode reload script
|
|
272
|
-
const EditedGreeting = ({
|
|
273
|
-
name
|
|
274
|
-
}) => {
|
|
275
|
-
return _jsxs("button", {
|
|
276
|
-
children: ["Edited ", name]
|
|
277
|
-
});
|
|
278
|
-
};
|
|
279
|
-
// identity matching is by name, and a const's inferred .name is its own variable name
|
|
280
|
-
// ("EditedGreeting") - force it to match the export name the real dev-mode reload script
|
|
281
|
-
// would see when re-importing the edited file (the export is still called "Greeting")
|
|
282
|
-
Object.defineProperty(EditedGreeting, 'name', {
|
|
283
|
-
value: 'Greeting'
|
|
284
|
-
});
|
|
285
|
-
EditedGreeting.style = {
|
|
286
|
-
moduleName: 'Greeting',
|
|
287
|
-
tags: {
|
|
288
|
-
button: 'greeting-button'
|
|
289
|
-
},
|
|
290
|
-
classes: {}
|
|
291
|
-
};
|
|
292
|
-
const result = await applyHmrModule({
|
|
293
|
-
Greeting: EditedGreeting
|
|
294
|
-
}, '/test/end-to-end-Greeting.tsx');
|
|
295
|
-
expect(result.matched).to.equal(true);
|
|
296
|
-
expect(result.orphaned).to.equal(false);
|
|
297
|
-
expect(document.body.innerHTML).to.contain('Edited Ada');
|
|
298
|
-
expect(document.body.innerHTML).to.not.contain('Hello Ada');
|
|
299
|
-
scheduler.dispose();
|
|
300
|
-
ssrScheduler.dispose();
|
|
301
|
-
});
|
|
302
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reconcileHydratedAttributes.sxyt.d.ts","sourceRoot":"","sources":["../../src/hydrate/reconcileHydratedAttributes.sxyt.ts"],"names":[],"mappings":""}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { describe } from 'sxy-test-runner';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import { Window } from 'happy-dom';
|
|
4
|
-
import { reconcileHydratedAttributes } from "./reconcileHydratedAttributes.js";
|
|
5
|
-
import { $props, $type } from "../contentNodeSymbols.js";
|
|
6
|
-
const window = new Window();
|
|
7
|
-
const node = (type, props) => ({
|
|
8
|
-
[$type]: type,
|
|
9
|
-
[$props]: props
|
|
10
|
-
});
|
|
11
|
-
/** Builds an element from markup the server could have produced. */
|
|
12
|
-
const element = html => {
|
|
13
|
-
const host = window.document.createElement('div');
|
|
14
|
-
host.innerHTML = html;
|
|
15
|
-
// eslint-disable-next-line no-type-assertion/no-type-assertion
|
|
16
|
-
return host.firstElementChild;
|
|
17
|
-
};
|
|
18
|
-
const attributesOf = domNode => Object.fromEntries([...domNode.attributes].map(attribute => [attribute.name, attribute.value]));
|
|
19
|
-
/** Reconciles and returns what changed. */
|
|
20
|
-
const reconcile = (type, props, html) => {
|
|
21
|
-
const domNode = element(html);
|
|
22
|
-
const mismatches = [];
|
|
23
|
-
reconcileHydratedAttributes(node(type, props), domNode, mismatch => mismatches.push(mismatch));
|
|
24
|
-
return {
|
|
25
|
-
domNode,
|
|
26
|
-
mismatches,
|
|
27
|
-
attributes: attributesOf(domNode)
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
describe('reconcileHydratedAttributes()', ({
|
|
31
|
-
it
|
|
32
|
-
}) => {
|
|
33
|
-
it('patches an attribute whose rendered value differs from the markup', () => {
|
|
34
|
-
const {
|
|
35
|
-
attributes,
|
|
36
|
-
mismatches
|
|
37
|
-
} = reconcile('div', {
|
|
38
|
-
style: {
|
|
39
|
-
backgroundColor: '#123456'
|
|
40
|
-
}
|
|
41
|
-
}, '<div style="background-color: #bae3ff;"></div>');
|
|
42
|
-
expect(attributes.style).to.equal('background-color: #123456;');
|
|
43
|
-
expect(mismatches.map(mismatch => mismatch.name)).to.deep.equal(['style']);
|
|
44
|
-
});
|
|
45
|
-
it('leaves a matching attribute untouched and reports nothing', () => {
|
|
46
|
-
const {
|
|
47
|
-
attributes,
|
|
48
|
-
mismatches
|
|
49
|
-
} = reconcile('input', {
|
|
50
|
-
name: 'ref',
|
|
51
|
-
title: 'Reference'
|
|
52
|
-
}, '<input name="ref" title="Reference">');
|
|
53
|
-
expect(attributes).to.deep.equal({
|
|
54
|
-
name: 'ref',
|
|
55
|
-
title: 'Reference'
|
|
56
|
-
});
|
|
57
|
-
expect(mismatches).to.deep.equal([]);
|
|
58
|
-
});
|
|
59
|
-
it('adds an attribute the markup is missing', () => {
|
|
60
|
-
const {
|
|
61
|
-
attributes
|
|
62
|
-
} = reconcile('a', {
|
|
63
|
-
href: '/x',
|
|
64
|
-
title: 't'
|
|
65
|
-
}, '<a href="/x"></a>');
|
|
66
|
-
expect(attributes).to.deep.equal({
|
|
67
|
-
href: '/x',
|
|
68
|
-
title: 't'
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
it('removes an attribute the render no longer produces', () => {
|
|
72
|
-
const {
|
|
73
|
-
attributes,
|
|
74
|
-
mismatches
|
|
75
|
-
} = reconcile('a', {
|
|
76
|
-
href: '/x'
|
|
77
|
-
}, '<a href="/x" title="gone"></a>');
|
|
78
|
-
expect(attributes).to.deep.equal({
|
|
79
|
-
href: '/x'
|
|
80
|
-
});
|
|
81
|
-
expect(mismatches.map(mismatch => mismatch.name)).to.deep.equal(['title']);
|
|
82
|
-
});
|
|
83
|
-
it('treats a true boolean as a present, empty attribute', () => {
|
|
84
|
-
expect(reconcile('button', {
|
|
85
|
-
disabled: true
|
|
86
|
-
}, '<button></button>').attributes).to.deep.equal({
|
|
87
|
-
disabled: ''
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
it('removes an attribute whose rendered value is false, null or undefined', () => {
|
|
91
|
-
expect(reconcile('button', {
|
|
92
|
-
disabled: false
|
|
93
|
-
}, '<button disabled></button>').attributes).to.deep.equal({});
|
|
94
|
-
expect(reconcile('a', {
|
|
95
|
-
href: null
|
|
96
|
-
}, '<a href="/x"></a>').attributes).to.deep.equal({});
|
|
97
|
-
expect(reconcile('a', {
|
|
98
|
-
href: undefined
|
|
99
|
-
}, '<a href="/x"></a>').attributes).to.deep.equal({});
|
|
100
|
-
});
|
|
101
|
-
// The comparison has to apply the same transformation the server used, or
|
|
102
|
-
// every element looks mismatched and the whole document gets rewritten.
|
|
103
|
-
it('applies the server prop transform, so className compares against class', () => {
|
|
104
|
-
const {
|
|
105
|
-
attributes,
|
|
106
|
-
mismatches
|
|
107
|
-
} = reconcile('div', {
|
|
108
|
-
className: 'frame Qtc_frame'
|
|
109
|
-
}, '<div class="frame Qtc_frame"></div>');
|
|
110
|
-
expect(attributes).to.deep.equal({
|
|
111
|
-
class: 'frame Qtc_frame'
|
|
112
|
-
});
|
|
113
|
-
expect(mismatches).to.deep.equal([]);
|
|
114
|
-
});
|
|
115
|
-
it('ignores event handlers rather than writing them as attributes', () => {
|
|
116
|
-
const {
|
|
117
|
-
attributes,
|
|
118
|
-
mismatches
|
|
119
|
-
} = reconcile('input', {
|
|
120
|
-
name: 'a',
|
|
121
|
-
onInput: () => undefined,
|
|
122
|
-
onClick: () => undefined
|
|
123
|
-
}, '<input name="a">');
|
|
124
|
-
expect(attributes).to.deep.equal({
|
|
125
|
-
name: 'a'
|
|
126
|
-
});
|
|
127
|
-
expect(mismatches).to.deep.equal([]);
|
|
128
|
-
});
|
|
129
|
-
it('ignores props that are instructions to Tungsten', () => {
|
|
130
|
-
const {
|
|
131
|
-
attributes,
|
|
132
|
-
mismatches
|
|
133
|
-
} = reconcile('div', {
|
|
134
|
-
__opaque: true,
|
|
135
|
-
dangerouslySetInnerHTML: {
|
|
136
|
-
__html: '<b>x</b>'
|
|
137
|
-
},
|
|
138
|
-
id: 'd'
|
|
139
|
-
}, '<div id="d"></div>');
|
|
140
|
-
expect(attributes).to.deep.equal({
|
|
141
|
-
id: 'd'
|
|
142
|
-
});
|
|
143
|
-
expect(mismatches).to.deep.equal([]);
|
|
144
|
-
});
|
|
145
|
-
// children is rendered content, not an attribute - the server renderer and the client
|
|
146
|
-
// update path both strip it before comparing/writing attributes, and hydration has to
|
|
147
|
-
// match or it writes the stringified child list (e.g. "[object Object],[object Object]")
|
|
148
|
-
// onto every element in the page as a literal "children" attribute.
|
|
149
|
-
it('does not write children as an attribute', () => {
|
|
150
|
-
const {
|
|
151
|
-
attributes,
|
|
152
|
-
mismatches
|
|
153
|
-
} = reconcile('div', {
|
|
154
|
-
id: 'd',
|
|
155
|
-
children: ['a', 'b']
|
|
156
|
-
}, '<div id="d"></div>');
|
|
157
|
-
expect(attributes).to.deep.equal({
|
|
158
|
-
id: 'd'
|
|
159
|
-
});
|
|
160
|
-
expect(mismatches).to.deep.equal([]);
|
|
161
|
-
});
|
|
162
|
-
it('reports what changed, for a dev-mode warning', () => {
|
|
163
|
-
const {
|
|
164
|
-
mismatches
|
|
165
|
-
} = reconcile('a', {
|
|
166
|
-
href: '/new'
|
|
167
|
-
}, '<a href="/old" title="stale"></a>');
|
|
168
|
-
expect(mismatches).to.deep.include({
|
|
169
|
-
name: 'href',
|
|
170
|
-
expected: '/new',
|
|
171
|
-
actual: '/old'
|
|
172
|
-
});
|
|
173
|
-
expect(mismatches).to.deep.include({
|
|
174
|
-
name: 'title',
|
|
175
|
-
expected: null,
|
|
176
|
-
actual: 'stale'
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
it('clears the checked property when removing a checked attribute', () => {
|
|
180
|
-
const domNode = element('<input type="checkbox" checked>');
|
|
181
|
-
// eslint-disable-next-line no-type-assertion/no-type-assertion
|
|
182
|
-
const checkbox = domNode;
|
|
183
|
-
expect(checkbox.checked).to.equal(true);
|
|
184
|
-
reconcileHydratedAttributes(node('input', {
|
|
185
|
-
type: 'checkbox'
|
|
186
|
-
}), domNode);
|
|
187
|
-
expect(checkbox.checked).to.equal(false);
|
|
188
|
-
expect(domNode.hasAttribute('checked')).to.equal(false);
|
|
189
|
-
});
|
|
190
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"importDevModuleWithRetry.sxyt.d.ts","sourceRoot":"","sources":["../src/importDevModuleWithRetry.sxyt.ts"],"names":[],"mappings":""}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import { describe } from 'sxy-test-runner';
|
|
3
|
-
import { mkdtemp, rm, writeFile } from 'fs/promises';
|
|
4
|
-
import { tmpdir } from 'os';
|
|
5
|
-
import { join } from 'path';
|
|
6
|
-
import { importDevModuleWithRetry, isTransientDevModuleError } from "./importDevModuleWithRetry.js";
|
|
7
|
-
function delay(ms) {
|
|
8
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
9
|
-
}
|
|
10
|
-
async function makeFixture() {
|
|
11
|
-
const dir = await mkdtemp(join(tmpdir(), 'tungsten-import-dev-module-retry-'));
|
|
12
|
-
const depPath = join(dir, 'dep.mjs');
|
|
13
|
-
const entryPath = join(dir, 'entry.mjs');
|
|
14
|
-
// dep.mjs never changes - it's the entry file itself that's momentarily
|
|
15
|
-
// stale on disk, exactly like Home.js briefly still reading its
|
|
16
|
-
// pre-rename import statement while Button.js has already been rewritten
|
|
17
|
-
await writeFile(depPath, `export const NewName = 2\n`);
|
|
18
|
-
await writeFile(entryPath, `export { OldName as NewName } from './dep.mjs'\n`);
|
|
19
|
-
return {
|
|
20
|
-
dir,
|
|
21
|
-
depPath,
|
|
22
|
-
entryPath
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
describe('importDevModuleWithRetry()', ({
|
|
26
|
-
it
|
|
27
|
-
}) => {
|
|
28
|
-
it(`rides out a transient module-shape mismatch, succeeding once the entry file itself catches up`, async () => {
|
|
29
|
-
const {
|
|
30
|
-
dir,
|
|
31
|
-
entryPath
|
|
32
|
-
} = await makeFixture();
|
|
33
|
-
try {
|
|
34
|
-
// simulate the entry file's own recompile (e.g. babel finishing
|
|
35
|
-
// its pass over Home.tsx) landing a little after this request
|
|
36
|
-
// started - the exact race this helper exists for
|
|
37
|
-
void delay(150).then(() => writeFile(entryPath, `export { NewName } from './dep.mjs'\n`));
|
|
38
|
-
const module = await importDevModuleWithRetry(`file://${entryPath}`, 10, 50);
|
|
39
|
-
expect(module.NewName).to.equal(2);
|
|
40
|
-
} finally {
|
|
41
|
-
await rm(dir, {
|
|
42
|
-
recursive: true,
|
|
43
|
-
force: true
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
it(`gives up and throws the real error once attempts are exhausted`, async () => {
|
|
48
|
-
const {
|
|
49
|
-
dir,
|
|
50
|
-
entryPath
|
|
51
|
-
} = await makeFixture();
|
|
52
|
-
try {
|
|
53
|
-
let threw = false;
|
|
54
|
-
try {
|
|
55
|
-
await importDevModuleWithRetry(`file://${entryPath}`, 3, 20);
|
|
56
|
-
} catch (e) {
|
|
57
|
-
threw = true;
|
|
58
|
-
expect(String(e)).to.contain('does not provide an export');
|
|
59
|
-
}
|
|
60
|
-
expect(threw).to.equal(true);
|
|
61
|
-
} finally {
|
|
62
|
-
await rm(dir, {
|
|
63
|
-
recursive: true,
|
|
64
|
-
force: true
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
it(`does not retry a genuine, unrelated error - so real bugs still surface immediately`, async () => {
|
|
69
|
-
const dir = await mkdtemp(join(tmpdir(), 'tungsten-import-dev-module-retry-real-error-'));
|
|
70
|
-
try {
|
|
71
|
-
const brokenPath = join(dir, 'broken.mjs');
|
|
72
|
-
await writeFile(brokenPath, `this is not valid javascript {{{\n`);
|
|
73
|
-
const start = Date.now();
|
|
74
|
-
let threw = false;
|
|
75
|
-
try {
|
|
76
|
-
await importDevModuleWithRetry(`file://${brokenPath}`, 10, 200);
|
|
77
|
-
} catch {
|
|
78
|
-
threw = true;
|
|
79
|
-
}
|
|
80
|
-
expect(threw).to.equal(true);
|
|
81
|
-
// a real syntax error must not be retried - if it were, this would
|
|
82
|
-
// take multiple * 200ms delays instead of failing on the first attempt
|
|
83
|
-
expect(Date.now() - start).to.be.lessThan(200);
|
|
84
|
-
} finally {
|
|
85
|
-
await rm(dir, {
|
|
86
|
-
recursive: true,
|
|
87
|
-
force: true
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
describe('isTransientDevModuleError()', ({
|
|
93
|
-
it
|
|
94
|
-
}) => {
|
|
95
|
-
it(`recognizes a bare "X is not defined" ReferenceError - the within-file version of the same race, seen live when a file's JSX still referenced a just-renamed import mid-multi-step-edit`, () => {
|
|
96
|
-
expect(isTransientDevModuleError(new ReferenceError('Button is not defined'))).to.equal(true);
|
|
97
|
-
});
|
|
98
|
-
it('does not match a differently-shaped ReferenceError, to stay a narrow signal', () => {
|
|
99
|
-
expect(isTransientDevModuleError(new ReferenceError('Cannot access X before initialization'))).to.equal(false);
|
|
100
|
-
});
|
|
101
|
-
it('does not match an unrelated TypeError', () => {
|
|
102
|
-
expect(isTransientDevModuleError(new TypeError(`Cannot read properties of undefined (reading 'foo')`))).to.equal(false);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"innerHtmlFromProps.sxyt.d.ts","sourceRoot":"","sources":["../src/innerHtmlFromProps.sxyt.ts"],"names":[],"mappings":""}
|