mocha icon indicating copy to clipboard operation
mocha copied to clipboard

feat: Add error handling for nonexistent file case with --file option

Open khoaHyh opened this issue 1 year ago • 2 comments

🔎 Overview

Fixes https://github.com/mochajs/mocha/issues/4047

  • Added validation to the file(s) passed in to the --file option by resolving the argument to an absolute path and check for its existence. We now log a warning and exit if the file does not exist.
    • the errors for --require bubble up to the middleware in lib/cli/run.js. See here. This specific error occurs in lib/cli/run-helpers.js in the singleRun method when we load files asynchronously. Since we were lacking error handling there, the errors appeared the way they previously did before these changes.
  • Added a test to assert our changes

Screenshot from 2024-02-07 00-34-30

khoaHyh avatar Jan 24 '24 06:01 khoaHyh

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: khoaHyh / name: Khoa Huynh (cf69df1d2ed1242f3b96607fc64c4674ba395689, f8aedff8fe32a21184374d66ed8a684fbc7ae7f2, 8983b84d1ae4decb010634cc333f8a4565ff3174, 4aad1845eeb666ee1054eccc1a3976ff82113229, 645e0b09d891fd20d5b8cec9571ee6e324b3aec2, 842387577330fa074e76ffa4958c2b5fcc641045, 21e566df39660572198d0d70faa456582b8e8d83, bd47d79ff1252fcae4358479c55f8f88da85646e, 909834d5e7500a500c9ad6659251ca86549525da, 9685b82304a7d6804e17e40438b03cb704e24d3f, 1a9f15594af4a061cd35ac081aae8e8f444b255d, b6d6dc2ce7b149f3eeb410c320841f90c5c58a9d, ea092bed0e4d33eacedb5deefe8b9c5239351c43, dce26f41a32212fc20723aad68176814d3faecc5, 9b3d5d21a0f6810c2ef73b9fa1d2bc3ea7d01929, 0e1e84a7c0dde8c1e3680a6c9dcb7b749f72bfcf, b905d215f272843a460dc18cd8f4826f91e6dd64, bad240d83b9e12e9e03a7be743665518aa1f5b8c, 4c9f31888e99281415e7754d638a576ed6f5de7c, a6bdef46b872293173d89d94cd3deccfe914877f, 6d4170ed2f6d74d3b2c4f362046432a4e633aaba, c82c87430c28d24f0d919b9fe9e60b6d57940feb, d6f49b9e1731ce0f4e4f6f68e09ef6e112434c5a, ff58b196353cf8d456a873d8b0c2f5dbe5bca993, 0d6f9c4df00fe4a396f693e7f7eb2582fc479aec, 5c076cde7bbdbea8993e2978740be86191bed39d, 3ec3dcd65fb2c4306723dec3de37eeb6a5762dba, ffdf2d6dc5943f5975673d72936c314085436e05)
  • :white_check_mark: login: voxpelli / name: Pelle Wessman (118fa4ccec39b917cf34baf0951ced7b1a3814ce)

Coverage Status

coverage: 94.257% (-0.1%) from 94.358% when pulling 1a9f15594af4a061cd35ac081aae8e8f444b255d on khoaHyh:issue/4047 into 472a8be14f9b578c8b1ef3e6ae05d06fc2d9891b on mochajs:master.

coveralls avatar Feb 07 '24 19:02 coveralls

Oh! It did, sorry and thank you!

JoshuaKGoldberg avatar May 30 '24 19:05 JoshuaKGoldberg

Looks like one test is failing, can you take a look?

That was my bad, I forgot to pass the mocha instance as a parameter to the handleUnmatchedFiles helper function. I also see the netlify/mocha/deploy-preview is failing, anything on my end I should do?

khoaHyh avatar Jun 18 '24 17:06 khoaHyh

I also see the netlify/mocha/deploy-preview is failing, anything on my end I should do?

You can ignore that - it's a separate issue from this PR on our end.

JoshuaKGoldberg avatar Jun 22 '24 22:06 JoshuaKGoldberg

Note: I switched this to a fix: as it's more of a fix around improper inputs than a fully fledged feature. It doesn't specifically need a minor version bump. A patch would suffice.

JoshuaKGoldberg avatar Jun 25 '24 06:06 JoshuaKGoldberg

Thanks for stepping in and merging @JoshuaKGoldberg 🙏 🙂

voxpelli avatar Jun 25 '24 07:06 voxpelli