mike-works / typescript-fundamentals

Mike North's 2018 TypeScript Fundamentals Course
https://frontendmasters.com/courses/typescript/
BSD 3-Clause "New" or "Revised" License
874 stars 731 forks source link

Replace mocha.opts file with .mocharc.json configuration file #1052

Open myang5 opened 3 years ago

myang5 commented 3 years ago

Is your feature request related to a problem? Please describe. This is related to a bug I ran into! The current challenges rely on a mocha.opts file to specify mocha flags. However, this method of specifying options has been deprecated, which prevents me from running tests (specified in Additional context section).

Describe the solution you'd like I was able to create a .mocharc.json configuration file based on the docs that fixes the issue and allows the tests to run, so it would probably help to replace the mocha.opts file with that.

challenges/address-book/.mocharc.json:

{
  "require": ["ts-node/register", "source-map-support/register"],
  "timeout": 60000,
  "extension": ["js", "ts", "json"],
  "spec": "test/**/*.test.ts"
}

Describe alternatives you've considered The mocha version in the package.json could use semver to specify an older version that allows for the mocha.opts file, but replacing the configuration file to keep up with newer mocha versions seems more reasonable.

Additional context This is the error I initially got when I ran yarn test in the challenges/address-book folder:

$ yarn test
yarn run v1.22.5
$ mocha
Error: No test files found
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I then tried to edit the test script in the package.json from just "mocha" to "mocha --opts test/mocha.opts" because I thought it would work with the older mocha version, but I still got an error:

× ERROR: --opts: configuring Mocha via 'mocha.opts' is DEPRECATED and no longer supported.
          Please use a configuration file instead.
error Command failed with exit code 1.

After this I made the configuration file.

CodeSchwert commented 3 years ago

+1 for this, I had to setup the same config to get the mocha tests to work.