【发布时间】:2018-08-09 03:19:40
【问题描述】:
我创建了一个新的应用程序 JHipster,没有任何修改,我无法打包它。
这是我的 .yo-rc.json
{
"generator-jhipster": {
"promptValues": {
"packageName": "testbug",
"nativeLanguage": "en"
},
"jhipsterVersion": "5.1.0",
"applicationType": "monolith",
"baseName": "testBugJhipster",
"packageName": "testbug",
"packageFolder": "testbug",
"serverPort": "8080",
"authenticationType": "jwt",
"cacheProvider": "ehcache",
"enableHibernateCache": true,
"websocket": "spring-websocket",
"databaseType": "sql",
"devDatabaseType": "h2Memory",
"prodDatabaseType": "mysql",
"searchEngine": "elasticsearch",
"messageBroker": "kafka",
"serviceDiscoveryType": "eureka",
"buildTool": "maven",
"enableSwaggerCodegen": true,
"jwtSecretKey": "a1643dc27d4bad4c20782e29fe5491fc3ecdf5e5",
"clientFramework": "angularX",
"useSass": true,
"clientPackageManager": "yarn",
"testFrameworks": [
"gatling",
"cucumber",
"protractor"
],
"jhiPrefix": "jhi",
"enableTranslation": true,
"nativeLanguage": "en",
"languages": [
"en",
"fr"
]
}
}
打包,我用
./mvnw -Pprod package
起初,我遇到了这个错误:
[INFO] Running 'yarn run webpack:test' in /home/korrident/testBugJhipster
[INFO] yarn run v1.6.0
[INFO] $ yarn run test
[INFO] $ yarn run lint && jest --coverage --logHeapUsage -w=2 --config src/test/javascript/jest.conf.js
[INFO] $ tslint --project tsconfig.json -e 'node_modules/**'
[ERROR] No valid rules have been specified
[ERROR] FAIL src/test/javascript/spec/app/shared/login/login.component.spec.ts
[ERROR] ● Test suite failed to run
[ERROR]
[ERROR] SecurityError: localStorage is not available for opaque origins
[ERROR]
[ERROR] at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)
[ERROR] at Array.forEach (<anonymous>)
[ERROR]
基于此 SO : client side tests fail using jhipster 5.1.0
我在 src/test/javascript/jest.conf.js 的末尾添加了
testEnvironment: "node",
testURL: "http://localhost/"
但是现在,我有这个错误
[INFO] $ yarn run test
[INFO] $ yarn run lint && jest --coverage --logHeapUsage -w=2 --config src/test/javascript/jest.conf.js
[INFO] $ tslint --project tsconfig.json -e 'node_modules/**'
[ERROR] No valid rules have been specified
[ERROR] FAIL src/test/javascript/spec/app/admin/health/health.component.spec.ts
[ERROR] ● Test suite failed to run
[ERROR]
[ERROR] ReferenceError: XMLHttpRequest is not defined
[ERROR]
[ERROR] at patchXHR (node_modules/zone.js/dist/zone.js:2926:39)
[ERROR] at node_modules/zone.js/dist/zone.js:2919:5
[ERROR] at Function.Object.<anonymous>.Zone.__load_patch (node_modules/zone.js/dist/zone.js:84:33)
[ERROR] at node_modules/zone.js/dist/zone.js:2917:6
[ERROR] at Object.<anonymous>.FUNCTION (node_modules/zone.js/dist/zone.js:9:65)
[ERROR] at Object.<anonymous> (node_modules/zone.js/dist/zone.js:12:2)
[ERROR] at Object.<anonymous> (node_modules/jest-preset-angular/setupJest.js:5:1)
[ERROR]
除了 jest.conf.js,git diff 没有显示从初始化提交的其他变化。
我尝试安装 xmlhttprequest@^1.8.0 但开玩笑的结果没有变化。
这个问题并不紧急,因为我可以禁用测试,但我不能让它太久。
【问题讨论】:
-
您将环境设置为节点,但 XMLHttpRequest 不是节点的一部分。如果您正在编写浏览器代码,请对其进行测试。
-
将其更改为
testEnvironment: 'jsdom'。添加testURL: 'http://localhost'应该足以修复第一个错误。这都与bug in Jest 发现的minor release update of jsdom 有关。
标签: jhipster