Skip to content

Commit

Permalink
refactor(bundle): Simplify makeOutputOpts and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcowman2 committed Dec 24, 2018
1 parent 86b006b commit a9f7e50
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ export const makeOutputOpts = (config: LoadedConfiguration) => {
const format = config.bundler.output.format.toLowerCase();
switch (format) {
case ModuleFormat.CJS:
output.format = format;
break;
case ModuleFormat.ESM:
output.format = format;
break;
Expand Down
42 changes: 41 additions & 1 deletion test/unit/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
bundleHeader,
getPlugins,
makeBundler,
esFooter
esFooter,
makeOutputOpts
} from "../../src/bundle";
import { LoadedConfiguration } from "../../src/interfaces-internal";
import standardBundle from "../../src/bundle-standard";
Expand Down Expand Up @@ -141,6 +142,45 @@ describe("Bundle", () => {
});
});

describe("makeOutputOpts", () => {
it("Includes the output file", () => {
const config = sampleConfig();
expect(makeOutputOpts(config).file).toBe(
config.bundler.output.file
);
});

it("Allows CJS module format", () => {
const config = sampleConfig();
config.bundler.output.format = ModuleFormat.CJS;
expect(makeOutputOpts(config).format).toBe(ModuleFormat.CJS);
});

it("Allows ESM module format", () => {
const config = sampleConfig();
config.bundler.output.format = ModuleFormat.ESM;
expect(makeOutputOpts(config).format).toBe(ModuleFormat.ESM);
});

it("Allows UMD module format and sets the output name", () => {
const config = sampleConfig();
config.bundler.output.format = ModuleFormat.UMD;

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

it("Rejects other module formats", () => {
const config = sampleConfig();
(config.bundler.output as any).format = "lars";

expect(() => makeOutputOpts(config)).toThrow(
"RegalError: Illegal module format: lars"
);
});
});

describe("Standard Bundle", () => {
beforeAll(() => {
onStartCommand(game => game.output.write("hi"));
Expand Down

0 comments on commit a9f7e50

Please sign in to comment.