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

jasmine_node_test passes despite errors in test runner #2688

Closed
katre opened this issue May 20, 2021 · 1 comment · Fixed by #2707
Closed

jasmine_node_test passes despite errors in test runner #2688

katre opened this issue May 20, 2021 · 1 comment · Fixed by #2707
Labels

Comments

@katre
Copy link
Contributor

katre commented May 20, 2021

🐞 bug report

Affected Rule

The issue is caused by the rule: jasmine_node_test

Description

A clear and concise description of the problem...

I am setting up a new project to use Typescript and jasmine testing with Bazel and rules_nodejs. I am directly setting this up with Bazel, and not using node or npm, because I am familiar with Bazel.

When I set up my tests using jasmine_node_test, I saw that the test passes. But when I looked at the test log, I see failures because my test code cannot be found. The test runner should not pass if there are underlying errors.

I may very well have errors in my project, and if you can identify them I am grateful, but the test should not pass if it cannot be run.

🔬 Minimal Reproduction

Check out https://github.com/katre/ts-demo/tree/jasmine-test-runner.

$ bazel test //frontend:model_test 
INFO: Invocation ID: 720a5dcb-7af7-4744-8724-99764108875b
INFO: Analyzed target //frontend:model_test (0 packages loaded, 0 targets configured).
INFO: Found 1 test target...
Target //frontend:model_test up-to-date:
  bazel-bin/frontend/model_test.sh
  bazel-bin/frontend/model_test_loader.js
  bazel-bin/frontend/model_test_require_patch.js
INFO: Elapsed time: 0.814s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
Test cases: finished with 1 passing and 0 failing out of 1 test cases

Executed 0 out of 1 test: 1 test passes.
There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command INFO: Build completed successfully, 1 total action

🔥 Exception or Error

But when I look at the test log:

$ cat bazel-testlogs/frontend/model_test/test.log 
...
- /home/jcater/.cache/bazel/_bazel_jcater/494d7a0f1105ee0299d093a558bf667b/sandbox/linux-sandbox/14/execroot/ts-demo/bazel-out/k8-fastbuild/bin/frontend/model_test.sh.runfiles/npm/node_modules/@bazel/jasmine/jasmine_runner.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at frontend/model.spec.ts:1:1
    at /home/jcater/.cache/bazel/_bazel_jcater/494d7a0f1105ee0299d093a558bf667b/sandbox/linux-sandbox/14/execroot/ts-demo/bazel-out/k8-fastbuild/bin/frontend/model_test.sh.runfiles/ts-demo/frontend/model.spec.js:3:17
    at Object.<anonymous> (/home/jcater/.cache/bazel/_bazel_jcater/494d7a0f1105ee0299d093a558bf667b/sandbox/linux-sandbox/14/execroot/ts-demo/bazel-out/k8-fastbuild/bin/frontend/model_test.sh.runfiles/ts-demo/frontend/model.spec.js:9:3)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Loader.requireShim [as require_] (node_modules/jasmine/lib/loader.js:35:3)
    at node_modules/jasmine/lib/loader.js:28:12
    at new Promise (<anonymous>)
    at Loader.load (node_modules/jasmine/lib/loader.js:27:12)
    at Jasmine.loadSpecs (node_modules/jasmine/lib/jasmine.js:91:23)
    at Jasmine.execute (node_modules/jasmine/lib/jasmine.js:267:14)
(node:55) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:55) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

🌍 Your Environment

Operating System: Linux
Output of bazel version: 4.0.0
Rules_nodejs version: 3.4.2

@katre
Copy link
Contributor Author

katre commented May 20, 2021

If you look at the main branch on https://github.com/katre/ts-demo, the tests are executed (and pass) using karma_web_test_suite. I'd prefer to test non-UI code using pure server-side methods, however, rather than using a headless browser (which I understand is how karma works).

alan-agius4 added a commit to alan-agius4/rules_nodejs that referenced this issue May 27, 2021
Currently unhandled promise rejection caused tests suit to pass. Example:
```
yarn bazel test //packages/angular_devkit/core:core_test --test_summary=detailed --test_output=all
INFO: Analyzed target //packages/angular_devkit/core:core_test (2 packages loaded, 148 targets configured).
INFO: Found 1 test target...
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 0.357s, Critical Path: 0.02s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
PASSED: //packages/angular_devkit/core:core_test (see /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log)
INFO: From Testing //packages/angular_devkit/core:core_test
==================== Test output for //packages/angular_devkit/core:core_test:
(node:11987) UnhandledPromiseRejectionWarning: Error: Cannot find module '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/src/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:303:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts:10:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Loader.requireShim [as require_] (node_modules/jasmine/lib/loader.js:35:3)
    at node_modules/jasmine/lib/loader.js:28:12
    at new Promise (<anonymous>)
    at Loader.load (node_modules/jasmine/lib/loader.js:27:12)
    at Jasmine.loadSpecs (node_modules/jasmine/lib/jasmine.js:91:23)
    at Jasmine.execute (node_modules/jasmine/lib/jasmine.js:267:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11987) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:11987) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
================================================================================
Test cases: finished with 1 passing and 0 failing out of 1 test cases
Executed 0 out of 1 test: 1 test passes.
```

The reason for this is because Jasmine `execute` method returns a `Promise`, which was not handled properly. See: https://unpkg.com/browse/jasmine@3.7.0/lib/jasmine.js#L267

Without this fix

```
yarn bazel test //packages/angular_devkit/core:core_test
yarn run v1.22.10
INFO: Build options --action_env and --enable_runfiles have changed, discarding analysis cache.
INFO: Analyzed target //packages/angular_devkit/core:core_test (3 packages loaded, 6322 targets configured).
INFO: Found 1 test target...
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 7.172s, Critical Path: 6.58s
INFO: 4 processes: 2 local, 2 worker.
INFO: Build completed successfully, 4 total actions
//packages/angular_devkit/core:core_test                                 PASSED in 0.5s

Executed 1 out of 1 test: 1 test passes.
INFO: Build completed successfully, 4 total actions
```

With this fix:
```
yarn bazel test //packages/angular_devkit/core:core_test
yarn run v1.22.10
$ /Users/alanagius/git/angular-cli/node_modules/.bin/bazel test //packages/angular_devkit/core:core_test
INFO: Analyzed target //packages/angular_devkit/core:core_test (1 packages loaded, 10 targets configured).
INFO: Found 1 test target...
FAIL: //packages/angular_devkit/core:core_test (see /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log)
INFO: From Testing //packages/angular_devkit/core:core_test:
==================== Test output for //packages/angular_devkit/core:core_test:
[jasmine_runner.js] An error has been reported: Error: Cannot find module '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/src/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:303:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts:10:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Loader.requireShim [as require_] (node_modules/jasmine/lib/loader.js:35:3)
    at node_modules/jasmine/lib/loader.js:28:12
    at new Promise (<anonymous>)
    at Loader.load (node_modules/jasmine/lib/loader.js:27:12)
    at Jasmine.loadSpecs (node_modules/jasmine/lib/jasmine.js:91:23)
    at Jasmine.execute (node_modules/jasmine/lib/jasmine.js:267:3)
    at main (node_modules/@bazel/jasmine/jasmine_runner.js:157:3)
    at node_modules/@bazel/jasmine/jasmine_runner.js:182:26 {
  code: 'MODULE_NOT_FOUND',
  path: '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/package.json',
  requestPath: '@angular-devkit/core'
}
================================================================================
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 0.761s, Critical Path: 0.42s
INFO: 2 processes: 2 local.
INFO: Build completed, 1 test FAILED, 2 total actions
//packages/angular_devkit/core:core_test                                 FAILED in 0.4s
  /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log
```

