2016-11-21 7 views
2

私はwebpackを使用した反応するWebアプリケーションを持っています。ビジュアルスタジオのオンラインビルドプロセスでmocha.jsテストを実行するには

左パッドの問題のため、ソース管理にnode_modulesフォルダが含まれています。

私はmochaと酵素を持っています。私の反応モジュールを単位テストするために設定しました。私のpackages.jsonは、以下のテスト構成を持っています。

"test": "mocha-webpack --webpack-config webpack.config-test.js \"source/**/*.test.js\"" 

すべてが素晴らしいです。私が走ったとき

npm run test 

私のローカル開発マシンで。すべてのテストが実行されます。

私が持っている問題は、私がもし私ことを発見し、私は専用のビルドマシン上でビルドプロセスの一環として、「NPMの実行テスト」を実行したときに、私はいくつかの周りを掘った後、次のエラー

Error: Cannot find module 'enzyme' 

を取得しています

npm install enzyme 

私がテストを実行する前に、次に正常に動作しました。 これは、インストールが自分のnode_modules/enzyme/packages.jsonファイルを変更したためです。このファイルには、ローカル開発環境へのパスが2つあり、プロジェクトがビルドマシン上で実行された場所へのフルパスに変更されています。彼らはローカルでテストを実行する場合のパスは、地元の発展に変更する必要がありますよう

_Args下に1つずつ

_where下
{ 
    "_args": [ 
    [ 
     { 
     "raw": "[email protected]^2.6.0", 
     "scope": null, 
     "escapedName": "enzyme", 
     "name": "enzyme", 
     "rawSpec": "^2.6.0", 
     "spec": ">=2.6.0 <3.0.0", 
     "type": "range" 
     }, 
     "C:\\Dev\\UnifiedWeb" 
    ] 
    ], 
    "_from": "[email protected]>=2.6.0 <3.0.0", 
    "_id": "[email protected]", 
    "_inCache": true, 
    "_location": "/enzyme", 
    "_nodeVersion": "7.0.0", 
    "_npmOperationalInternal": { 
    "host": "packages-12-west.internal.npmjs.com", 
    "tmp": "tmp/enzyme-2.6.0.tgz_1478746866117_0.454174768878147" 
    }, 
    "_npmUser": { 
    "name": "ljharb", 
    "email": "[email protected]" 
    }, 
    "_npmVersion": "3.10.8", 
    "_phantomChildren": {}, 
    "_requested": { 
    "raw": "[email protected]^2.6.0", 
    "scope": null, 
    "escapedName": "enzyme", 
    "name": "enzyme", 
    "rawSpec": "^2.6.0", 
    "spec": ">=2.6.0 <3.0.0", 
    "type": "range" 
    }, 
    "_requiredBy": [ 
    "#DEV:/", 
    "#USER" 
    ], 
    "_resolved": "https://registry.npmjs.org/enzyme/-/enzyme-2.6.0.tgz", 
    "_shasum": "148d742b25e2565f7e80870a0c92aea9be1b90ea", 
    "_shrinkwrap": null, 
    "_spec": "[email protected]^2.6.0", 
    "_where": "C:\\Dev\\UnifiedWeb", 
    "author": { 
    "name": "Leland Richardson", 
    "email": "[email protected]" 
    }, 
    "bugs": { 
    "url": "https://github.com/airbnb/enzyme/issues" 
    }, 
    "dependencies": { 
    "cheerio": "^0.22.0", 
    "function.prototype.name": "^1.0.0", 
    "in-publish": "^2.0.0", 
    "is-subset": "^0.1.1", 
    "lodash": "^4.16.4", 
    "object-is": "^1.0.1", 
    "object.assign": "^4.0.4", 
    "object.entries": "^1.0.3", 
    "object.values": "^1.0.3", 
    "uuid": "^2.0.3" 
    }, 
    "description": "JavaScript Testing utilities for React", 
    "devDependencies": { 
    "babel-cli": "^6.18.0", 
    "babel-core": "^6.18.2", 
    "babel-eslint": "^7.1.0", 
    "babel-loader": "^6.2.7", 
    "babel-preset-airbnb": "^2.1.1", 
    "babel-register": "^6.18.0", 
    "chai": "^3.5.0", 
    "coveralls": "^2.11.14", 
    "enzyme-example-jest": "^0.1.0", 
    "enzyme-example-karma": "^0.1.1", 
    "enzyme-example-karma-webpack": "^0.1.4", 
    "enzyme-example-mocha": "^0.1.0", 
    "enzyme-example-react-native": "^0.1.0", 
    "eslint": "^3.9.1", 
    "eslint-config-airbnb": "^13.0.0", 
    "eslint-plugin-import": "^2.2.0", 
    "eslint-plugin-jsx-a11y": "^2.2.3", 
    "eslint-plugin-react": "^6.6.0", 
    "gitbook-cli": "^1.0.1", 
    "istanbul": "^1.0.0-alpha.2", 
    "jsdom": "^6.1.0", 
    "json-loader": "^0.5.4", 
    "karma": "^1.3.0", 
    "karma-chrome-launcher": "^1.0.1", 
    "karma-firefox-launcher": "^1.0.0", 
    "karma-mocha": "^1.2.0", 
    "karma-sourcemap-loader": "^0.3.7", 
    "karma-webpack": "^1.8.0", 
    "mocha": "^3.1.2", 
    "rimraf": "^2.5.4", 
    "safe-publish-latest": "^1.1.1", 
    "sinon": "^1.17.6", 
    "webpack": "^1.13.3" 
    }, 
    "directories": {}, 
    "dist": { 
    "shasum": "148d742b25e2565f7e80870a0c92aea9be1b90ea", 
    "tarball": "https://registry.npmjs.org/enzyme/-/enzyme-2.6.0.tgz" 
    }, 
    "gitHead": "5c37d91715a88d393f3c260447a189a446d76e0c", 
    "homepage": "https://github.com/airbnb/enzyme#readme", 
    "keywords": [ 
    "javascript", 
    "shallow rendering", 
    "shallowRender", 
    "test", 
    "reactjs", 
    "react", 
    "flux", 
    "testing", 
    "test utils", 
    "assertion helpers", 
    "tdd", 
    "mocha" 
    ], 
    "license": "MIT", 
    "main": "build", 
    "maintainers": [ 
    { 
     "name": "airbnb", 
     "email": "[email protected]" 
    }, 
    { 
     "name": "intelligibabble", 
     "email": "[email protected]" 
    }, 
    { 
     "name": "ljharb", 
     "email": "[email protected]" 
    } 
    ], 
    "name": "enzyme", 
    "optionalDependencies": {}, 
    "peerDependencies": { 
    "react": "0.13.x || 0.14.x || ^15.0.0-0 || 15.x" 
    }, 
    "readme": "ERROR: No README data found!", 
    "repository": { 
    "type": "git", 
    "url": "git+https://github.com/airbnb/enzyme.git" 
    }, 
    "scripts": { 
    "build": "babel src --out-dir build", 
    "check": "npm run lint && npm run test:all", 
    "clean": "rimraf build", 
    "docs:build": "npm run docs:prepare && gitbook build", 
    "docs:clean": "rimraf _book", 
    "docs:prepare": "gitbook install", 
    "docs:publish": "npm run docs:clean && npm run docs:build && cd _book && git init && git commit --allow-empty -m 'update book' && git fetch [email protected]:airbnb/enzyme.git gh-pages && git checkout -b gh-pages && git add . && git commit -am 'update book' && git push [email protected]:airbnb/enzyme.git gh-pages --force", 
    "docs:watch": "npm run docs:prepare && gitbook serve", 
    "lint": "eslint --ext js,jsx src test", 
    "postversion": "git push && git push --tags && npm run clean && npm run docs:publish", 
    "prepublish": "not-in-publish || (npm run clean && npm run build && safe-publish-latest)", 
    "pretest": "npm run lint", 
    "preversion": "npm run clean && npm run check", 
    "react:13": "npm run react:clean && npm i [email protected]", 
    "react:14": "npm run react:clean && npm i [email protected] [email protected] [email protected]", 
    "react:15": "npm run react:clean && npm i [email protected] [email protected] [email protected]", 
    "react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils", 
    "test": "npm run clean && npm run build && npm run test:only", 
    "test:all": "npm run react:13 && npm run test:only && npm run react:14 && npm run test:only && npm run react:15 && npm run test:only", 
    "test:env": "sh ./example-test.sh", 
    "test:karma": "karma start", 
    "test:only": "mocha --recursive test", 
    "test:single": "mocha --watch", 
    "test:watch": "mocha --recursive --watch test", 
    "travis": "babel-node ./node_modules/.bin/istanbul cover --report html _mocha -- test --recursive", 
    "version": "npm run build" 
    }, 
    "version": "2.6.0" 
} 

この問題は、私のチームで他の開発者に影響を与えます。

酵素パッケージの完全な経路はなぜですか?これを処理するより良い方法はありますか?私は何かを逃しているのですか、またはnpmは移植できませんか?

+0

あなたは偶然 'NPMのshrinkwrap'を使用しましたか? ['enzyme''package.json'](https://github.com/airbnb/enzyme/blob/master/package.json)ファイルを見ると、ローカルパスがないようです。 – MarcoL

+0

ありがとうMarcol。私は酵素/ package.jsonを追加しました。私はNPMがそれらを酵素ではなく添加すると思う –

答えて

関連する問題