Skip to content

Commit

Permalink
chore: add a test to verify that the preload script runs
Browse files Browse the repository at this point in the history
  • Loading branch information
yu-ogi committed Nov 14, 2024
1 parent 18a2d2a commit cbddfe9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/__tests__/InitialSceneSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ describe("test InitialScene", () => {
};
const assetBundle = `{
assets: {
"/script/preload.js": {
type: "script",
path: "script/preload.js",
preload: true,
execute: (runtimeValue) => {
const { module } = runtimeValue;
const exports = module.exports;
module.exports = () => {
g.game.vars.preloaded = true;
}
return module.exports;
}
},
"/script/module.js": {
type: "script",
path: "script/module.js",
Expand All @@ -37,7 +52,7 @@ describe("test InitialScene", () => {
return module.exports;
}
}
},
},
}`;

Expand All @@ -46,6 +61,8 @@ describe("test InitialScene", () => {
game.resourceFactory.scriptContents["./main.js"] = "module.exports = () => g.game.__entry_point__();";
game.resourceFactory.scriptContents["./asset.bundle.js"] = `module.exports = ${assetBundle}`;
(game as any).__entry_point__ = () => {
expect(game.vars.preloaded).toBe(true); // エントリポイントに先行して /script/preload.js が実行されていることを確認

const assetBundle = game._moduleManager._internalRequire(configuration.assetBundle!);
expect(assetBundle.assets["/script/module.js"]).toBeDefined();
expect(assetBundle.assets["/script/module.js"].type).toBe("script");
Expand Down

0 comments on commit cbddfe9

Please sign in to comment.