From 085d393ddb8500d041597684fd053596ca83cdfc Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:29:39 +0100 Subject: [PATCH] add: TS tests --- package-lock.json | 29 ++++++++++++++++++- package.json | 3 ++ test/{ => tests}/array.spec.js | 0 test/{zotero.spec.js => tests/zotero.spec.ts} | 0 test/tsconfig.json | 8 +++++ test/typings/global.d.ts | 6 ++++ tsconfig.json | 8 +++-- zotero-plugin.config.ts | 3 +- 8 files changed, 53 insertions(+), 4 deletions(-) rename test/{ => tests}/array.spec.js (100%) rename test/{zotero.spec.js => tests/zotero.spec.ts} (100%) create mode 100644 test/tsconfig.json create mode 100644 test/typings/global.d.ts diff --git a/package-lock.json b/package-lock.json index c9a3c2e0..fb136d4a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,15 +35,18 @@ "unist-util-visit": "^5.0.0", "unist-util-visit-parents": "^6.0.1", "yamljs": "^0.3.0", + "zotero-plugin-scaffold": "file:../zotero-plugin-scaffold", "zotero-plugin-toolkit": "^4.0.11" }, "devDependencies": { "@esbuild-plugins/node-globals-polyfill": "^0.2.3", "@prettier/plugin-xml": "^3.2.2", "@types/browser-or-node": "^1.3.2", + "@types/chai": "^5.0.1", "@types/diff": "^5.0.9", "@types/html-docx-js": "^0.3.4", "@types/katex": "^0.16.7", + "@types/mocha": "^10.0.10", "@types/node": "^20.10.4", "@types/path-browserify": "^1.0.2", "@types/seedrandom": "^3.0.8", @@ -68,7 +71,6 @@ }, "../zotero-plugin-scaffold": { "version": "0.1.7", - "extraneous": true, "license": "AGPL-3.0-or-later", "dependencies": { "@babel/generator": "^7.26.3", @@ -405,6 +407,15 @@ "integrity": "sha512-CkvJrvVMI4ZHbiL+Df22Owzq1IYnHnoSrM8s6Dmy4MRdqvdFi9bHsIvyFrSGJPOxvFI9Y3MqY2gFCqIafJBcfw==", "dev": true }, + "node_modules/@types/chai": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.0.1.tgz", + "integrity": "sha512-5T8ajsg3M/FOncpLYW7sdOcD6yf4+722sze/tc4KQV0P8Z2rAr3SAuHCIkYmYpt8VbcQlnz8SxlOlPQYefe4cA==", + "dev": true, + "dependencies": { + "@types/deep-eql": "*" + } + }, "node_modules/@types/debug": { "version": "4.1.12", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", @@ -413,6 +424,12 @@ "@types/ms": "*" } }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true + }, "node_modules/@types/diff": { "version": "5.0.9", "resolved": "https://registry.npmjs.org/@types/diff/-/diff-5.0.9.tgz", @@ -474,6 +491,12 @@ "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.10.tgz", "integrity": "sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==" }, + "node_modules/@types/mocha": { + "version": "10.0.10", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.10.tgz", + "integrity": "sha512-xPyYSz1cMPnJQhl0CLMH68j3gprKZaTjG3s5Vi+fDgx+uhG9NOXwbVt52eFS8ECyXhyKcjDLCBEqBExKuiZb7Q==", + "dev": true + }, "node_modules/@types/ms": { "version": "0.7.34", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.34.tgz", @@ -7648,6 +7671,10 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/zotero-plugin-scaffold": { + "resolved": "../zotero-plugin-scaffold", + "link": true + }, "node_modules/zotero-plugin-toolkit": { "version": "4.0.11", "resolved": "https://registry.npmjs.org/zotero-plugin-toolkit/-/zotero-plugin-toolkit-4.0.11.tgz", diff --git a/package.json b/package.json index 5ba8c377..2eb7bd80 100644 --- a/package.json +++ b/package.json @@ -57,15 +57,18 @@ "unist-util-visit": "^5.0.0", "unist-util-visit-parents": "^6.0.1", "yamljs": "^0.3.0", + "zotero-plugin-scaffold": "file:../zotero-plugin-scaffold", "zotero-plugin-toolkit": "^4.0.11" }, "devDependencies": { "@esbuild-plugins/node-globals-polyfill": "^0.2.3", "@prettier/plugin-xml": "^3.2.2", "@types/browser-or-node": "^1.3.2", + "@types/chai": "^5.0.1", "@types/diff": "^5.0.9", "@types/html-docx-js": "^0.3.4", "@types/katex": "^0.16.7", + "@types/mocha": "^10.0.10", "@types/node": "^20.10.4", "@types/path-browserify": "^1.0.2", "@types/seedrandom": "^3.0.8", diff --git a/test/array.spec.js b/test/tests/array.spec.js similarity index 100% rename from test/array.spec.js rename to test/tests/array.spec.js diff --git a/test/zotero.spec.js b/test/tests/zotero.spec.ts similarity index 100% rename from test/zotero.spec.js rename to test/tests/zotero.spec.ts diff --git a/test/tsconfig.json b/test/tsconfig.json new file mode 100644 index 00000000..edf75096 --- /dev/null +++ b/test/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "composite": true + }, + "include": ["./**/*.spec.ts", "typings", "../node_modules/zotero-types"], + "exclude": [] +} diff --git a/test/typings/global.d.ts b/test/typings/global.d.ts new file mode 100644 index 00000000..a1fcf880 --- /dev/null +++ b/test/typings/global.d.ts @@ -0,0 +1,6 @@ +import type * as chai from "chai"; + +declare global { + const expect: typeof chai.expect; + const assert: typeof chai.assert; +} diff --git a/tsconfig.json b/tsconfig.json index 71888461..f7f5bfb9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,8 +7,12 @@ "resolveJsonModule": true, "skipLibCheck": true, "alwaysStrict": false, - "strict": true + "strict": true, + "composite": true }, "include": ["src", "typings", "node_modules/zotero-types"], - "exclude": ["build", "addon"] + "exclude": ["build", "addon", "test"], + "references": [ + { "path": "./test" } + ] } diff --git a/zotero-plugin.config.ts b/zotero-plugin.config.ts index 9e0c532e..c88e1b9a 100644 --- a/zotero-plugin.config.ts +++ b/zotero-plugin.config.ts @@ -69,7 +69,8 @@ export default defineConfig({ entries: ["test/"], prefs: {}, abortOnFail: true, - exitOnFinish: true, + exitOnFinish: false, + hooks: {}, }, // If you need to see a more detailed build log, uncomment the following line: