2016-09-06 5 views
0

피닉스 앱이 있으며 자바 단위 테스트를 위해 모카를 연결하려고합니다. 모듈 'One'을 가져 오는 모듈 'Two'를 테스트하고 싶지만 모듈 1을 찾기 위해 Mocha를 구성하는 방법을 알 수 없습니다.모카가 가져온 코드에서 모듈을 찾을 수 없습니다.

웹/정지/JS의/

export var One = 1; 

웹/정지/JS/two.js

one.js : 여기

테스트 코드
import {One} from "web/static/js/one"; 
export var Two = function() {return One + One;} 
01 23,516,

> 시험/JS/two_test.js 여기

import assert from 'assert'; 
import {Two} from "../../web/static/js/two"; 

describe('Two()', function() { 
    it('returns value 2', function() { 
    assert.equal(2, Two()); 
    }); 
}); 

난 실행할 때 출력 npm test

home:~/elixir/optitrue$ npm test 

> @ test /home/jon/elixir/optitrue 
> mocha --compilers js:babel-register test/js/**/*.js 

module.js:457 
    throw err; 
    ^

Error: Cannot find module 'web/static/js/one' 
    at Function.Module._resolveFilename (module.js:455:15) 
    at Function.Module._load (module.js:403:25) 
    at Module.require (module.js:483:17) 
    at require (internal/module.js:20:19) 
    at Object.<anonymous> (two.js:1:1) 
    at Module._compile (module.js:556:32) 
    at loader (/home/jon/elixir/optitrue/node_modules/babel-register/lib/node.js:148:5) 
    at Object.require.extensions.(anonymous function) [as .js] (/home/jon/elixir/optitrue/node_modules/babel-register/lib/node.js:158:7) 
    at Module.load (module.js:473:32) 
    at tryModuleLoad (module.js:432:12) 
    at Function.Module._load (module.js:424:3) 
    at Module.require (module.js:483:17) 
    at require (internal/module.js:20:19) 
    at Object.<anonymous> (two_test.js:2:1) 
    at Module._compile (module.js:556:32) 
    at loader (/home/jon/elixir/optitrue/node_modules/babel-register/lib/node.js:148:5) 
    at Object.require.extensions.(anonymous function) [as .js] (/home/jon/elixir/optitrue/node_modules/babel-register/lib/node.js:158:7) 
    at Module.load (module.js:473:32) 
    at tryModuleLoad (module.js:432:12) 
    at Function.Module._load (module.js:424:3) 
    at Module.require (module.js:483:17) 
    at require (internal/module.js:20:19) 
    at /home/jon/elixir/optitrue/node_modules/mocha/lib/mocha.js:220:27 
    at Array.forEach (native) 
    at Mocha.loadFiles (/home/jon/elixir/optitrue/node_modules/mocha/lib/mocha.js:217:14) 
    at Mocha.run (/home/jon/elixir/optitrue/node_modules/mocha/lib/mocha.js:485:10) 
    at Object.<anonymous> (/home/jon/elixir/optitrue/node_modules/mocha/bin/_mocha:403:18) 
    at Module._compile (module.js:556:32) 
    at Object.Module._extensions..js (module.js:565:10) 
    at Module.load (module.js:473:32) 
    at tryModuleLoad (module.js:432:12) 
    at Function.Module._load (module.js:424:3) 
    at Module.runMain (module.js:590:10) 
    at run (bootstrap_node.js:394:7) 
    at startup (bootstrap_node.js:149:9) 
    at bootstrap_node.js:509:3 

brunch.config

exports.config = { 
    // See http://brunch.io/#documentation for docs. 
    files: { 
    javascripts: { 
     joinTo: "js/app.js" 
    }, 
    stylesheets: { 
     joinTo: "css/app.css" 
    }, 
    templates: { 
     joinTo: "js/app.js" 
    } 
    }, 

    conventions: { 
    assets: /^(web\/static\/assets)/ 
    }, 

    // Phoenix paths configuration 
    paths: { 
    watched: [ 
     "web/static", 
     "test/static" 
    ], 

    // Where to compile files to 
    public: "priv/static" 
    }, 

    // Configure your plugins 
    plugins: { 
    babel: { 
     // Do not use ES6 compiler in vendor code 
     ignore: [/web\/static\/vendor/] 
    } 
    }, 

    modules: { 
    autoRequire: { 
     "js/app.js": ["web/static/js/app"] 
    } 
    }, 

    npm: { 
    enabled: true, 
    whitelist: ["phoenix", "phoenix_html"] 
    } 
}; 

답변

1

오류는 아주 명확 :

import {One} from "./one"; 
: 당신이 작동하지 않습니다 제공하는 경로를 의미

Error: Cannot find module 'web/static/js/one' 

, 상대 경로를 사용하십시오

관련 문제