如何在没有CLI的情况下设置elee测试Angular?

时间:2018-05-24 13:23:25

标签: angular protractor angular-e2e

我目前正在尝试为一个非常大的Angular应用程序进行e2e测试,但是我无法设置它们。 由于各种情况,我无法尝试将Angular CLI集成到项目中,所以我必须解决它。

我的项目结构

app
├── e2e
│   ├── tsconfig.e2e.json
│   ├── component.e2e-spec.ts
│   └── pages
│        └── component.page.ts
├── ....
├── protractor.conf.js
└── tsconfig.json

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "allowJs": true,
    "noEmit": true,
    "noEmitHelpers": true,
    "importHelpers": true,
    "strictNullChecks": false,
    "lib": [
      "dom",
      "es6"
    ]
  },
  "typeRoots": [
      "node_modules/@types"
    ],
  "types": [
      "jasmine",
      "node",
      "source-map",
      "uglify-js",
      "webpack"
  ],
  "exclude": [
    "node_modules",
    "!node_modules/@types",
    "dist",
    "typescript"
  ],
  "awesomeTypescriptLoaderOptions": {
    "forkChecker": true,
    "useWebpackText": true
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

protractor.conf.ts

 const {SpecReporter} = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome',
    directConnect: true,
    baseUrl: 'http://localhost:4200/',
    framework: 'jasmine',
    jasmineNodeOpts: {
      showColors: true,
      defaultTimeoutInterval: 30000,
      print: function () {
      }
    },
    onPrepare() {
      require('ts-node').register({
        project: 'e2e/tsconfig.e2e.json'
      });
      jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true}}));
    }
  }
}

tsconfig.e2e.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/e2e",
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jasmine",
      "jasminewd2",
      "node"
    ]
  }
}

我可以使用:

启动我的服务器
npm run webpack-dev-server -- --config config/webpack.dev.js --open --progress --profile --watch --content-base src/

当我尝试用:

开始e2e测试时
npm-run-all -p -r server:prod:ci protractor

我得到以下错误:

Error: C:\Users\xxx\Desktop\app\e2e\component.e2e-spec.ts:1
(function (exports, require, module, __filename, __dirname) { import { ComponentPage} from './pages/component.page';
                                                          ^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)

我认为抛出错误是因为.ts文件没有被转换为.js ... 所以我想我的配置或开始测试的方式都是错误的。

0 个答案:

没有答案
相关问题