Skip to content

Commit

Permalink
refactor: Change UMD global name; add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jcowman2 committed Dec 28, 2018
1 parent a9f7e50 commit 201424d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const makeOutputOpts = (config: LoadedConfiguration) => {
break;
case ModuleFormat.UMD:
output.format = format;
output.name = "GameBundle";
output.name = "Game";
break;
default:
throw new RegalError(`Illegal module format: ${format}`);
Expand Down
38 changes: 4 additions & 34 deletions test/cases/esm/esm.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
import * as path from "path";
import * as fs from "fs";
import { GameApi } from "regal";
import { lines } from "../../test-utils";
import { bundleHeader } from "../../../src/bundle";

// @ts-ignore: import will be resolved
import { bundle } from "../../../dist/regal-bundler.cjs.js";

describe("Case: ESM", () => {
beforeAll(
async () =>
await bundle({
configLocation: __dirname
})
);

it("TODO", async () => {
// @ts-ignore: import will be resolved
// const Game: GameApi = await import("./the-smallest-game.regal.js");
// let response = Game.postStartCommand();
// expect(response.output.wasSuccessful).toBe(true);
// expect(lines(response)).toEqual(["Game initialized to zero."]);
// response = Game.postPlayerCommand(response.instance, "inc");
// expect(response.output.wasSuccessful).toBe(true);
// expect(lines(response)).toEqual([
// "Game state incremented from 0 to 1."
// ]);
// for (let i = 0; i < 5; i++) {
// response = Game.postPlayerCommand(response.instance, "dec");
// }
// expect(response.output.wasSuccessful).toBe(true);
// expect(lines(response)).toEqual([
// "Game state decremented from -3 to -4."
// ]);
// response = Game.postPlayerCommand(response.instance, "woof");
// expect(response.output.wasSuccessful).toBe(true);
// expect(lines(response)).toEqual(["Command not recognized: 'woof'."]);
it("Bundles successfully", async () => {
await bundle({
configLocation: __dirname
});
});
});
1 change: 1 addition & 0 deletions test/cases/umd/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
14 changes: 14 additions & 0 deletions test/cases/umd/regal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"game": {
"name": "My UMD Game",
"author": "Joe Cowman"
},
"bundler": {
"input": {
"file": "../basic/src/index.ts"
},
"output": {
"format": "umd"
}
}
}
13 changes: 13 additions & 0 deletions test/cases/umd/test-umd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>UMD Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="my-umd-game.regal.js"></script>
</head>
<body>

</body>
</html>
39 changes: 39 additions & 0 deletions test/cases/umd/umd.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @ts-ignore: import will be resolved
import { bundle } from "../../../dist/regal-bundler.cjs.js";
import { lines } from "../../test-utils";
import { GameApi } from "regal";

describe("Case: UMD", () => {
beforeAll(async () => {
await bundle({
configLocation: __dirname
});
});

it("Creates a functional bundle", async () => {
// @ts-ignore: import will be resolved
const Game: GameApi = await import("./my-umd-game.regal.js");

let response = Game.postStartCommand();
expect(response.output.wasSuccessful).toBe(true);
expect(lines(response)).toEqual(["Game initialized to zero."]);

response = Game.postPlayerCommand(response.instance, "inc");
expect(response.output.wasSuccessful).toBe(true);
expect(lines(response)).toEqual([
"Game state incremented from 0 to 1."
]);

for (let i = 0; i < 5; i++) {
response = Game.postPlayerCommand(response.instance, "dec");
}
expect(response.output.wasSuccessful).toBe(true);
expect(lines(response)).toEqual([
"Game state decremented from -3 to -4."
]);

response = Game.postPlayerCommand(response.instance, "woof");
expect(response.output.wasSuccessful).toBe(true);
expect(lines(response)).toEqual(["Command not recognized: 'woof'."]);
});
});
2 changes: 1 addition & 1 deletion test/unit/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe("Bundle", () => {

const opts = makeOutputOpts(config);
expect(opts.format).toBe(ModuleFormat.UMD);
expect(opts.name).toBe("GameBundle");
expect(opts.name).toBe("Game");
});

it("Rejects other module formats", () => {
Expand Down

0 comments on commit 201424d

Please sign in to comment.