Spectron测试产生JScript语法错误

时间:2017-05-30 20:03:27

标签: json node.js electron spectron

我正试图在测试方面测试电子的光谱,但是当我正在阅读教程时,每当我运行 npm run test:e2e 时,我都会收到此错误消息。我的测试文件在语法上是正确的,但我不确定为什么我会通过编译遇到错误

规格:

  • Nodejs 6.10.3

  • Electron 1.6.1

here's the error message

这是json文件 package.json

{
  "name": "your-app",
  "version": "0.1.0",
  "main": "main.js",
  "scripts": {
    "start": "C:/Users/Livs/Documents/imdc/logger/node_modules/.bin/electron .",
    "test:e2e": "C:/Users/Livs/Documents/imdc/logger/test.js"
  },
  "devDependencies": {
    "electron-chromedriver": "^1.7.1",
    "electron-prebuilt": "^1.4.13",
    "electron-rebuild": "^1.5.11",
    "chai": "^3.5.0",
    "chai-as-promised": "^5.3.0",
    "electron": "^1.3.4",
    "mocha": "^3.0.2",
    "spectron": "^3.4.0"
  }
}

继承测试文件 test.js

const Application = require('spectron').Application;
const path = require('path');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');

var electronPath = path.join(__dirname, '..', 'node_modules', '.bin',     'electron');

if (process.platform === 'win32') {
    electronPath += '.cmd';
}

var appPath = path.join(__dirname, '..');

var app = new Application({
            path: electronPath,
            args: [appPath]
        });

1 个答案:

答案 0 :(得分:0)

您的npm run e2e只是调用test.js文件。例如,您需要一个测试运行器mocha。然后你会运行mocha test.js。或者更改package.json中的e2e脚本以运行该命令。

package.json内脚本的所有文件路径都应该与包根相对,即logger/test.js。关于npm bin,您只需键入bin名称,即electron

要解决您的问题,您应该将package.json test:e2e命令更改为mocha test.js

(您也可以将start命令更改为electron .,因为自定义npm命令始终会在./node_modules/.bin

中查找二进制文件