rules_nodejs icon indicating copy to clipboard operation
rules_nodejs copied to clipboard

Verify early that test files actually define the corresponding named modules

Open mernst-github opened this issue 5 years ago • 5 comments

#1308 # Relevant Rules

karma_web_test

Description

The scripts generated by karma_web_test loadFile()s all the files and then require()s them as modules:

...
 loadFile(
      "workspace/src/test/ts/..._test.js",
      "var __awaiter = ...");
  loadFile(
      "../../../../../../../../_tmp/38e45c1d5edcea94c71b05fa49e4545d/tmp-18895cP3fwIlj2RG3.js",
      "\n      // A simplified version of Karma's requirejs.config.tpl.js f...)

The unstated assumption is that ..._test.js actually defines a named module '..._test' . If that assumption doesn't hold the errors are really hard to grasp for a newbie, namely 'no timestamp' warnings, 404s in the web server (since the module name doesn't even map to the right url) and a 30s timeout (since we never reach karma.start).

I did not find this documented anywhere and the mechanism in the examples/ is also fairly obscure:

// at least one import or export is needed for this file to
// be compiled into an named-UMD module by typescript
export {}; 

To reproduce, try to use an empty .js file as "src" of a karma_web_test rule.

Describe the solution you'd like

The requirements for the contents of test files should be documented more clearly. Also, after/as part of each loadFile, karma_web_test should check that the file indeed defined the right named module and abort early with a useful error message.

Describe alternatives you've considered

Maybe even a build-time check on the test files whether they're named modules?

mernst-github avatar May 05 '20 09:05 mernst-github

#1872 is a "wonderful" example of the confusion that arises when people try to debug these issues. A better error would really be appreciated!

mernst-github avatar May 15 '20 07:05 mernst-github

+1 This caused me much wasted time.

applmak avatar May 17 '20 16:05 applmak

Alternatively, instead of assuming that test files create certain modules, one could use this (semi-public) requirejs api to learn which modules are defined and issue the respective 'require' calls. https://github.com/requirejs/requirejs/wiki/Internal-API:-onResourceLoad (I just read up on this, I have no experience whether the api works as expected.)

mernst-github avatar May 27 '20 06:05 mernst-github

This issue has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!

github-actions[bot] avatar Sep 08 '20 01:09 github-actions[bot]

+1 This caused us much wasted time.

papshed avatar Nov 24 '21 16:11 papshed

Sorry everyone - since karma_web_test is no longer in this repo, I'm closing the issue.

alexeagle avatar Jun 06 '24 20:06 alexeagle