Closes bazel-contrib#2688
alexeagle pushed a commit that referenced this issue May 27, 2021
Currently unhandled promise rejection caused tests suit to pass. Example:
```
yarn bazel test //packages/angular_devkit/core:core_test --test_summary=detailed --test_output=all
INFO: Analyzed target //packages/angular_devkit/core:core_test (2 packages loaded, 148 targets configured).
INFO: Found 1 test target...
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 0.357s, Critical Path: 0.02s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
PASSED: //packages/angular_devkit/core:core_test (see /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log)
INFO: From Testing //packages/angular_devkit/core:core_test
==================== Test output for //packages/angular_devkit/core:core_test:
(node:11987) UnhandledPromiseRejectionWarning: Error: Cannot find module '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/src/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:303:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts:10:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Loader.requireShim [as require_] (node_modules/jasmine/lib/loader.js:35:3)
    at node_modules/jasmine/lib/loader.js:28:12
    at new Promise (<anonymous>)
    at Loader.load (node_modules/jasmine/lib/loader.js:27:12)
    at Jasmine.loadSpecs (node_modules/jasmine/lib/jasmine.js:91:23)
    at Jasmine.execute (node_modules/jasmine/lib/jasmine.js:267:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11987) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:11987) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
================================================================================
Test cases: finished with 1 passing and 0 failing out of 1 test cases
Executed 0 out of 1 test: 1 test passes.
```

The reason for this is because Jasmine `execute` method returns a `Promise`, which was not handled properly. See: https://unpkg.com/browse/jasmine@3.7.0/lib/jasmine.js#L267

Without this fix

```
yarn bazel test //packages/angular_devkit/core:core_test
yarn run v1.22.10
INFO: Build options --action_env and --enable_runfiles have changed, discarding analysis cache.
INFO: Analyzed target //packages/angular_devkit/core:core_test (3 packages loaded, 6322 targets configured).
INFO: Found 1 test target...
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 7.172s, Critical Path: 6.58s
INFO: 4 processes: 2 local, 2 worker.
INFO: Build completed successfully, 4 total actions
//packages/angular_devkit/core:core_test                                 PASSED in 0.5s

Executed 1 out of 1 test: 1 test passes.
INFO: Build completed successfully, 4 total actions
```

With this fix:
```
yarn bazel test //packages/angular_devkit/core:core_test
yarn run v1.22.10
$ /Users/alanagius/git/angular-cli/node_modules/.bin/bazel test //packages/angular_devkit/core:core_test
INFO: Analyzed target //packages/angular_devkit/core:core_test (1 packages loaded, 10 targets configured).
INFO: Found 1 test target...
FAIL: //packages/angular_devkit/core:core_test (see /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log)
INFO: From Testing //packages/angular_devkit/core:core_test:
==================== Test output for //packages/angular_devkit/core:core_test:
[jasmine_runner.js] An error has been reported: Error: Cannot find module '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/src/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:303:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts:10:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Loader.requireShim [as require_] (node_modules/jasmine/lib/loader.js:35:3)
    at node_modules/jasmine/lib/loader.js:28:12
    at new Promise (<anonymous>)
    at Loader.load (node_modules/jasmine/lib/loader.js:27:12)
    at Jasmine.loadSpecs (node_modules/jasmine/lib/jasmine.js:91:23)
    at Jasmine.execute (node_modules/jasmine/lib/jasmine.js:267:3)
    at main (node_modules/@bazel/jasmine/jasmine_runner.js:157:3)
    at node_modules/@bazel/jasmine/jasmine_runner.js:182:26 {
  code: 'MODULE_NOT_FOUND',
  path: '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/package.json',
  requestPath: '@angular-devkit/core'
}
================================================================================
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 0.761s, Critical Path: 0.42s
INFO: 2 processes: 2 local.
INFO: Build completed, 1 test FAILED, 2 total actions
//packages/angular_devkit/core:core_test                                 FAILED in 0.4s
  /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log
```

