2017-06-14 118 views
0

我已經寫了一個角4的應用程序,現在我試圖運行使用Protractor一些基於端到端測試意外令牌進口。語法錯誤:當試圖導入端到端測試量角器的角度

我在這裏錯過了什麼嗎?

錯誤試圖運行測試腳本時:

[[email protected] repo]$ npm run e2e 

> [email protected] e2e /home/rob/git/repo 
> protractor protractor.config.js 

[20:12:24] I/launcher - Running 1 instances of WebDriver 
[20:12:24] I/hosted - Using the selenium server at http://localhost:4444/wd/hub 
[20:12:25] E/launcher - Error: /home/rob/git/repo/test/e2e/app.ui.test.ts:3 
import { browser } from 'protractor'; 
^^^^^^ 
SyntaxError: Unexpected token import 
    at Object.exports.runInThisContext (vm.js:76:16) 
    at Module._compile (module.js:542:28) 
    at Object.Module._extensions..js (module.js:579:10) 
    at Module.load (module.js:487:32) 
    at tryModuleLoad (module.js:446:12) 
    at Function.Module._load (module.js:438:3) 
    at Module.require (module.js:497:17) 
    at require (internal/module.js:20:19) 
    at /home/rob/git/repo/node_modules/jasmine/lib/jasmine.js:93:5 
    at Array.forEach (native) 
[20:12:25] E/launcher - Process exited with error code 100 

protractor.config.js

exports.config = { 
    framework: 'jasmine', 
    seleniumAddress: 'http://localhost:4444/wd/hub', 
    multiCapabilities: [{ 
    'browserName': 'chrome' 
    }], 
    specs: ['test/e2e/**/*.ts'], 
    mochaOpts: { 
    reporter: 'spec', 
    slow: 5000, 
    timeout: 5000 
    } 
}; 

端到端測試文件(app.ui.test.ts):

'use strict'; 
import { browser } from 'protractor'; 
const HOST_URL = 'http://localhost:1344'; 

describe('hello world', function() { 

    describe('hello world app', function() { 
    const FULL_URL = HOST_URL + '/'; 
    it('should greet', function() { 
     browser.get(FULL_URL); 
    }); 
    }); 
}); 

目錄結構:

├── protractor.config.js 
├── test 
│   └── e2e 
│    └── app.ui.test.ts 

回答

2

首先,您需要在運行前transpile你*.ts -files,就像你與你的應用程序源文件。

也許this會幫你。