intern icon indicating copy to clipboard operation
intern copied to clipboard

Support for using as a hoisted dependency in yarn workspaces

Open platosha opened this issue 7 years ago • 1 comments

I am using intern in as a yarn workspaces individual package dependency.

By default, yarn is hoists all dependencies of a workspace in workspace root node_modules, meaning that the intern packages ends up installed my-workspace/node_modules/intern. The test config is in my-workspace/packages/my-package/intern.json. Both node and browser environments are in use.

Expected behavior

Running cd my-workspace/packages/my-package && yarn intern can run the tests in both node and browser environments.

Current behavior

With default basePath:

  • the node environment works
  • the browser environment throws Error: Unable to load /../../node_modules/intern/loaders/default.js

After setting the basePath to ../.. (workspace root):

  • the node environment works
  • the browser environment throws Error: Unable to load /test/index.spec.js

Adjust the suites from test/**/*.spec.js to packages/my-package/test/**/*.spec.js did not help too, breaks loading all of them.

Possible solution

Apparently, something assumes the server serves intern in node_modules/intern for browsers, but the actual install path is different. Although, intern is able to find internPath correctly, and the server already maps __intern to that location.

It seems that using __intern in browsers to load the intern parts should help much, if not eliminate the issue.

Steps to reproduce (for bugs)

  1. Setup a workspace using yarn workspaces
  2. Create a package in a workspace
  3. Add intern to the package from step 2 and try to run a test suite for the package

Environment

Intern version: v4.3.3 Node version: v11.1.0 yarn version: v1.12.1

Additional information

Workaround: use nohoist in the yarn workspace setup exclude intern from hoisting, so that it is installed in my-workspace/packages/my-package/node_modules/intern.

platosha avatar Nov 12 '18 13:11 platosha

Just wanted to drop a note that this also affects workspaces with npm v7 when intern is installed at the root level. Unfortunately npm does not currently have an option like yarn's nohoist, so this means that intern is unable to be used in npm workspaces where intern is hoisted to the root node_modules folder.

dstaley avatar Jul 28 '21 21:07 dstaley