Skip to content

Commit bbe72b3

Browse files
committed
Added testing for new singleton logic (and caught a typo in the process!)
1 parent 92e3730 commit bbe72b3

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

lib/sharing/ConsumeSharedRuntimeModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
248248
"scopeName, scope, key, fallback",
249249
[
250250
`if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) return fallback();`,
251-
"return getSingletonVersion(scope, scopeName, key);"
251+
"return getSingleton(scope, scopeName, key);"
252252
]
253253
)});`,
254254
`var loadSingletonVersionCheckFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction(

test/configCases/sharing/consume-module/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ it("should handle version matching correctly in strict and singleton mode", asyn
196196
get: () => () => "shared singleton",
197197
from: 'container-a'
198198
}
199+
},
200+
singletonWithoutVersion: {
201+
"1.0.0": {
202+
get: () => () => "shared singleton v1.0.0",
203+
loaded: true
204+
},
205+
"2.0.0": {
206+
get: () => () => "shared singleton v2.0.0"
207+
}
199208
}
200209
};
201210
{
@@ -235,3 +244,21 @@ it("should handle version matching correctly in strict and singleton mode", asyn
235244
);
236245
}
237246
});
247+
248+
it("should not instantiate multiple singletons even if a higher version exists", async () => {
249+
__webpack_share_scopes__["default"] = {
250+
singletonWithoutVersion: {
251+
"1.0.0": {
252+
get: () => () => "shared singleton v1.0.0",
253+
loaded: true
254+
},
255+
"2.0.0": {
256+
get: () => () => "shared singleton v2.0.0"
257+
}
258+
}
259+
};
260+
{
261+
const result = await import("singletonWithoutVersion");
262+
expect(result.default).toBe("shared singleton v1.0.0");
263+
}
264+
});

test/configCases/sharing/consume-module/node_modules/singletonWithoutVersion.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/configCases/sharing/consume-module/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ module.exports = {
5454
requiredVersion: "1.1.0",
5555
singleton: true,
5656
strictVersion: false
57+
},
58+
singletonWithoutVersion: {
59+
requiredVersion: false,
60+
singleton: true
5761
}
5862
}
5963
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy