SyntaxError:尝试在 e2e 测试中导入量角器时出现意外的令牌导入 [英] SyntaxError: Unexpected token import when trying to import protractor in e2e test for angular

查看:24
本文介绍了SyntaxError:尝试在 e2e 测试中导入量角器时出现意外的令牌导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个 Angular 4 应用程序,现在我正在尝试使用 Protractor 运行一些基于 e2e 的测试.

I've written an angular 4 app and now I'm trying to run some e2e based tests using Protractor.

我错过了什么吗?

尝试运行测试脚本时出错:

Error when trying to run test script:

[rob@work repo]$ npm run e2e

> repo@1.0.0 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

量角器.config.js

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
  }
};

e2e 测试文件(app.ui.test.ts):

e2e test file (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

推荐答案

您首先需要在运行之前转译您的 *.ts-文件,就像您处理应用源文件一样.

You first need to transpile your *.ts-files before running, just like you do with your app source files.

p>

也许 this 会帮助你.

这篇关于SyntaxError:尝试在 e2e 测试中导入量角器时出现意外的令牌导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