Closes #2688
alexeagle pushed a commit that referenced this issue May 28, 2021
Currently unhandled promise rejection caused tests suit to pass. Example:
```
yarn bazel test //packages/angular_devkit/core:core_test --test_summary=detailed --test_output=all
INFO: Analyzed target //packages/angular_devkit/core:core_test (2 packages loaded, 148 targets configured).
INFO: Found 1 test target...
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 0.357s, Critical Path: 0.02s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
PASSED: //packages/angular_devkit/core:core_test (see /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log)
INFO: From Testing //packages/angular_devkit/core:core_test
==================== Test output for //packages/angular_devkit/core:core_test:
(node:11987) UnhandledPromiseRejectionWarning: Error: Cannot find module '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/src/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:303:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts:10:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Loader.requireShim [as require_] (node_modules/jasmine/lib/loader.js:35:3)
    at node_modules/jasmine/lib/loader.js:28:12
    at new Promise (<anonymous>)
    at Loader.load (node_modules/jasmine/lib/loader.js:27:12)
    at Jasmine.loadSpecs (node_modules/jasmine/lib/jasmine.js:91:23)
    at Jasmine.execute (node_modules/jasmine/lib/jasmine.js:267:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11987) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:11987) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
================================================================================
Test cases: finished with 1 passing and 0 failing out of 1 test cases
Executed 0 out of 1 test: 1 test passes.
```

The reason for this is because Jasmine `execute` method returns a `Promise`, which was not handled properly. See: https://unpkg.com/browse/jasmine@3.7.0/lib/jasmine.js#L267

Without this fix

```
yarn bazel test //packages/angular_devkit/core:core_test
yarn run v1.22.10
INFO: Build options --action_env and --enable_runfiles have changed, discarding analysis cache.
INFO: Analyzed target //packages/angular_devkit/core:core_test (3 packages loaded, 6322 targets configured).
INFO: Found 1 test target...
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 7.172s, Critical Path: 6.58s
INFO: 4 processes: 2 local, 2 worker.
INFO: Build completed successfully, 4 total actions
//packages/angular_devkit/core:core_test                                 PASSED in 0.5s

Executed 1 out of 1 test: 1 test passes.
INFO: Build completed successfully, 4 total actions
```

With this fix:
```
yarn bazel test //packages/angular_devkit/core:core_test
yarn run v1.22.10
$ /Users/alanagius/git/angular-cli/node_modules/.bin/bazel test //packages/angular_devkit/core:core_test
INFO: Analyzed target //packages/angular_devkit/core:core_test (1 packages loaded, 10 targets configured).
INFO: Found 1 test target...
FAIL: //packages/angular_devkit/core:core_test (see /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log)
INFO: From Testing //packages/angular_devkit/core:core_test:
==================== Test output for //packages/angular_devkit/core:core_test:
[jasmine_runner.js] An error has been reported: Error: Cannot find module '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/src/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:303:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts:10:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Loader.requireShim [as require_] (node_modules/jasmine/lib/loader.js:35:3)
    at node_modules/jasmine/lib/loader.js:28:12
    at new Promise (<anonymous>)
    at Loader.load (node_modules/jasmine/lib/loader.js:27:12)
    at Jasmine.loadSpecs (node_modules/jasmine/lib/jasmine.js:91:23)
    at Jasmine.execute (node_modules/jasmine/lib/jasmine.js:267:3)
    at main (node_modules/@bazel/jasmine/jasmine_runner.js:157:3)
    at node_modules/@bazel/jasmine/jasmine_runner.js:182:26 {
  code: 'MODULE_NOT_FOUND',
  path: '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/package.json',
  requestPath: '@angular-devkit/core'
}
================================================================================
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 0.761s, Critical Path: 0.42s
INFO: 2 processes: 2 local.
INFO: Build completed, 1 test FAILED, 2 total actions
//packages/angular_devkit/core:core_test                                 FAILED in 0.4s
  /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log
```

