From b97f80e4d94e6ed5abe8a6dadb1629712192783c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 8 Feb 2020 14:10:53 -0500 Subject: Setup GitHub actions --- package.json | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 package.json (limited to 'package.json') diff --git a/package.json b/package.json new file mode 100644 index 00000000..eb1fb25c --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "yomichan", + "version": "0.0.0", + "description": "Japanese pop-up dictionary extension for Chrome and Firefox.", + "directories": { + "test": "test" + }, + "scripts": { + "test": "npm run test-lint", + "test-lint": "eslint ." + }, + "repository": { + "type": "git", + "url": "git+https://github.com/FooSoft/yomichan.git" + }, + "author": "FooSoft", + "licenses": [ + { + "type": "GPLv3", + "url": "https://www.gnu.org/licenses/gpl-3.0.html" + } + ], + "bugs": { + "url": "https://github.com/FooSoft/yomichan/issues" + }, + "homepage": "https://foosoft.net/projects/yomichan/", + "devDependencies": { + "eslint": "^6.8.0" + } +} -- cgit v1.2.3 From e83167dcd1f40ed8c9fd0f2f1039717b61175e9e Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 11 Feb 2020 22:11:28 -0500 Subject: Add eslint-plugin-no-unsanitized --- .eslintrc.json | 5 ++++- package-lock.json | 6 ++++++ package.json | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'package.json') diff --git a/.eslintrc.json b/.eslintrc.json index d4ae215b..39c5e964 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,6 +10,7 @@ "es2017": true, "webextensions": true }, + "plugins": ["no-unsanitized"], "ignorePatterns": [ "/ext/mixed/lib/", "/ext/bg/js/templates.js" @@ -32,7 +33,9 @@ "quote-props": ["error", "consistent"], "quotes": ["error", "single", "avoid-escape"], "require-atomic-updates": "off", - "semi": "error" + "semi": "error", + "no-unsanitized/method": "error", + "no-unsanitized/property": "error" }, "overrides": [ { diff --git a/package-lock.json b/package-lock.json index 0d8eb27f..11cf28bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -264,6 +264,12 @@ "v8-compile-cache": "^2.0.3" } }, + "eslint-plugin-no-unsanitized": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-no-unsanitized/-/eslint-plugin-no-unsanitized-3.0.2.tgz", + "integrity": "sha512-JnwpoH8Sv4QOjrTDutENBHzSnyYtspdjtglYtqUtAHe6f6LLKqykJle+UwFPg23GGwt5hI3amS9CRDezW8GAww==", + "dev": true + }, "eslint-scope": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", diff --git a/package.json b/package.json index eb1fb25c..8e71de59 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "homepage": "https://foosoft.net/projects/yomichan/", "devDependencies": { - "eslint": "^6.8.0" + "eslint": "^6.8.0", + "eslint-plugin-no-unsanitized": "^3.0.2" } } -- cgit v1.2.3 From 174d9e7429a0f7a45538e56a594ce627239d80c3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 17 Feb 2020 14:20:22 -0500 Subject: Add some basic unit tests for JSON schemas --- .github/workflows/ci.yml | 8 +- package.json | 5 +- test/test-schema.js | 236 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 245 insertions(+), 4 deletions(-) create mode 100644 test/test-schema.js (limited to 'package.json') diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40bc005d..c65d254b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,11 @@ jobs: run: npm ci - name: Build run: npm run build --if-present - - name: Run tests - run: npm test + - name: Lint + run: npm run test-lint + env: + CI: true + - name: Tests + run: npm run test-code env: CI: true diff --git a/package.json b/package.json index 8e71de59..b486c25d 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,9 @@ "test": "test" }, "scripts": { - "test": "npm run test-lint", - "test-lint": "eslint ." + "test": "npm run test-lint && npm run test-code", + "test-lint": "eslint .", + "test-code": "node ./test/test-schema.js" }, "repository": { "type": "git", diff --git a/test/test-schema.js b/test/test-schema.js new file mode 100644 index 00000000..2f294e43 --- /dev/null +++ b/test/test-schema.js @@ -0,0 +1,236 @@ +const fs = require('fs'); +const path = require('path'); +const assert = require('assert'); + +const jsonSchemaFileName = path.join(__dirname, '../ext/bg/js/json-schema.js'); +const jsonSchemaFileSource = fs.readFileSync(jsonSchemaFileName, {encoding: 'utf8'}); +const JsonSchema = Function(`'use strict';${jsonSchemaFileSource};return JsonSchema;`)(); + + +function testValidate1() { + const schema = { + allOf: [ + { + type: 'number' + }, + { + anyOf: [ + {minimum: 10, maximum: 100}, + {minimum: -100, maximum: -10} + ] + }, + { + oneOf: [ + {multipleOf: 3}, + {multipleOf: 5} + ] + }, + { + not: [ + {multipleOf: 20} + ] + } + ] + }; + + const schemaValidate = (value, schema) => { + try { + JsonSchema.validate(value, schema); + return true; + } catch (e) { + return false; + } + }; + + const jsValidate = (value) => { + return ( + typeof value === 'number' && + ( + (value >= 10 && value <= 100) || + (value >= -100 && value <= -10) + ) && + ( + ( + (value % 3 )=== 0 || + (value % 5) === 0 + ) && + (value % 15) !== 0 + ) && + (value % 20) !== 0 + ); + }; + + for (let i = -111; i <= 111; i++) { + const actual = schemaValidate(i, schema); + const expected = jsValidate(i); + assert.strictEqual(actual, expected); + } +} + + +function testGetValidValueOrDefault1() { + // Test value defaulting on objects with additionalProperties=false + const schema = { + type: 'object', + required: ['test'], + properties: { + test: { + type: 'string', + default: 'default' + } + }, + additionalProperties: false + }; + + const testData = [ + [ + void(0), + {test: 'default'} + ], + [ + null, + {test: 'default'} + ], + [ + 0, + {test: 'default'} + ], + [ + '', + {test: 'default'} + ], + [ + [], + {test: 'default'} + ], + [ + {}, + {test: 'default'} + ], + [ + {test: 'value'}, + {test: 'value'} + ], + [ + {test2: 'value2'}, + {test: 'default'} + ], + [ + {test: 'value', test2: 'value2'}, + {test: 'value'} + ] + ]; + + for (const [value, expected] of testData) { + const actual = JsonSchema.getValidValueOrDefault(schema, value); + assert.deepStrictEqual(actual, expected); + } +} + +function testGetValidValueOrDefault2() { + // Test value defaulting on objects with additionalProperties=true + const schema = { + type: 'object', + required: ['test'], + properties: { + test: { + type: 'string', + default: 'default' + } + }, + additionalProperties: true + }; + + const testData = [ + [ + {}, + {test: 'default'} + ], + [ + {test: 'value'}, + {test: 'value'} + ], + [ + {test2: 'value2'}, + {test: 'default', test2: 'value2'} + ], + [ + {test: 'value', test2: 'value2'}, + {test: 'value', test2: 'value2'} + ] + ]; + + for (const [value, expected] of testData) { + const actual = JsonSchema.getValidValueOrDefault(schema, value); + assert.deepStrictEqual(actual, expected); + } +} + +function testGetValidValueOrDefault3() { + // Test value defaulting on objects with additionalProperties={schema} + const schema = { + type: 'object', + required: ['test'], + properties: { + test: { + type: 'string', + default: 'default' + } + }, + additionalProperties: { + type: 'number', + default: 10 + } + }; + + const testData = [ + [ + {}, + {test: 'default'} + ], + [ + {test: 'value'}, + {test: 'value'} + ], + [ + {test2: 'value2'}, + {test: 'default', test2: 10} + ], + [ + {test: 'value', test2: 'value2'}, + {test: 'value', test2: 10} + ], + [ + {test2: 2}, + {test: 'default', test2: 2} + ], + [ + {test: 'value', test2: 2}, + {test: 'value', test2: 2} + ], + [ + {test: 'value', test2: 2, test3: null}, + {test: 'value', test2: 2, test3: 10} + ], + [ + {test: 'value', test2: 2, test3: void(0)}, + {test: 'value', test2: 2, test3: 10} + ] + ]; + + for (const [value, expected] of testData) { + const actual = JsonSchema.getValidValueOrDefault(schema, value); + assert.deepStrictEqual(actual, expected); + } +} + + +function main() { + testValidate1(); + testGetValidValueOrDefault1(); + testGetValidValueOrDefault2(); + testGetValidValueOrDefault3(); +} + + +main(); -- cgit v1.2.3 From 03886eb83310d051cc2a8d2ab0bb69412239ddd8 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 18 Feb 2020 22:16:30 -0500 Subject: Add fake-indexeddb --- package-lock.json | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- 2 files changed, 100 insertions(+), 1 deletion(-) (limited to 'package.json') diff --git a/package-lock.json b/package-lock.json index 11cf28bc..505c71db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -93,6 +93,12 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, + "base64-arraybuffer-es6": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/base64-arraybuffer-es6/-/base64-arraybuffer-es6-0.5.0.tgz", + "integrity": "sha512-UCIPaDJrNNj5jG2ZL+nzJ7czvZV/ZYX6LaIRgfVU1k1edJOQg7dkbiSKzwHkNp6aHEHER/PhlFBrMYnlvJJQEw==", + "dev": true + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -162,6 +168,12 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "core-js": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", + "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==", + "dev": true + }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -207,6 +219,15 @@ "esutils": "^2.0.2" } }, + "domexception": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/domexception/-/domexception-1.0.1.tgz", + "integrity": "sha512-raigMkn7CJNNo6Ihro1fzG7wr3fHuYVytzquZKX5n0yizGsTcYgzdIUwj1X9pK0VvjeihV+XiclP+DjwbsSKug==", + "dev": true, + "requires": { + "webidl-conversions": "^4.0.2" + } + }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -353,6 +374,16 @@ "tmp": "^0.0.33" } }, + "fake-indexeddb": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/fake-indexeddb/-/fake-indexeddb-3.0.0.tgz", + "integrity": "sha512-VrnV9dJWlVWvd8hp9MMR+JS4RLC4ZmToSkuCg91ZwpYE5mSODb3n5VEaV62Hf3AusnbrPfwQhukU+rGZm5W8PQ==", + "dev": true, + "requires": { + "realistic-structured-clone": "^2.0.1", + "setimmediate": "^1.0.5" + } + }, "fast-deep-equal": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", @@ -601,6 +632,12 @@ "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", "dev": true }, + "lodash.sortby": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", + "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=", + "dev": true + }, "mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -732,6 +769,18 @@ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, + "realistic-structured-clone": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/realistic-structured-clone/-/realistic-structured-clone-2.0.2.tgz", + "integrity": "sha512-5IEvyfuMJ4tjQOuKKTFNvd+H9GSbE87IcendSBannE28PTrbolgaVg5DdEApRKhtze794iXqVUFKV60GLCNKEg==", + "dev": true, + "requires": { + "core-js": "^2.5.3", + "domexception": "^1.0.1", + "typeson": "^5.8.2", + "typeson-registry": "^1.0.0-alpha.20" + } + }, "regexpp": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", @@ -793,6 +842,12 @@ "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", "dev": true }, + "setimmediate": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=", + "dev": true + }, "shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", @@ -951,6 +1006,15 @@ "os-tmpdir": "~1.0.2" } }, + "tr46": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz", + "integrity": "sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=", + "dev": true, + "requires": { + "punycode": "^2.1.0" + } + }, "tslib": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", @@ -972,6 +1036,23 @@ "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", "dev": true }, + "typeson": { + "version": "5.18.2", + "resolved": "https://registry.npmjs.org/typeson/-/typeson-5.18.2.tgz", + "integrity": "sha512-Vetd+OGX05P4qHyHiSLdHZ5Z5GuQDrHHwSdjkqho9NSCYVSLSfRMjklD/unpHH8tXBR9Z/R05rwJSuMpMFrdsw==", + "dev": true + }, + "typeson-registry": { + "version": "1.0.0-alpha.34", + "resolved": "https://registry.npmjs.org/typeson-registry/-/typeson-registry-1.0.0-alpha.34.tgz", + "integrity": "sha512-2U0R5eFGJPaqha8HBAICJv6rW2x/cAVHizURHbcAo61Mpd47s+MDn67Ktxoyl9jWgsqCAibZsrldG8v/2ZuCaw==", + "dev": true, + "requires": { + "base64-arraybuffer-es6": "0.5.0", + "typeson": "5.18.2", + "whatwg-url": "7.1.0" + } + }, "uri-js": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", @@ -987,6 +1068,23 @@ "integrity": "sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g==", "dev": true }, + "webidl-conversions": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", + "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==", + "dev": true + }, + "whatwg-url": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.1.0.tgz", + "integrity": "sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==", + "dev": true, + "requires": { + "lodash.sortby": "^4.7.0", + "tr46": "^1.0.1", + "webidl-conversions": "^4.0.2" + } + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index b486c25d..4190741a 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "homepage": "https://foosoft.net/projects/yomichan/", "devDependencies": { "eslint": "^6.8.0", - "eslint-plugin-no-unsanitized": "^3.0.2" + "eslint-plugin-no-unsanitized": "^3.0.2", + "fake-indexeddb": "^3.0.0" } } -- cgit v1.2.3 From a31ac6857430ed7bea1e1500ef5643caca9b4347 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 18 Feb 2020 22:20:00 -0500 Subject: Update tests --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'package.json') diff --git a/package.json b/package.json index 4190741a..2bbc6a79 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "test": "npm run test-lint && npm run test-code", "test-lint": "eslint .", - "test-code": "node ./test/test-schema.js" + "test-code": "node ./test/test-schema.js && node ./test/test-dictionary.js && node ./test/test-database.js" }, "repository": { "type": "git", -- cgit v1.2.3 From f463e2e238b1616d58bf254ecb53de8b0dae6573 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 23 Feb 2020 11:49:10 -0500 Subject: Update license strings to remove npm warning --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'package.json') diff --git a/package.json b/package.json index 2bbc6a79..17fdfa82 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,10 @@ "url": "git+https://github.com/FooSoft/yomichan.git" }, "author": "FooSoft", + "license": "GPL-3.0-or-later", "licenses": [ { - "type": "GPLv3", + "type": "GPL-3.0-or-later", "url": "https://www.gnu.org/licenses/gpl-3.0.html" } ], -- cgit v1.2.3