Skip to content

fix(tests): Make .mocharc.js independent of current working directory#7329

Merged
cpcallen merged 1 commit intoRaspberryPiFoundation:developfrom
cpcallen:fix/mocha
Jul 31, 2023
Merged

fix(tests): Make .mocharc.js independent of current working directory#7329
cpcallen merged 1 commit intoRaspberryPiFoundation:developfrom
cpcallen:fix/mocha

Conversation

@cpcallen
Copy link
Copy Markdown
Collaborator

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide
  • I ran npm run format and npm run lint

The details

Resolves

Fixes difficulties with running individual tests via npx mocha path/to/test_file.js

Proposed Changes

Move tests/browser/test/.mocharc.js to tests/browser and use __dirname to make the require directive work regardless of where mocha is invoked from.

Simplify the browser:test script accordingly, taking advantage also of the mocha default of running all tests in the test/ subdirectory.

Behaviour Before Change

It was necessary to be in the repository root, and specify --config tests/browser/test/.mocharc.js in order to successfully invoke mocha on any/all of the files in tests/browser/test.

Behaviour After Change

The previous way works, but it's also possible to npx mocha path/to/test_file.js from anywhere in browser/tests/

Reason for Changes

Convenience when developing tests.

Test Coverage

Unchanged.

Move tests/browser/test/.mocharc.js to tests/browser and use
__dirname to make the require directive work regardless of where
mocha is invoked from.

Simplify the browser:test script accordingly, taking advantage
also of the mocha default of running all tests in the test/
subdirectory.
@cpcallen cpcallen requested a review from a team as a code owner July 27, 2023 17:19
@cpcallen cpcallen requested a review from NeilFraser July 27, 2023 17:19
@github-actions github-actions bot added the PR: fix Fixes a bug label Jul 27, 2023
@cpcallen cpcallen requested review from rachel-fenichel and removed request for NeilFraser July 27, 2023 17:38
"tsc": "gulp tsc",
"test": "gulp test",
"test:browser": "npx mocha ./tests/browser/test --config ./tests/browser/test/.mocharc.js",
"test:browser": "cd tests/browser && npx mocha",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding && cd .. to get back to the original directory after running the command.

@cpcallen cpcallen merged commit 8893107 into RaspberryPiFoundation:develop Jul 31, 2023
@cpcallen cpcallen deleted the fix/mocha branch July 31, 2023 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants