浏览代码

add spectron basic test.

oldj 8 年之前
父节点
当前提交
8d41e18f27
共有 4 个文件被更改,包括 79 次插入3 次删除
  1. 1 1
      .gitignore
  2. 0 0
      app/build/bundle.js
  3. 34 2
      package.json
  4. 44 0
      test/index.js

+ 1 - 1
.gitignore

@@ -20,4 +20,4 @@ node_modules
 UserInterfaceState.xcuserstate
 xcdebugger
 npm-debug.log
-
+.nyc_output

文件差异内容过多而无法显示
+ 0 - 0
app/build/bundle.js


+ 34 - 2
package.json

@@ -4,7 +4,7 @@
   "description": "Homepage: [https://oldj.github.io/SwitchHosts/](https://oldj.github.io/SwitchHosts/)",
   "main": "",
   "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1",
+    "test": "nyc ava",
     "start": "electron app",
     "dev": "ENV=dev electron app",
     "build": "gulp ver && webpack -p",
@@ -26,10 +26,14 @@
   "homepage": "https://oldj.github.io/SwitchHosts/",
   "dependencies": {},
   "devDependencies": {
+    "ava": "^0.18.2",
     "babel-core": "^6.20.0",
     "babel-loader": "^6.2.9",
-    "babel-preset-latest": "^6.16.0",
+    "babel-polyfill": "^6.23.0",
+    "babel-preset-latest": "^6.22.0",
     "babel-preset-react": "^6.16.0",
+    "babel-preset-stage-0": "^6.22.0",
+    "babel-register": "^6.23.0",
     "css-loader": "^0.26.1",
     "electron-prebuilt": "^1.4.12",
     "file-loader": "^0.9.0",
@@ -38,10 +42,38 @@
     "js-beautify": "^1.6.4",
     "less": "^2.7.1",
     "less-loader": "^2.2.3",
+    "nyc": "^10.1.2",
+    "spectron": "^3.6.0",
     "style-loader": "^0.13.1",
     "uglify-loader": "^1.4.0",
     "url-loader": "^0.5.7",
     "webpack": "^2.2.1",
     "yargs": "^6.5.0"
+  },
+  "ava": {
+    "files": [
+      "src/**/*.ava.js",
+      "test/*.js",
+      "!**/node_modules/**/*.*"
+    ],
+    "source": [
+      "**/*.{js,jsx}",
+      "!dist/**/*"
+    ],
+    "match": [],
+    "concurrency": 5,
+    "failFast": true,
+    "tap": true,
+    "powerAssert": false,
+    "require": [
+      "babel-polyfill",
+      "babel-register"
+    ],
+    "babel": {
+      "presets": [
+        "latest",
+        "stage-0"
+      ]
+    }
   }
 }

+ 44 - 0
test/index.js

@@ -0,0 +1,44 @@
+/**
+ * @author oldj
+ * @blog https://oldj.net
+ */
+
+'use strict';
+
+const path = require('path');
+const {test} = require('ava');
+const assert = require('assert');
+const Application = require('spectron').Application;
+
+let appPath = path.resolve(__dirname, '../app');
+let electronPath = path.resolve(__dirname, '../node_modules/.bin/electron');
+
+test.beforeEach(async t => {
+    t.context.app = new Application({
+        path: electronPath,
+        args: [appPath]
+    });
+
+    await t.context.app.start();
+});
+
+test.afterEach(async t => {
+    await t.context.app.stop();
+});
+
+test('basic', async t => {
+    let app = t.context.app;
+
+    await app.client.waitUntilWindowLoaded();
+    const win = app.browserWindow;
+
+    t.is(await app.client.getWindowCount(), 1);
+    t.is(await app.client.getTitle(), 'SwitchHosts!');
+    t.false(await win.isMinimized());
+    t.false(await win.isDevToolsOpened());
+    t.true(await win.isVisible());
+
+    const {width, height} = await win.getBounds();
+    t.true(width > 0);
+    t.true(height > 0);
+});

部分文件因为文件数量过多而无法显示