2017-10-06 76 views
0

語法錯誤,我使用NightWatch框架Vue.js我可以在e2e測試中導入模塊嗎?進口

在測試運行我的端到端測試,我需要檢查瀏覽器中顯示的值被重置爲定義的初始值,設定爲從config.js輸出恆定文件

但我得到一個SYNTAX錯誤,是不是被接受?

Starting selenium server... started - PID: 49634 
There was an error while starting the test runner: 
../test/e2e/specs/test.js:4 
import { WORKING_TIME } from '@/config'; 
^^^^^^ 
SyntaxError: Unexpected token import at createScript (vm.js:74:10) 
    at Object.runInThisContext (vm.js:116:10) 
    at Module._compile (module.js:537:28) 
    at loader (../node_modules/babel-register/lib/node.js:144:5) 
    at Object.require.extensions.(anonymous function) [as .js] (/../node_modules/babel-register/lib/node.js:154:7) 
    at Module.load (module.js:507:32) 
    at tryModuleLoad (module.js:470:12) 
    at Function.Module._load (module.js:462:3) 
    at Module.require (module.js:517:17) 
    at require (internal/module.js:11:18) 

config.js

let coeff = process.env.NODE_ENV === 'testing' ? 0.5 : 1 
export const WORKING_TIME = coeff * 60 

E2E/test.js

import { WORKING_TIME } from '@/config' 

module.exports = { 
    'check STOP event': (browser) => { 
    const devServer = browser.globals.devServerURL 
    browser.url(devServer).waitForElementVisible('#app', 5000) 
    browser.click('[title=start]').waitForElementVisible('i.toggle-volume', 5000) 

    // CLICK on STOP button 
    browser.click('[title=stop]').pause(1000) 
    ... 
    // Check timer is reset 
    const leftPad = (str, length = 10) => { 
     return `${' '.repeat(length)}${str}` 
    } 
    const min = Math.floor(WORKING_TIME/60) 
    const sec = WORKING_TIME % 60 
    const initialTimer = leftPad(min, 2) + ':' + leftPad(sec, 2) 
    browser.expect.element('.my-timer').text.to.equal(initialTimer) 
    browser.end() 
    } 
} 
+0

它看起來像你在ES6中有問題。 請確保在使用babel運行測試之前進行測試 – OmranAbazid

+0

感謝Omran!現在得到它,你把我放在軌道上..看到我自己的答案 – erwin

回答

0

正如@Omran提到的,我有問題瓦特ES6蒸散..

1 - 需要在之前插入進口(也寫一個正確的路徑...)

E2E/test.js

require('babel-core/register') 
import { WORKING_TIME } from '../../../config' 

2 - E2E測試runner.js被設置:

process.env.NODE_ENV = 'testing' 

我要補充它變成.babelrc

.babelrc

{ 
    "presets": [ 
    ["env", { 
     "modules": false, 
     "targets": { 
     "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] 
     } 
    }], 
    "stage-2" 
    ], 
    "plugins": ["transform-runtime"], 
    "env": { 
    "test": { 
     "presets": ["env", "stage-2"], 
     "plugins": ["istanbul"] 
    }, 
    "testing": { 
     "presets": ["env", "stage-2"], 
     "plugins": ["istanbul"] 
    } 
    } 
} 
相關問題