Skip to content

Commit

Permalink
Test case for #69
Browse files Browse the repository at this point in the history
  • Loading branch information
btd committed Apr 3, 2020
1 parent a5ed8b3 commit 1f69179
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 29 deletions.
85 changes: 56 additions & 29 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let args = require("yargs")
.strict()
.option("all", {
describe: "Build all templates",
boolean: true
boolean: true,
})
.option("open", { describe: "Open browser with stat files", boolean: true })
.option("json", { describe: "Generate json", boolean: true })
Expand All @@ -30,7 +30,7 @@ let args = require("yargs")
for (const t of TEMPLATE) {
args = args.option(t, {
describe: `Build ${t} template`,
boolean: true
boolean: true,
});
}

Expand All @@ -56,25 +56,25 @@ const simpleOptions = {
json: argv.json,
sourcemap: argv.sourcemap,
gzipSize: argv.gzip,
brotliSize: argv.brotli
brotliSize: argv.brotli,
};

const COMMON_PLUGINS = () =>
[
resolve(),
commonJs({
ignoreGlobal: true,
include: "node_modules/**"
include: "node_modules/**",
}),
postcss({
extract: true,
plugins: [
postcssUrl({
url: "inline"
})
]
url: "inline",
}),
],
}),
argv.terser ? terser() : null
argv.terser ? terser() : null,
].filter(Boolean);

const onwarn = (warning, warn) => {
Expand All @@ -89,25 +89,25 @@ const onwarn = (warning, warn) => {
warn(warning);
};

const runBuild = async template => {
const runBuild = async (template) => {
const inputOptions = {
input: `./src/script-${template}.js`,
plugins: [...COMMON_PLUGINS()],
onwarn
onwarn,
};
const outputOptions = {
format: "iife",
dir: "./lib/",
name: "drawChart",
sourcemap: argv.sourcemap
sourcemap: argv.sourcemap,
};

const bundle = await rollup(inputOptions);

await bundle.write(outputOptions);
};

const runBuildDev = async template => {
const runBuildDev = async (template) => {
const input = {};
for (const t of TEMPLATE) {
input[t] = `./src/script-${t}.js`;
Expand All @@ -120,15 +120,15 @@ const runBuildDev = async template => {
title: `test ${template}`,
filename: `stats.${template}${fileExt}`,
template,
...simpleOptions
})
...simpleOptions,
}),
],
onwarn
onwarn,
};
const outputOptions = {
format: "es",
dir: "./temp/",
sourcemap: argv.sourcemap
sourcemap: argv.sourcemap,
};

const bundle = await rollup(inputOptions);
Expand All @@ -139,7 +139,7 @@ const runBuildDev = async template => {
const runBuildTest_e2e = async (template = "treemap") => {
const input = {
input: "./test/e2e/input.js",
input2: "./test/e2e/input2.js"
input2: "./test/e2e/input2.js",
};

const inputOptions = {
Expand All @@ -151,15 +151,15 @@ const runBuildTest_e2e = async (template = "treemap") => {
title: "test e2e",
filename: `stats.e2e${fileExt}`,
template,
...simpleOptions
})
...simpleOptions,
}),
],
onwarn
onwarn,
};
const outputOptions = {
format: "es",
dir: "./temp/",
sourcemap: argv.sourcemap
sourcemap: argv.sourcemap,
};

const bundle = await rollup(inputOptions);
Expand All @@ -172,7 +172,7 @@ const runBuildTest_gh59 = async () => {
index: "test/gh59/src/index",
"components/index": "test/gh59/src/components/index",
"components/A": "test/gh59/src/components/A",
"components/B": "test/gh59/src/components/B"
"components/B": "test/gh59/src/components/B",
};

const inputOptions = {
Expand All @@ -182,15 +182,41 @@ const runBuildTest_gh59 = async () => {
title: "test gh59",
filename: `stats.gh59${fileExt}`,
template: "treemap",
...simpleOptions
})
...simpleOptions,
}),
],
onwarn
onwarn,
};
const outputOptions = {
format: "es",
dir: "./temp/",
sourcemap: argv.sourcemap
sourcemap: argv.sourcemap,
};

const bundle = await rollup(inputOptions);

await bundle.write(outputOptions);
};

const runBuildTest_gh69 = async () => {
const input = "test/gh69/main.js";

const inputOptions = {
input,
plugins: [
require("./")({
title: "test gh69",
filename: `stats.gh69${fileExt}`,
template: "treemap",
...simpleOptions,
}),
],
onwarn,
};
const outputOptions = {
format: "es",
dir: "./temp/",
sourcemap: argv.sourcemap,
};

const bundle = await rollup(inputOptions);
Expand All @@ -199,15 +225,16 @@ const runBuildTest_gh59 = async () => {
};

const run = async () => {
await Promise.all(TEMPLATE.map(t => runBuild(t)));
await Promise.all(TEMPLATE.map((t) => runBuild(t)));
if (argv.dev) {
await Promise.all(templatesToBuild.map(t => runBuildDev(t)));
await Promise.all(templatesToBuild.map((t) => runBuildDev(t)));
}
if (argv.e2e) {
await Promise.all(templatesToBuild.map(t => runBuildTest_e2e(t)));
await Promise.all(templatesToBuild.map((t) => runBuildTest_e2e(t)));
}
if (argv.test) {
await runBuildTest_gh59();
await runBuildTest_gh69();
}
};

Expand Down
3 changes: 3 additions & 0 deletions test/gh69/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parserOptions:
sourceType: module

3 changes: 3 additions & 0 deletions test/gh69/dynamic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as lib from "./lib.js";

lib.bar();
7 changes: 7 additions & 0 deletions test/gh69/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function foo() {
console.log("foo()");
}

export function bar() {
console.log("bar()");
}
8 changes: 8 additions & 0 deletions test/gh69/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { foo } from "./lib.js";

async function main() {
foo();
await import("./dynamic.js");
}

main();

0 comments on commit 1f69179

Please sign in to comment.