npm test在运行量角器打字稿时抛出错误

时间:2017-06-08 09:21:12

标签: typescript npm jasmine protractor

在使用npm测试在visual studio代码中运行量角器测试时,得到以下错误,看起来像node_modules/@types/jasmine/index.d.ts的问题,如何摆脱这个错误?

C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test>npm test

> example-typescript@1.0.0 pretest C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test
> npm run tsc


> example-typescript@1.0.0 tsc C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test
> tsc

node_modules/@types/jasmine/index.d.ts(26,41): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s).
node_modules/@types/jasmine/index.d.ts(27,39): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s).
node_modules/@types/jasmine/index.d.ts(152,24): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s).

node_modules/@types/jasmine/index.d.ts(334,14): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s).

node_modules/@types/jasmine/index.d.ts(435,24): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s).

node_modules/@types/jasmine/index.d.ts(448,30): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s).
node_modules/@types/jasmine/index.d.ts(448,30): error TS2314: Generic type 'Matchers<T>' requires 1 type argument(s).

node_modules/@types/jasminewd2/index.d.ts(23,13): error TS2428: All declarations of 'Matchers' must have identical ty
pe parameters.
node_modules/@types/jasminewd2/index.d.ts(47,13): error TS2430: Interface 'ArrayLikeMatchers<T>' incorrectly extends
interface 'Matchers<ArrayLike<T>>'.
  Types of property 'toBe' are incompatible.
    Type '(expected: any, expectationFailOutput?: any) => Promise<void>' is not assignable to type '{ (expected: any,
 expectationFailOutput?: any): boolean; (expected: any, expectationFailOutput?: ...'.
      Type 'Promise<void>' is not assignable to type 'boolean'.
node_modules/@types/jasminewd2/index.d.ts(48,20): error TS2304: Cannot find name 'Expected'.
node_modules/@types/jasminewd2/index.d.ts(49,23): error TS2304: Cannot find name 'Expected'.

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "
run" "tsc"
npm ERR! node v6.10.3
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! example-typescript@1.0.0 tsc: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the example-typescript@1.0.0 tsc script 'tsc'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the example-typescript package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     tsc
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs example-typescript
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls example-typescript
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test\npm-debug.log
npm ERR! Test failed.  See above for more details.

C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test>

以下是我用于在visual studio代码中使用typescript和jasmine框架运行量角器的文件

的package.json

{
  "name": "example-typescript",
  "version": "1.0.0",
  "description": "a typescript example",
  "author": "",
  "license": "MIT",
  "scripts": {
    "tsc": "tsc",
    "pretest": "npm run tsc",
    "test": "C:/Users/skp/AppData/Roaming/npm/node_modules/protractor/bin/protractor tmp/conf.js",
   "debug": "node --inspect --debug-brk C:/Users/skp/AppData/Roaming/npm/node_modules/protractor/bin/protractor asyncAwait/conf.js"
  },
  "dependencies": {
    "@types/jasmine": "2.5.41",
    "@types/jasminewd2": "^2.0.0",
    "jasmine": "^2.4.1",
    "protractor": "C:/Users/skp/AppData/Roaming/npm/node_modules/protractor/bin/protractor",
    "typescript": "~2.0.0"
  },
  "devDependencies": {
    "@types/jasminewd2": "^2.0.0",
    "ts-node": "^3.0.2"
  }
}

spec.ts

import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';

describe('protractor with typescript typings', () => {
  beforeEach(() => {
    browser.get('http://www.angularjs.org');
  });

  it('should greet the named user', () => {
    element(by.model('yourName')).sendKeys('Julie');
    let greeting = element(by.binding('yourName'));
    expect(greeting.getText()).toEqual('Hello Julie!');
  });

  it('should list todos', function() {
    let todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.count()).toEqual(2);
    expect(todoList.get(1).getText()).toEqual('build an angular app');
  });
});

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "inlineSourceMap": true,
    "declaration": false,
    "noImplicitAny": false,
    "outDir": "tmp"
  },
  "exclude": [
    "node_modules",
    "asyncAwait",
    "plugins.ts"
  ]
}

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我修复了以下问题:

1)我将"@types/jasmine": "2.5.41"替换为"@types/jasmine": "^2.5.51""typescript": "~2.0.0"

"typescript": "2.1"

2)我执行了npm install && npm test。我收到了一个新错误,所以接下来我做了两个步骤。

3)我执行了node_modules / .bin / webdriver-manager update

4)在conf.ts评论该线路 seleniumAddress: 'http://localhost:4444/wd/hub',

5)我执行npm test并且它有效。