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

Bundle mocha with webpack to extend functionality #4516

Closed
4 tasks done
devhazem opened this issue Nov 22, 2020 · 6 comments · Fixed by devhazem/mocha#1 or #4521
Closed
4 tasks done

Bundle mocha with webpack to extend functionality #4516

devhazem opened this issue Nov 22, 2020 · 6 comments · Fixed by devhazem/mocha#1 or #4521
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer

Comments

@devhazem
Copy link
Contributor

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

I am working on Angular 2 with Cypress. I would like to extend mocha's functionality to add a custom metadata object inside it() and describe(). To do this, i obviously need to require mocha. Code: https://github.com/devhazem/mocha-test-options/blob/master/index.js

When doing this, I get the following error (even though the file does exist):
Error: Webpack Compilation Error C:/app/node_modules/mocha/lib/browser/growl.js Module not found: Error: Can't resolve '../../package' in 'C:\app\node_modules\mocha\lib\browser' resolve '../../package' in 'C:\app\node_modules\mocha\lib\browser' using description file: C:\app\node_modules\mocha\package.json (relative path: ./lib/browser) using description file: C:\app\node_modules\mocha\package.json (relative path: ./package)
How can I achieve this?

Steps to Reproduce

  • Use https://github.com/devhazem/mocha-test-options as a dev dependency in any Angular 2 project
  • declare module:
    declare module mocha-test-options: export function describe(title: string, metadata: object, fn); export function it(title: string, metadata: object, fn);
  • import declared module

Expected behavior: should not throw any errors

Actual behavior:
Error: Webpack Compilation Error C:/app/node_modules/mocha/lib/browser/growl.js Module not found: Error: Can't resolve '../../package' in 'C:\app\node_modules\mocha\lib\browser' resolve '../../package' in 'C:\app\node_modules\mocha\lib\browser' using description file: C:\app\node_modules\mocha\package.json (relative path: ./lib/browser) using description file: C:\app\node_modules\mocha\package.json (relative path: ./package)

Reproduces how often: All the time

Versions

mocha: 8.2.0
typescript: "3.9.4"

@boneskull
Copy link
Contributor

would accept a PR which changes require('../../package') in lib/browser/growl.js to require('../../package.json')

@boneskull boneskull added type: bug a defect, confirmed by a maintainer status: accepting prs Mocha can use your help with this one! and removed unconfirmed-bug labels Nov 23, 2020
This was referenced Nov 25, 2020
@devhazem
Copy link
Contributor Author

@boneskull Please review the PR. The GUI tests seem to be stuck. They''ve been running now for almost 5 hours.

@devhazem devhazem reopened this Nov 25, 2020
@devhazem
Copy link
Contributor Author

@boneskull any update?

@devhazem
Copy link
Contributor Author

devhazem commented Dec 2, 2020

@boneskull please have a look at my PR and merge accordingly

@devhazem
Copy link
Contributor Author

devhazem commented Dec 8, 2020

@outsideris would you please review my PR and merge?

@devhazem
Copy link
Contributor Author

devhazem commented Dec 9, 2020

@boneskull @outsideris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants