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

Using require('../../package') breaks in Polendina #4278

Closed
4 tasks done
jtacoma opened this issue May 10, 2020 · 2 comments
Closed
4 tasks done

Using require('../../package') breaks in Polendina #4278

jtacoma opened this issue May 10, 2020 · 2 comments

Comments

@jtacoma
Copy link

jtacoma commented May 10, 2020

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

Steps to Reproduce

  1. npm init -y
  2. npm i -D mocha @types/mocha polendina ts-loader typescript
  3. mkdir src && echo 'import "mocha";' > src/test.spec.ts
  4. npx tsc --init
  5. echo "module.exports={target:'web',resolve:{modules:['./node_modules'],extensions:['.tsx','.ts','.js']}}" > webpack.test.js
  6. npx polendina --cleanup --timeout 60 src/**/*.spec.ts --webpack-config webpack.test.js

Expected behavior: test run results.

Actual behavior: "Module not found" error

(output from polendina doesn't paste well, this is lightly processed...)

./node_modules/mocha/lib/browser/growl.js
Module not found: Error: Can't resolve '../../package' in '/Users/joshua/code/mocha-growl-require-package/node_modules/mocha/lib/browser'
resolve '../../package' in '/Users/joshua/code/mocha-growl-require-package/node_modules/mocha/lib/browser'
  using description file: /Users/joshua/code/mocha-growl-require-package/node_modules/mocha/package.json (relative path: ./lib/browser)
    using description file: /Users/joshua/code/mocha-growl-require-package/node_modules/mocha/package.json (relative path: ./package)
      no extension
        /Users/joshua/code/mocha-growl-require-package/node_modules/mocha/package doesn't exist
      .tsx
        /Users/joshua/code/mocha-growl-require-package/node_modules/mocha/package.tsx doesn't exist
      .ts
        /Users/joshua/code/mocha-growl-require-package/node_modules/mocha/package.ts doesn't exist
      .js
        /Users/joshua/code/mocha-growl-require-package/node_modules/mocha/package.js doesn't exist
      as directory
        /Users/joshua/code/mocha-growl-require-package/node_modules/mocha/package doesn't exist
[/Users/joshua/code/mocha-growl-require-package/node_modules/mocha/package]
[/Users/joshua/code/mocha-growl-require-package/node_modules/mocha/package.tsx]
[/Users/joshua/code/mocha-growl-require-package/node_modules/mocha/package.ts]
[/Users/joshua/code/mocha-growl-require-package/node_modules/mocha/package.js]
 @ ./node_modules/mocha/lib/browser/growl.js 127:13-37
 @ ./node_modules/mocha/lib/mocha.js
 @ ./node_modules/mocha/browser-entry.js
 @ ./node_modules/ts-loader!./src/test.spec.ts
 @ ./src/test.spec.ts
 @ multi ./src/test.spec.ts ./build/mocha-run.js /Users/joshua/code/mocha-growl-require-package/src/test.spec.ts

Reproduces how often: 100%

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version:
    • bash: mocha: command not found
    • 7.1.2
  • The output of node --version:
    • v13.8.0
  • Your operating system
    • name and version: macOS Catalina 10.15.4 (19E287)
    • architecture (32 or 64-bit): 64-bit
  • Your shell (e.g., bash, zsh, PowerShell, cmd): bash
  • Your browser and version (if running browser tests): n/a
  • Any third-party Mocha-related modules (and their versions): n/a
  • Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): TypeScript v3.8.3 (with ts-loader v7.0.3)

Additional Information

I'm able to work around the problem temporarily with this diff to ./node_modules/mocha/lib/browser/growl.js:

-  var logo = require('../../package').notifyLogo;
+  var logo = require('../../package.json').notifyLogo;
@Munter
Copy link
Contributor

Munter commented May 11, 2020

Why are you bundling mocha when we've already made a browser bundle available?
It looks like Polendina can let you specify the test runner with --runner, where you can specify mocha. And you don't even have to because it's default

@jtacoma
Copy link
Author

jtacoma commented May 12, 2020

I didn't really know what you mean by "bundling mocha" in this context, but there wasn't a lot of information in my post from which you could conclude I was bundling mocha. I looked for something I had mentioned that I could remove and, when I removed import 'mocha'; from test.spec.ts everything worked. In fact, it worked better than before. I had no idea that mocha did not need to be imported. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants