-
Notifications
You must be signed in to change notification settings - Fork 782
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
qunit --require
does not find local module if qunit is globally installed
#1372
Comments
Hi @jeremiahlee, thanks for the issue. Just out of curiosity, does it work if both QUnit and esm are installed locally or globally? Asking because ESLint has a similar issue where a global ESLint can't find local plugins. |
Good question, @platinumazure. I hadn't tried those variations. I tried all globally first:
I got the same error. Then I tried installing
and it worked!
So good news! I'm unblocked. But is this expected behavior? |
Hi @jeremiahlee 👋 Thanks for trying |
@jdalton Thanks for jumping in! I first tried |
Without QUnit doing some coding |
I'm not able to get it work with a pure local install: ~/classes/vanilla-web/coin-toss > npm ls -g esm
/Users/marty/.node/lib
└── (empty)
~/classes/vanilla-web/coin-toss > npm ls -g qunit
/Users/marty/.node/lib
└── (empty)
~/classes/vanilla-web/coin-toss > npm ls esm qunit
/Users/marty/classes/vanilla-web/coin-toss
├── [email protected]
└── [email protected]
~/classes/vanilla-web/coin-toss > npx qunit --require esm test/tests.js
TAP version 13
not ok 1 test/tests.js > Failed to load the test file with error:
/Users/marty/classes/vanilla-web/coin-toss/test/tests.js:2
import getHeadsOrTails from '../src/get-heads-or-tails.js';
^^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:74:7)
at createScript (vm.js:246:10)
at Object.runInThisContext (vm.js:298:10)
at Module._compile (internal/modules/cjs/loader.js:670:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
---
message: "should be able to load file"
severity: failed
actual: false
expected: true
stack: at Object.<anonymous> (/Users/marty/classes/vanilla-web/coin-toss/node_modules/qunit/src/cli/run.js:60:13)
...
1..1
# pass 0
# skip 0
# todo 0
# fail 1 |
Work around is to use an intermediate file /* eslint-disable */
require = require('esm')(module);
module.exports = require("./tests.js"); Then launch that file: > npx qunit tests/index.js |
qunit --require esm
does not workqunit --require
does not find local module if qunit is globally installed
I think a locally installed However, the case of globally installing qunit and finding a local module seems one I expect to work. I do generally recommend for project management to keep versioning of dependencies local to a project (and run via I've updated the task summary to reflect that use case to distinguish it from the case where both are local, which appears to work. |
This makes sense to me. I'm looking into this now that we're dropping Node 8 support. I'm seeing however that we already do exactly as you suggest. The c6365ed6#diff-3309eba0612e0921bb3a101c1bc467ea function requireFromCWD( mod ) {
const resolvedPath = resolve.sync( mod, { basedir: process.cwd() } );
return require( resolvedPath );
};
# qunit/src/cli.js
options.requires.forEach( requireFromCWD ); Which means that from what I can tell both of the following should work as expected:
|
Closing for now as this seems to work on 2.11 from my own testing. Feel free to ping me here or file a new issue if you still encounter an issue with |
Tell us about your runtime:
What are you trying to do?
Pull request #1271 added the
--require
option, but it does not seem to work withesm
, as @jdalton hoped.I wrote a test of using
esm
withqunit --require
. Perhaps I am not doing it correctly. If you can help me figure this out, I would happily contribute to qunitjs/qunitjs.com#144.npm install
to getesm
package.npm install -g qunit
to getqunit
globally.qunit --require esm test.js
to run the test.What actually happened?
What did you expect to happen?
The text was updated successfully, but these errors were encountered: