Hyperledger Composer 测试代码
Hyperledger composer test code
我按照 IBM hyperledger composer 开发人员指南上的说明进行操作,但是当我编译时,它失败了并出现了这个错误。
> mocha -t 0 --recursive && cucumber-js
Sample
1) "before each" hook for "Alice can read all of the assets"
0 passing (912ms)
1 failing
1) Sample "before each" hook for "Alice can read all of the assets":
SyntaxError: Failed to parse /Users/calvinlin007/Documents/hyperledger-composer/my-network/lib/sample.js: The keyword 'const' is reserved (17:0)
at new Script (node_modules/composer-common/lib/introspect/script.js:55:27)
at ScriptManager.createScript (node_modules/composer-common/lib/scriptmanager.js:61:16)
at Object.process (node_modules/composer-common/lib/businessnetworkdefinition.js:507:69)
at Function.processFile (node_modules/composer-common/lib/businessnetworkdefinition.js:578:27)
at items.forEach (node_modules/composer-common/lib/businessnetworkdefinition.js:563:39)
at Array.forEach (native)
at Function.processDirectory (node_modules/composer-common/lib/businessnetworkdefinition.js:562:15)
at Function.fromDirectory (node_modules/composer-common/lib/businessnetworkdefinition.js:498:35)
at adminConnection.createProfile.then.then (test/sample.js:66:50)
npm ERR! Darwin 16.7.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test-inner"
npm ERR! node v6.11.3
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! my-network@0.1.6 test-inner: `mocha -t 0 --recursive && cucumber-js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-network@0.1.6 test-inner script 'mocha -t 0 --recursive && cucumber-js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the my-network package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mocha -t 0 --recursive && cucumber-js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs my-network
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls my-network
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/calvinlin007/Documents/hyperledger-composer/my-network/npm-debug.log
npm ERR! Test failed. See above for more details.
这是我的.eslintrc.yml配置
env:
es6: true
node: true
mocha: true
extends: 'eslint:recommended'
parserOptions:
ecmaVersion: 2015
sourceType:
- script
因为问题我查过了,应该是EMCAScript版本的,
但我尝试更改它,但没有用。
我检查过我的 macOS 是 10.12。这是我的 package.json
{
"engines": {
"composer": "^0.11.0 || ^0.12.0 || ^0.13.0"
},
"name": "my-network",
"version": "0.1.6",
"description": "My Commodity Trading network",
"networkImage": "https://hyperledger.github.io/composer-sample-networks/packages/basic-sample-network/networkimage.svg",
"networkImageanimated": "https://hyperledger.github.io/composer-sample-networks/packages/basic-sample-network/networkimageanimated.svg",
"scripts": {
"prepublish": "mkdirp ./dist ; composer archive create --sourceType dir --sourceName . -a ./dist/my-network.bna",
"pretest": "npm run lint",
"lint": "eslint .",
"postlint": "npm run licchk",
"licchk": "license-check",
"postlicchk": "npm run doc",
"doc": "jsdoc --pedantic --recurse -c jsdoc.json",
"test-inner": "mocha -t 0 --recursive && cucumber-js",
"test-cover": "nyc npm run test-inner",
"test": "npm run test-inner"
},
"repository": {
"type": "git",
"url": "https://github.com/hyperledger/composer-sample-networks.git"
},
"keywords": [
"sample",
"composer",
"composer-network"
],
"author": "Hyperledger Composer",
"license": "Apache-2.0",
"devDependencies": {
"browserfs": "^1.2.0",
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"composer-admin": "^0.11.0",
"composer-cli": "^0.11.0",
"composer-client": "^0.11.0",
"composer-connector-embedded": "^0.11.0",
"composer-cucumber-steps": "^0.11.0",
"cucumber": "^2.2.0",
"eslint": "^3.6.1",
"istanbul": "^0.4.5",
"jsdoc": "^3.4.1",
"license-check": "^1.1.5",
"mkdirp": "^0.5.1",
"mocha": "^3.2.0",
"moment": "^2.17.1",
"nyc": "^11.0.2"
},
"license-check-config": {
"src": [
"**/*.js",
"!./coverage/**/*",
"!./node_modules/**/*",
"!./out/**/*",
"!./scripts/**/*"
],
"path": "header.txt",
"blocking": true,
"logInfo": false,
"logError": true
},
"nyc": {
"exclude": [
"coverage/**",
"features/**",
"out/**",
"test/**"
],
"reporter": [
"text-summary",
"html"
],
"all": true,
"check-coverage": true,
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100
}
}
有谁知道如何解决这个问题@@?
这就是 npm list 命令returns
Calvinde-MacBook-Air:my-network calvinlin007$ npm list -g --depth=0
/usr/local/lib
├── composer-cli@0.12.2
├── composer-playground@0.12.2
├── composer-rest-server@0.12.2
├── generator-hyperledger-composer@0.12.2
├── npm@3.10.10
└── yo@2.0.0
npm ERR! peer dep missing: @angular/core@^4.0.3, required by @ng-bootstrap/ng-bootstrap@1.0.0-beta.2
npm ERR! peer dep missing: @angular/core@>=4.0.0, required by ngx-clipboard@8.0.4
npm ERR! peer dep missing: @angular/common@^4.0.3, required by @ng-bootstrap/ng-bootstrap@1.0.0-beta.2
npm ERR! peer dep missing: @angular/common@>=4.0.0, required by ngx-clipboard@8.0.4
npm ERR! peer dep missing: @angular/forms@^4.0.3, required by @ng-bootstrap/ng-bootstrap@1.0.0-beta.2
npm ERR! peer dep missing: @angular/platform-browser@>=4.0.0, required by ngx-clipboard@8.0.4
npm ERR! peer dep missing: core-js@>=2.4.1, required by ngx-clipboard@8.0.4
npm ERR! peer dep missing: @angular/core@>=2.4.1, required by ngx-window-token@0.0.2
npm ERR! peer dep missing: @angular/common@>=2.4.1, required by ngx-window-token@0.0.2
npm ERR! peer dep missing: @angular/platform-browser@>=2.4.1, required by ngx-window-token@0.0.2
npm ERR! peer dep missing: core-js@>=2.4.1, required by ngx-window-token@0.0.2
关于您的第一个问题 - sample.js 测试脚本 - 您已将 单元测试 脚本内容复制到 lib/sample.js
中,这就是为什么您有问题 - 即 'const' 错误 - 该文件是交易处理器功能脚本。您应该(根据开发人员教程)将单元测试脚本粘贴到位于 test/sample.js
的文件中。我想也许文件名(在 'lib' 和 'test' 子目录中)相同的事实引起了一些混乱 - 我想我会改变它以改善用户体验。另一个 Angular 错误(前面提到的)仍然存在。
关于您的第二次发帖(Angular 模块错误)。本地 Composer 游乐场安装依赖于 Angular(请注意,开发人员指南使用在线游乐场)。查看 package.json 以获得 angular 依赖项列表。看起来你的游乐场安装不正确,如果它显示缺少依赖项(@angular/core 等)建议清除 docker ps -aq | xargs docker rm -f
和 docker images -aq | xargs docker rmi -f
(警告:清除所有 docker开发环境中的容器)然后使用单行安装它(作为非特权用户) - 即 npm uninstall -g composer-playground
- 使用命令 curl -sSL https://hyperledger.github.io/composer/install-hlfv1.sh | bash
在 docker 容器中安装游乐场。
我按照 IBM hyperledger composer 开发人员指南上的说明进行操作,但是当我编译时,它失败了并出现了这个错误。
> mocha -t 0 --recursive && cucumber-js
Sample
1) "before each" hook for "Alice can read all of the assets"
0 passing (912ms)
1 failing
1) Sample "before each" hook for "Alice can read all of the assets":
SyntaxError: Failed to parse /Users/calvinlin007/Documents/hyperledger-composer/my-network/lib/sample.js: The keyword 'const' is reserved (17:0)
at new Script (node_modules/composer-common/lib/introspect/script.js:55:27)
at ScriptManager.createScript (node_modules/composer-common/lib/scriptmanager.js:61:16)
at Object.process (node_modules/composer-common/lib/businessnetworkdefinition.js:507:69)
at Function.processFile (node_modules/composer-common/lib/businessnetworkdefinition.js:578:27)
at items.forEach (node_modules/composer-common/lib/businessnetworkdefinition.js:563:39)
at Array.forEach (native)
at Function.processDirectory (node_modules/composer-common/lib/businessnetworkdefinition.js:562:15)
at Function.fromDirectory (node_modules/composer-common/lib/businessnetworkdefinition.js:498:35)
at adminConnection.createProfile.then.then (test/sample.js:66:50)
npm ERR! Darwin 16.7.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test-inner"
npm ERR! node v6.11.3
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! my-network@0.1.6 test-inner: `mocha -t 0 --recursive && cucumber-js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-network@0.1.6 test-inner script 'mocha -t 0 --recursive && cucumber-js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the my-network package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mocha -t 0 --recursive && cucumber-js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs my-network
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls my-network
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/calvinlin007/Documents/hyperledger-composer/my-network/npm-debug.log
npm ERR! Test failed. See above for more details.
这是我的.eslintrc.yml配置
env:
es6: true
node: true
mocha: true
extends: 'eslint:recommended'
parserOptions:
ecmaVersion: 2015
sourceType:
- script
因为问题我查过了,应该是EMCAScript版本的, 但我尝试更改它,但没有用。
我检查过我的 macOS 是 10.12。这是我的 package.json
{
"engines": {
"composer": "^0.11.0 || ^0.12.0 || ^0.13.0"
},
"name": "my-network",
"version": "0.1.6",
"description": "My Commodity Trading network",
"networkImage": "https://hyperledger.github.io/composer-sample-networks/packages/basic-sample-network/networkimage.svg",
"networkImageanimated": "https://hyperledger.github.io/composer-sample-networks/packages/basic-sample-network/networkimageanimated.svg",
"scripts": {
"prepublish": "mkdirp ./dist ; composer archive create --sourceType dir --sourceName . -a ./dist/my-network.bna",
"pretest": "npm run lint",
"lint": "eslint .",
"postlint": "npm run licchk",
"licchk": "license-check",
"postlicchk": "npm run doc",
"doc": "jsdoc --pedantic --recurse -c jsdoc.json",
"test-inner": "mocha -t 0 --recursive && cucumber-js",
"test-cover": "nyc npm run test-inner",
"test": "npm run test-inner"
},
"repository": {
"type": "git",
"url": "https://github.com/hyperledger/composer-sample-networks.git"
},
"keywords": [
"sample",
"composer",
"composer-network"
],
"author": "Hyperledger Composer",
"license": "Apache-2.0",
"devDependencies": {
"browserfs": "^1.2.0",
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"composer-admin": "^0.11.0",
"composer-cli": "^0.11.0",
"composer-client": "^0.11.0",
"composer-connector-embedded": "^0.11.0",
"composer-cucumber-steps": "^0.11.0",
"cucumber": "^2.2.0",
"eslint": "^3.6.1",
"istanbul": "^0.4.5",
"jsdoc": "^3.4.1",
"license-check": "^1.1.5",
"mkdirp": "^0.5.1",
"mocha": "^3.2.0",
"moment": "^2.17.1",
"nyc": "^11.0.2"
},
"license-check-config": {
"src": [
"**/*.js",
"!./coverage/**/*",
"!./node_modules/**/*",
"!./out/**/*",
"!./scripts/**/*"
],
"path": "header.txt",
"blocking": true,
"logInfo": false,
"logError": true
},
"nyc": {
"exclude": [
"coverage/**",
"features/**",
"out/**",
"test/**"
],
"reporter": [
"text-summary",
"html"
],
"all": true,
"check-coverage": true,
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100
}
}
有谁知道如何解决这个问题@@?
这就是 npm list 命令returns
Calvinde-MacBook-Air:my-network calvinlin007$ npm list -g --depth=0
/usr/local/lib
├── composer-cli@0.12.2
├── composer-playground@0.12.2
├── composer-rest-server@0.12.2
├── generator-hyperledger-composer@0.12.2
├── npm@3.10.10
└── yo@2.0.0
npm ERR! peer dep missing: @angular/core@^4.0.3, required by @ng-bootstrap/ng-bootstrap@1.0.0-beta.2
npm ERR! peer dep missing: @angular/core@>=4.0.0, required by ngx-clipboard@8.0.4
npm ERR! peer dep missing: @angular/common@^4.0.3, required by @ng-bootstrap/ng-bootstrap@1.0.0-beta.2
npm ERR! peer dep missing: @angular/common@>=4.0.0, required by ngx-clipboard@8.0.4
npm ERR! peer dep missing: @angular/forms@^4.0.3, required by @ng-bootstrap/ng-bootstrap@1.0.0-beta.2
npm ERR! peer dep missing: @angular/platform-browser@>=4.0.0, required by ngx-clipboard@8.0.4
npm ERR! peer dep missing: core-js@>=2.4.1, required by ngx-clipboard@8.0.4
npm ERR! peer dep missing: @angular/core@>=2.4.1, required by ngx-window-token@0.0.2
npm ERR! peer dep missing: @angular/common@>=2.4.1, required by ngx-window-token@0.0.2
npm ERR! peer dep missing: @angular/platform-browser@>=2.4.1, required by ngx-window-token@0.0.2
npm ERR! peer dep missing: core-js@>=2.4.1, required by ngx-window-token@0.0.2
关于您的第一个问题 - sample.js 测试脚本 - 您已将 单元测试 脚本内容复制到 lib/sample.js
中,这就是为什么您有问题 - 即 'const' 错误 - 该文件是交易处理器功能脚本。您应该(根据开发人员教程)将单元测试脚本粘贴到位于 test/sample.js
的文件中。我想也许文件名(在 'lib' 和 'test' 子目录中)相同的事实引起了一些混乱 - 我想我会改变它以改善用户体验。另一个 Angular 错误(前面提到的)仍然存在。
关于您的第二次发帖(Angular 模块错误)。本地 Composer 游乐场安装依赖于 Angular(请注意,开发人员指南使用在线游乐场)。查看 package.json 以获得 angular 依赖项列表。看起来你的游乐场安装不正确,如果它显示缺少依赖项(@angular/core 等)建议清除 docker ps -aq | xargs docker rm -f
和 docker images -aq | xargs docker rmi -f
(警告:清除所有 docker开发环境中的容器)然后使用单行安装它(作为非特权用户) - 即 npm uninstall -g composer-playground
- 使用命令 curl -sSL https://hyperledger.github.io/composer/install-hlfv1.sh | bash
在 docker 容器中安装游乐场。