client side tests fail using jhipster 5.1.0

2019-06-07 04:49发布

问题:

I'm using jhipster 5.1.0 and when I generate a new monolith app [using default options] and I run yarn test , it fails with the following output :

$ yarn test
yarn run v1.7.0
$ yarn run lint && jest --coverage --logHeapUsage -w=2 --config src/test/javascript/jest.conf.js
$ tslint --project tsconfig.json -e 'node_modules/**'
No valid rules have been specified
 FAIL  src/test/javascript/spec/app/admin/health/health.component.spec.ts
  ● Test suite failed to run

    SecurityError: localStorage is not available for opaque origins

      at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)
          at Array.forEach (<anonymous>)

 FAIL  src/test/javascript/spec/app/shared/login/login.component.spec.ts
  ● Test suite failed to run

    SecurityError: localStorage is not available for opaque origins

      at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)
          at Array.forEach (<anonymous>)

 FAIL  src/test/javascript/spec/app/admin/audits/audits.component.spec.ts
  ● Test suite failed to run

    SecurityError: localStorage is not available for opaque origins

      at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)
          at Array.forEach (<anonymous>)

 FAIL  src/test/javascript/spec/app/account/password-reset/init/password-reset-init.component.spec.ts

...

  ● Test suite failed to run

    SecurityError: localStorage is not available for opaque origins

      at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)
          at Array.forEach (<anonymous>)

 FAIL  src/test/javascript/spec/app/admin/audits/audits.service.spec.ts
  ● Test suite failed to run

    SecurityError: localStorage is not available for opaque origins

      at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)
          at Array.forEach (<anonymous>)

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 16 failed, 16 total
Tests:       0 total
Snapshots:   0 total
Time:        2.353s
Ran all test suites.
error Command failed with exit code 1.

is it a bug or I'm missing something locally ?

回答1:

Seems like a bug.

Try to add this at the bottom of src/test/javascript/jest.conf.js:

testEnvironment: "node",
testUrl: "http://localhost/"