Skip to content

Commit

Permalink
try to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-bravo-yahoo committed Nov 21, 2024
1 parent 777189c commit babc25c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
"pretest:ci": "npm run build:app",
"test:ci": "mocha --recursive ./test --require ./test/mocha-root-hooks.mjs --reporter mocha-multi-reporters --reporter-options configFile=./test/config/reporter.json",
"build": "npm run build:app && npm run build:sea",
"build:app": "esbuild --bundle ./src/user-entrypoint.mjs --platform=node --outfile=./dist/cli.cjs --format=cjs --inject:./sea/import-meta-url.js --define:import.meta.url=importMetaUrl",
"postbuild:app": "node ./scripts/update-prod-hashbang.mjs",
"build:app": "esbuild --bundle ./src/user-entrypoint.mjs --platform=node --outfile=./dist/cli.cjs --format=cjs --inject:./sea/import-meta-url.js --define:import.meta.url=importMetaUrl --define:process.env.NODE_ENV=\\\"production\\\"",
"build:sea": "node ./sea/build.cjs",
"format": "prettier -w ."
},
Expand Down
15 changes: 0 additions & 15 deletions scripts/update-prod-hashbang.mjs

This file was deleted.

3 changes: 3 additions & 0 deletions src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export async function run(argvInput, _container) {
container = _container;
const logger = container.resolve("logger");
const parseYargs = container.resolve("parseYargs");
if (process.env.NODE_ENV === "production") {
process.removeAllListeners("warning");
}

try {
builtYargs = buildYargs(argvInput);
Expand Down
28 changes: 20 additions & 8 deletions test/general-cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { builtYargs, run } from "../src/cli.mjs";
import { setupTestContainer as setupContainer } from "../src/config/setup-test-container.mjs";
import { f } from "./helpers.mjs";

const __dirname = import.meta.dirname;

describe("cli operations", function () {
let container;

Expand Down Expand Up @@ -126,11 +128,16 @@ describe("cli operations", function () {
});

it("enables nodeJS warnings from the dev entrypoint", async function () {
let stderr = spawnSync("./src/user-entrypoint.mjs", ["warn"], {
const cliPath = path.resolve(__dirname, "../src/user-entrypoint.mjs");
let cli = spawnSync(cliPath, ["warn"], {
encoding: "utf8",
shell: true,
stdio: "pipe",
}).stderr;
// input: "",
timeout: 5000,
// stdio: ["inherit", "pipe", "pipe"],
// shell: true,
});
if (cli.error) throw cli.error;
let stderr = cli.stderr;

// the dev script should emit warnings
expect(stderr).to.include(
Expand All @@ -139,12 +146,17 @@ describe("cli operations", function () {
});

it("suppresses nodeJS warnings from the prod entrypoint", async function () {
let stderr = spawnSync("./dist/cli.cjs", ["warn"], {
const cliPath = path.resolve(__dirname, "../dist/cli.cjs");
let cli = spawnSync(cliPath, ["warn"], {
encoding: "utf8",
shell: true,
stdio: "pipe",
}).stderr;
// input: "",
timeout: 5000,
// stdio: ["inherit", "pipe", "pipe"],
// shell: true,
});
if (cli.error) throw cli.error;

let stderr = cli.stderr;
// the prod one should not
expect(stderr).to.equal("");
});
Expand Down

0 comments on commit babc25c

Please sign in to comment.