Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative custom reporter to mocha-multi #7931

Merged

Conversation

HarshaNalluru
Copy link
Member

@HarshaNalluru HarshaNalluru commented Mar 21, 2020

Issue

Solution

  • mocha-multi is being used to plug in multiple reporters(spec and junit-reporters specifically) during the test runs
  • To allow mocha@7.0.0 upgrade, build a custom mocha reporter to invoke spec and junit-reporters and not rely on mocha-multi

Changes in this PR

  • Added a new custom mocha reporter under common/tools/ that invokes spec and mocha-junit-reporter (and consequently getting rid of the dependence on mocha-multi)
  • Updated the test-scripts in package.json for all the SDKs to use this new reporter instead of relying on mocha-multi
    • OLD: --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=-
    • NEW: --reporter ../../../common/tools/mocha-multi-reporter.js
  • Removed mocha-multi from the devDependencies for all the SDKs in the repo
  • Removed "ts-mocha": "^6.0.0" for event-hubs which was also causing issues with mocha@7.0
    • (I think ts-mocha was used previously(long back) to run the tests for event-hubs)
  • Updated the unit-test commands of the @azure/eslint-plugin-azure-sdk to fix build failures caused by the missing unit-test:node

@HarshaNalluru HarshaNalluru changed the title Update mocha to 7.0.0 & an alternative custom reporter to mocha-multi Alternative custom reporter to mocha-multi Mar 21, 2020
@HarshaNalluru
Copy link
Member Author

HarshaNalluru commented Mar 21, 2020

Update to mocha@7.0 is working fine in the repo when tested. (#7930)
Though it works, some tests might need a revamp.. Here's an example test failure.

Not upgrading in this PR. Logged #7932

@@ -1,6 +1,5 @@
--require ts-node/register
--timeout 50000
--reporter mocha-multi
--reporter-options spec=-,mocha-junit-reporter=-
--reporter ../../../common/tools/mocha-multi-reporter.js
Copy link
Member Author

@HarshaNalluru HarshaNalluru Mar 21, 2020

Choose a reason for hiding this comment

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

core-arm and core-http packages have mocha.opts file.
TO DO - Remove the mocha.opts file and update test scripts accordingly to stay consistent with the other packages in this repo.

Copy link
Member Author

Choose a reason for hiding this comment

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

Logged #7933

@@ -32,7 +32,7 @@
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
"test": "npm run build:test && npm run unit-test && npm run integration-test",
"unit-test:browser": "echo skipped",
"unit-test:node": "mocha test-dist/**/*.js --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=-",
"unit-test:node": "mocha test-dist/**/*.js --reporter ../../../common/tools/mocha-multi-reporter.js",
Copy link
Member Author

@HarshaNalluru HarshaNalluru Mar 21, 2020

Choose a reason for hiding this comment

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

  • The --reporter options are exactly same for all the SDKs.
  • For local runs - we only need spec reporter and not junit-reporter.
  • spec reporter is the default reporter when we don't specify a reporter.
  • Both junit-reporter and spec reporter are required in the CI.

One proposal to refactor is to move the reporter options to the rush-yaml scripts where we trigger the test scripts instead of package.jsons if possible.
@KarishmaGhiya is checking if rush and our configs allow this. Logged followup #7934

Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! ❤️

common/tools/mocha-multi-reporter.js Outdated Show resolved Hide resolved
"use strict";

const Mocha = require("mocha");
const MochaJUnitReporter = require("mocha-junit-reporter");
Copy link
Member Author

@HarshaNalluru HarshaNalluru Mar 24, 2020

Choose a reason for hiding this comment

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

One thing to note here is that the mocha-multi-reporter.js file is not part of any project/utilities, it is an independent file and doesn't have a package.json of its own.
Placed here(under common/tools/ folder) only so that all the SDKs can leverage.

SDKs are expected to import mocha and mocha-junit-reporter as devDependencies and then use this .js file as the reporter in the mocha test command in package.json.

@@ -49,7 +49,7 @@ packages:
is-buffer: 2.0.4
jssha: 2.3.1
process: 0.11.10
rhea: 1.0.19
rhea: 1.0.20
Copy link
Contributor

Choose a reason for hiding this comment

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

How did removing dependency on mocha-multi result in rhea version getting updated?
Is this a result of running more than just rush update?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is due to rush update --full.

Copy link
Member Author

Choose a reason for hiding this comment

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

If a library is removed, pnpm-lock file is unaffected with rush update.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the guidance was not to run rush update --full as part of regular PRs and that this would be done in frequent intervals by the Eng Sys team. This keeps the changes in the rest of the PR and the changes to lock file in sync

Copy link
Member Author

Choose a reason for hiding this comment

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

pushed!

Copy link
Member

Choose a reason for hiding this comment

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

Is the guidance that we should have a separate PR that only does update --full then? Otherwise we won't be able to shake removed deps out.

Copy link
Member

Choose a reason for hiding this comment

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

If we need to remove a dep ASAP, then yes I would recommend a second PR that only does "update --full". Anyone on the JS team can create such a PR, or you can ask @KarishmaGhiya to do it on your behalf.

Alternatively, @KarishmaGhiya should be running "update --full" about once per week, and in most cases it should be fine to wait until this weekly update to remove unused deps.

Copy link
Member

Choose a reason for hiding this comment

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

Of course, if a PR needs "update --full" to be green, then the PR should include an "update --full" commit in the same PR.

Copy link
Member

Choose a reason for hiding this comment

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

The reason is that update --full updates all packages to semver latest, which often breaks something (and will often be unrelated to any other changes in your PR). So it's safest to isolate update --full into a separate PR and ensure we run core tests on it.

@HarshaNalluru HarshaNalluru requested review from richardpark-msft and removed request for richardpark-msft and XiaoningLiu March 24, 2020 17:05
@HarshaNalluru HarshaNalluru merged commit fdbd2ef into Azure:master Mar 24, 2020
@xirzec xirzec mentioned this pull request Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants