Skip to content

Commit 97b578f

Browse files
committed
Performance tests use run_bundler.mjs
1 parent 5b57923 commit 97b578f

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

scripts/run_bundler.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ import PROJECT_ROOT_DIRECTORY from "./utils/project_root_directory.mjs";
3434
* @param {boolean} [options.silent] - If `true`, we won't output logs.
3535
* @param {string} [options.outfile] - Destination of the produced es2017
3636
* bundle. To ignore to skip ES2017 bundle generation.
37+
* @param {Object} [options.globals] - Optional globally-defined identifiers, as
38+
* a key-value objects, where the object is a string (trick: if you want to
39+
* replace an identifier with a string, call `JSON.stringify` on it).
3740
* @returns {Promise}
3841
*/
3942
export default async function runBundler(inputFile, options) {
@@ -43,6 +46,7 @@ export default async function runBundler(inputFile, options) {
4346
const isDevMode = !options.production;
4447
const isSilent = options.silent;
4548
const outfile = options.outfile;
49+
const globals = options.globals;
4650
const relativeInFile = path.relative(PROJECT_ROOT_DIRECTORY, inputFile);
4751
const relativeOutfile =
4852
outfile === undefined
@@ -105,6 +109,7 @@ export default async function runBundler(inputFile, options) {
105109
}),
106110
__LOGGER_LEVEL__: JSON.stringify({ CURRENT_LEVEL: isDevMode ? "INFO" : "NONE" }),
107111
__GLOBAL_SCOPE__: JSON.stringify(globalScope),
112+
...globals,
108113
},
109114
});
110115
if (watch) {

tests/performance/run.mjs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
/* eslint-env node */
33

44
import { exec, spawn } from "child_process";
5-
import esbuild from "esbuild";
65
import * as fs from "fs/promises";
76
import { createServer } from "http";
87
import * as path from "path";
98
import { fileURLToPath, pathToFileURL } from "url";
109
import launchStaticServer from "../../scripts/launch_static_server.mjs";
1110
import removeDir from "../../scripts/utils/remove_dir.mjs";
11+
import runBundler from "../../scripts/run_bundler.mjs";
1212
import createContentServer from "../contents/server.mjs";
1313
import { rmSync, writeFileSync } from "fs";
1414

@@ -465,7 +465,7 @@ async function initializePerformanceTestsPages({ branchName, remoteGitUrl }) {
465465
*/
466466
async function prepareCurrentRxPlayerTests() {
467467
await linkCurrentRxPlayer();
468-
await createBundle({ output: "current.js", minify: false, production: true });
468+
await createBundle({ output: "current.js", minify: true, production: true });
469469
}
470470

471471
/**
@@ -480,7 +480,7 @@ async function prepareCurrentRxPlayerTests() {
480480
*/
481481
async function prepareLastRxPlayerTests({ branchName, remoteGitUrl }) {
482482
await linkRxPlayerBranch({ branchName, remoteGitUrl });
483-
await createBundle({ output: "previous.js", minify: false, production: true });
483+
await createBundle({ output: "previous.js", minify: true, production: true });
484484
}
485485

486486
/**
@@ -981,35 +981,26 @@ function getSamplePerScenarios(samplesObj) {
981981
* in "development" mode, which has supplementary assertions.
982982
* @returns {Promise}
983983
*/
984-
function createBundle(options) {
984+
async function createBundle(options) {
985985
const minify = !!options.minify;
986-
const isDevMode = !options.production;
987-
return esbuild
988-
.build({
989-
entryPoints: [path.join(currentDirectory, "src", "main.js")],
990-
bundle: true,
986+
try {
987+
await runBundler(path.join(currentDirectory, "src", "main.js"), {
991988
minify,
989+
silent: true,
990+
globalScope: false,
991+
production: true,
992+
watch: false,
992993
outfile: path.join(currentDirectory, options.output),
993-
define: {
994+
globals: {
994995
__TEST_CONTENT_SERVER__: JSON.stringify({
995996
URL: "127.0.0.1",
996997
PORT: "3000",
997998
}),
998-
"process.env.NODE_ENV": JSON.stringify(isDevMode ? "development" : "production"),
999-
__ENVIRONMENT__: JSON.stringify({
1000-
PRODUCTION: 0,
1001-
DEV: 1,
1002-
CURRENT_ENV: isDevMode ? 1 : 0,
1003-
}),
1004-
__LOGGER_LEVEL__: JSON.stringify({
1005-
CURRENT_LEVEL: "INFO",
1006-
}),
1007-
__GLOBAL_SCOPE__: JSON.stringify(false),
1008999
},
1009-
})
1010-
.catch((err) => {
1011-
throw new Error(`Demo build failed:`, err);
10121000
});
1001+
} catch (err) {
1002+
throw new Error(`Performance build failed:`, err);
1003+
}
10131004
}
10141005

10151006
/**

0 commit comments

Comments
 (0)