Closes #2688
twheys pushed a commit to twheys/rules_nodejs that referenced this issue Jan 13, 2022
Currently unhandled promise rejection caused tests suit to pass. Example:
```
yarn bazel test //packages/angular_devkit/core:core_test --test_summary=detailed --test_output=all
INFO: Analyzed target //packages/angular_devkit/core:core_test (2 packages loaded, 148 targets configured).
INFO: Found 1 test target...
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 0.357s, Critical Path: 0.02s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
PASSED: //packages/angular_devkit/core:core_test (see /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log)
INFO: From Testing //packages/angular_devkit/core:core_test
==================== Test output for //packages/angular_devkit/core:core_test:
(node:11987) UnhandledPromiseRejectionWarning: Error: Cannot find module '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/src/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:303:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts:10:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Loader.requireShim [as require_] (node_modules/jasmine/lib/loader.js:35:3)
    at node_modules/jasmine/lib/loader.js:28:12
    at new Promise (<anonymous>)
    at Loader.load (node_modules/jasmine/lib/loader.js:27:12)
    at Jasmine.loadSpecs (node_modules/jasmine/lib/jasmine.js:91:23)
    at Jasmine.execute (node_modules/jasmine/lib/jasmine.js:267:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11987) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:11987) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
================================================================================
Test cases: finished with 1 passing and 0 failing out of 1 test cases
Executed 0 out of 1 test: 1 test passes.
```

The reason for this is because Jasmine `execute` method returns a `Promise`, which was not handled properly. See: https://unpkg.com/browse/jasmine@3.7.0/lib/jasmine.js#L267

Without this fix

```
yarn bazel test //packages/angular_devkit/core:core_test
yarn run v1.22.10
INFO: Build options --action_env and --enable_runfiles have changed, discarding analysis cache.
INFO: Analyzed target //packages/angular_devkit/core:core_test (3 packages loaded, 6322 targets configured).
INFO: Found 1 test target...
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 7.172s, Critical Path: 6.58s
INFO: 4 processes: 2 local, 2 worker.
INFO: Build completed successfully, 4 total actions
//packages/angular_devkit/core:core_test                                 PASSED in 0.5s

Executed 1 out of 1 test: 1 test passes.
INFO: Build completed successfully, 4 total actions
```

With this fix:
```
yarn bazel test //packages/angular_devkit/core:core_test
yarn run v1.22.10
$ /Users/alanagius/git/angular-cli/node_modules/.bin/bazel test //packages/angular_devkit/core:core_test
INFO: Analyzed target //packages/angular_devkit/core:core_test (1 packages loaded, 10 targets configured).
INFO: Found 1 test target...
FAIL: //packages/angular_devkit/core:core_test (see /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log)
INFO: From Testing //packages/angular_devkit/core:core_test:
==================== Test output for //packages/angular_devkit/core:core_test:
[jasmine_runner.js] An error has been reported: Error: Cannot find module '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/src/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:303:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts:10:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Loader.requireShim [as require_] (node_modules/jasmine/lib/loader.js:35:3)
    at node_modules/jasmine/lib/loader.js:28:12
    at new Promise (<anonymous>)
    at Loader.load (node_modules/jasmine/lib/loader.js:27:12)
    at Jasmine.loadSpecs (node_modules/jasmine/lib/jasmine.js:91:23)
    at Jasmine.execute (node_modules/jasmine/lib/jasmine.js:267:3)
    at main (node_modules/@bazel/jasmine/jasmine_runner.js:157:3)
    at node_modules/@bazel/jasmine/jasmine_runner.js:182:26 {
  code: 'MODULE_NOT_FOUND',
  path: '/private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/node_modules/@angular-devkit/core/package.json',
  requestPath: '@angular-devkit/core'
}
================================================================================
Target //packages/angular_devkit/core:core_test up-to-date:
  dist/bin/packages/angular_devkit/core/core_test.sh
  dist/bin/packages/angular_devkit/core/core_test_loader.js
  dist/bin/packages/angular_devkit/core/core_test_require_patch.js
INFO: Elapsed time: 0.761s, Critical Path: 0.42s
INFO: 2 processes: 2 local.
INFO: Build completed, 1 test FAILED, 2 total actions
//packages/angular_devkit/core:core_test                                 FAILED in 0.4s
  /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/execroot/angular_cli/bazel-out/darwin-fastbuild/testlogs/packages/angular_devkit/core/core_test/test.log
```

Closes bazel-contrib#2688
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants