Explorar el Código

test: update test script

Gerald hace 9 años
padre
commit
55e4a03fe1
Se han modificado 3 ficheros con 79 adiciones y 80 borrados
  1. 3 2
      package.json
  2. 0 15
      test/index.html
  3. 76 63
      test/test_background.js

+ 3 - 2
package.json

@@ -7,7 +7,8 @@
     "dev": "gulp watch",
     "i18n": "gulp i18n",
     "lint": "gulp lint",
-    "update": "node scripts/update"
+    "update": "node scripts/update",
+    "test": "mocha"
   },
   "description": "Violentmonkey",
   "devDependencies": {
@@ -26,8 +27,8 @@
     "html-minifier": "^2.1.0",
     "js-yaml": "^3.5.5",
     "merge2": "^1.0.2",
+    "mocha": "^3.1.2",
     "ncp": "^2.0.0",
-    "qunitjs": "^2.0.0-rc1",
     "through2": "^2.0.1"
   },
   "author": "Gerald <[email protected]>",

+ 0 - 15
test/index.html

@@ -1,15 +0,0 @@
-<!doctype html>
-<html>
-  <head>
-    <title>Violentmonkey Tests</title>
-    <link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
-    <script src="../src/public/lib/require-lite.js"></script>
-    <script src="../src/background/utils/tester.js"></script>
-  </head>
-  <body>
-    <div id="qunit"></div>
-    <script src="../node_modules/qunitjs/qunit/qunit.js"></script>
-    <script src="test_background.js"></script>
-    <script>define.use('tests/background');</script>
-  </body>
-</html>

+ 76 - 63
test/test_background.js

@@ -1,82 +1,95 @@
-define('tests/background', function (require, exports, module) {
-  var tester = require('utils/tester');
+const assert = require('assert');
+const tester = require('../src/background/utils/tester');
 
-  QUnit.module('utils/tester', function (hooks) {
-    hooks.beforeEach(function (assert) {
-      this.script = {
+describe('tester', () => {
+  describe('scheme', () => {
+    it('should match all', () => {
+      const script = {
         custom: {},
-        meta: {},
+        meta: {
+          match: [
+            '*://*/*',
+          ],
+        }
       };
+      assert.ok(tester.testURL('https://www.google.com/', script), 'should match `http | https`');
+      assert.ok(!tester.testURL('file:///Users/Gerald/file', script), 'should not match `file`');
     });
 
-    QUnit.module('test match', function (hooks) {
-      QUnit.module('match scheme', function (hooks) {
-        QUnit.test('match all', function (assert) {
-          this.script.meta.match = [
-            '*://*/*',
-          ];
-          assert.ok(tester.testURL('https://www.google.com/', this.script), 'should match `http | https`');
-          assert.ok(!tester.testURL('file:///Users/Gerald/file', this.script), 'should not match `file`');
-        });
-
-        QUnit.test('match exact', function (assert) {
-          this.script.meta.match = [
+    it('should match exact', () => {
+      const script = {
+        custom: {},
+        meta: {
+          match: [
             'http://*/*',
             'ftp://*/*',
             'file:///*',
-          ];
-          assert.ok(tester.testURL('http://www.google.com/', this.script), 'should match `http`');
-          assert.ok(!tester.testURL('https://www.google.com/', this.script), 'should not match `https`');
-          assert.ok(tester.testURL('file:///Users/Gerald/file', this.script), 'should match `file`');
-          assert.ok(tester.testURL('ftp://example.com/file', this.script), 'should match `ftp`');
-        });
-      });
-
-      QUnit.module('match host', function (hooks) {
-        QUnit.test('match all', function (assert) {
-          this.script.meta.match = [
-            '*://*/',
-          ];
-          assert.ok(tester.testURL('https://www.google.com/', this.script), 'should match any');
-        });
+          ],
+        },
+      };
+      assert.ok(tester.testURL('http://www.google.com/', script), 'should match `http`');
+      assert.ok(!tester.testURL('https://www.google.com/', script), 'should not match `https`');
+      assert.ok(tester.testURL('file:///Users/Gerald/file', script), 'should match `file`');
+      assert.ok(tester.testURL('ftp://example.com/file', script), 'should match `ftp`');
+    });
+  });
 
-        QUnit.test('match exact domain', function (assert) {
-          this.script.meta.match = [
+  describe('host', () => {
+    it('should match domain', () => {
+      const script = {
+        custom: {},
+        meta: {
+          match: [
             '*://docs.google.com/',
-          ];
-          assert.ok(tester.testURL('https://docs.google.com/', this.script), 'should match exact domain name');
-          assert.ok(!tester.testURL('https://sub.docs.google.com/', this.script), 'should not match subdomains');
-          assert.ok(!tester.testURL('https://docs.google.com.cn/', this.script), 'should not match suffixed domains');
-        });
+          ],
+        },
+      };
+      assert.ok(tester.testURL('https://docs.google.com/', script), 'should match exact domain name');
+      assert.ok(!tester.testURL('https://sub.docs.google.com/', script), 'should not match subdomains');
+      assert.ok(!tester.testURL('https://docs.google.com.cn/', script), 'should not match suffixed domains');
+    });
 
-        QUnit.test('match subdomains', function (assert) {
-          this.script.meta.match = [
+    it('should match subdomains', () => {
+      const script = {
+        custom: {},
+        meta: {
+          match: [
             '*://*.google.com/',
-          ];
-          assert.ok(tester.testURL('https://www.google.com/', this.script), 'should match subdomains');
-          assert.ok(tester.testURL('https://a.b.google.com/', this.script), 'should match subdomains');
-          assert.ok(tester.testURL('https://google.com/', this.script), 'should match specified domain');
-          assert.ok(!tester.testURL('https://www.google.com.hk/', this.script), 'should not match suffixed domains');
-        });
-      });
+          ],
+        },
+      };
+      assert.ok(tester.testURL('https://www.google.com/', script), 'should match subdomains');
+      assert.ok(tester.testURL('https://a.b.google.com/', script), 'should match subdomains');
+      assert.ok(tester.testURL('https://google.com/', script), 'should match specified domain');
+      assert.ok(!tester.testURL('https://www.google.com.hk/', script), 'should not match suffixed domains');
+    });
+  });
 
-      QUnit.module('match path', function (hooks) {
-        QUnit.test('match any', function (assert) {
-          this.script.meta.match = [
+  describe('path', () => {
+    it('should match any', () => {
+      const script = {
+        custom: {},
+        meta: {
+          match: [
             'https://www.google.com/*',
-          ];
-          assert.ok(tester.testURL('https://www.google.com/', this.script), 'should match `/`');
-          assert.ok(tester.testURL('https://www.google.com/hello/world', this.script), 'should match any');
-        });
+          ],
+        },
+      };
+      assert.ok(tester.testURL('https://www.google.com/', script), 'should match `/`');
+      assert.ok(tester.testURL('https://www.google.com/hello/world', script), 'should match any');
+    });
 
-        QUnit.test('match exact', function (assert) {
-          this.script.meta.match = [
+    it('should match exact', () => {
+      const script = {
+        custom: {},
+        meta: {
+          match: [
             'https://www.google.com/a/b/c',
-          ];
-          assert.ok(tester.testURL('https://www.google.com/a/b/c', this.script), 'should match exact');
-          assert.ok(!tester.testURL('https://www.google.com/a/b/c/d', this.script), 'should match exact');
-        });
-      });
+          ],
+        },
+      };
+      assert.ok(tester.testURL('https://www.google.com/a/b/c', script), 'should match exact');
+      assert.ok(!tester.testURL('https://www.google.com/a/b/c/d', script), 'should match exact');
     });
   });
 });