From a68e07bd43bcafbb91b4b62e71bd6bdab4fed21f Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 23 Mar 2025 11:23:22 +0100 Subject: [PATCH 1/7] test: setup and cover current functions --- package-lock.json | 497 ++++++++++++++++++++---- package.json | 6 +- plugins/plugin-tools/src/config.spec.ts | 224 +++++++++++ plugins/plugin-tools/src/init.spec.ts | 94 +++++ tsconfig.json | 3 +- tsconfig.spec.json | 17 + vitest.config.ts | 11 + 7 files changed, 779 insertions(+), 73 deletions(-) create mode 100644 plugins/plugin-tools/src/config.spec.ts create mode 100644 plugins/plugin-tools/src/init.spec.ts create mode 100644 tsconfig.spec.json create mode 100644 vitest.config.ts diff --git a/package-lock.json b/package-lock.json index 244eeb0..501c863 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ "devDependencies": { "@types/node": "^22.13.10", "prettier": "^3.5.3", - "prettier-plugin-organize-imports": "^4.1.0" + "prettier-plugin-organize-imports": "^4.1.0", + "vitest": "^3.0.9" } }, "node_modules/@ampproject/remapping": { @@ -467,7 +468,6 @@ "os": [ "aix" ], - "peer": true, "engines": { "node": ">=12" } @@ -483,7 +483,6 @@ "os": [ "android" ], - "peer": true, "engines": { "node": ">=12" } @@ -499,7 +498,6 @@ "os": [ "android" ], - "peer": true, "engines": { "node": ">=12" } @@ -515,7 +513,6 @@ "os": [ "android" ], - "peer": true, "engines": { "node": ">=12" } @@ -531,7 +528,6 @@ "os": [ "darwin" ], - "peer": true, "engines": { "node": ">=12" } @@ -547,7 +543,6 @@ "os": [ "darwin" ], - "peer": true, "engines": { "node": ">=12" } @@ -563,7 +558,6 @@ "os": [ "freebsd" ], - "peer": true, "engines": { "node": ">=12" } @@ -579,7 +573,6 @@ "os": [ "freebsd" ], - "peer": true, "engines": { "node": ">=12" } @@ -595,7 +588,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=12" } @@ -611,7 +603,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=12" } @@ -627,7 +618,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=12" } @@ -643,7 +633,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=12" } @@ -659,7 +648,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=12" } @@ -675,7 +663,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=12" } @@ -691,7 +678,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=12" } @@ -707,7 +693,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=12" } @@ -723,7 +708,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=12" } @@ -739,7 +723,6 @@ "os": [ "netbsd" ], - "peer": true, "engines": { "node": ">=12" } @@ -755,7 +738,6 @@ "os": [ "openbsd" ], - "peer": true, "engines": { "node": ">=12" } @@ -771,7 +753,6 @@ "os": [ "sunos" ], - "peer": true, "engines": { "node": ">=12" } @@ -787,7 +768,6 @@ "os": [ "win32" ], - "peer": true, "engines": { "node": ">=12" } @@ -803,7 +783,6 @@ "os": [ "win32" ], - "peer": true, "engines": { "node": ">=12" } @@ -819,7 +798,6 @@ "os": [ "win32" ], - "peer": true, "engines": { "node": ">=12" } @@ -863,8 +841,7 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.25", @@ -1068,8 +1045,7 @@ "optional": true, "os": [ "android" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-android-arm64": { "version": "4.14.1", @@ -1081,8 +1057,7 @@ "optional": true, "os": [ "android" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-darwin-arm64": { "version": "4.14.1", @@ -1094,8 +1069,7 @@ "optional": true, "os": [ "darwin" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-darwin-x64": { "version": "4.14.1", @@ -1107,8 +1081,7 @@ "optional": true, "os": [ "darwin" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { "version": "4.14.1", @@ -1120,8 +1093,7 @@ "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { "version": "4.14.1", @@ -1133,8 +1105,7 @@ "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { "version": "4.14.1", @@ -1146,8 +1117,7 @@ "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { "version": "4.14.1", @@ -1159,8 +1129,7 @@ "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { "version": "4.14.1", @@ -1172,8 +1141,7 @@ "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { "version": "4.14.1", @@ -1185,8 +1153,7 @@ "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { "version": "4.14.1", @@ -1198,8 +1165,7 @@ "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-linux-x64-musl": { "version": "4.14.1", @@ -1211,8 +1177,7 @@ "optional": true, "os": [ "linux" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { "version": "4.14.1", @@ -1224,8 +1189,7 @@ "optional": true, "os": [ "win32" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { "version": "4.14.1", @@ -1237,8 +1201,7 @@ "optional": true, "os": [ "win32" - ], - "peer": true + ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { "version": "4.14.1", @@ -1250,8 +1213,7 @@ "optional": true, "os": [ "win32" - ], - "peer": true + ] }, "node_modules/@swc/counter": { "version": "0.1.3", @@ -1272,8 +1234,7 @@ "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", - "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", - "peer": true + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==" }, "node_modules/@types/node": { "version": "22.13.10", @@ -1285,6 +1246,129 @@ "undici-types": "~6.20.0" } }, + "node_modules/@vitest/expect": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-3.0.9.tgz", + "integrity": "sha512-5eCqRItYgIML7NNVgJj6TVCmdzE7ZVgJhruW0ziSQV4V7PvLkDL1bBkBdcTs/VuIz0IxPb5da1IDSqc1TR9eig==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "3.0.9", + "@vitest/utils": "3.0.9", + "chai": "^5.2.0", + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/mocker": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-3.0.9.tgz", + "integrity": "sha512-ryERPIBOnvevAkTq+L1lD+DTFBRcjueL9lOUfXsLfwP92h4e+Heb+PjiqS3/OURWPtywfafK0kj++yDFjWUmrA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "3.0.9", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.17" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9", + "vite": "^5.0.0 || ^6.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/pretty-format": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-3.0.9.tgz", + "integrity": "sha512-OW9F8t2J3AwFEwENg3yMyKWweF7oRJlMyHOMIhO5F3n0+cgQAJZBjNgrF8dLwFTEXl5jUqBLXd9QyyKv8zEcmA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-3.0.9.tgz", + "integrity": "sha512-NX9oUXgF9HPfJSwl8tUZCMP1oGx2+Sf+ru6d05QjzQz4OwWg0psEzwY6VexP2tTHWdOkhKHUIZH+fS6nA7jfOw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/utils": "3.0.9", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-3.0.9.tgz", + "integrity": "sha512-AiLUiuZ0FuA+/8i19mTYd+re5jqjEc2jZbgJ2up0VY0Ddyyxg/uUtBDpIFAy4uzKaQxOW8gMgBdAJJ2ydhu39A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "3.0.9", + "magic-string": "^0.30.17", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/spy": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-3.0.9.tgz", + "integrity": "sha512-/CcK2UDl0aQ2wtkp3YVWldrpLRNCfVcIOFGlVGKO4R5eajsH393Z1yiXLVQ7vWsj26JOEjeZI0x5sm5P4OGUNQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyspy": "^3.0.2" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/utils": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-3.0.9.tgz", + "integrity": "sha512-ilHM5fHhZ89MCp5aAaM9uhfl1c2JdxVxl3McqsdVyVNN6JffnEen8UMCdRTzOhGXNQGo5GNL9QugHrz727Wnng==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "3.0.9", + "loupe": "^3.1.3", + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/browserslist": { "version": "4.24.4", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.24.4.tgz", @@ -1330,6 +1414,16 @@ "node": ">=10.16.0" } }, + "node_modules/cac": { + "version": "6.7.14", + "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", + "integrity": "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/caniuse-lite": { "version": "1.0.30001706", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001706.tgz", @@ -1351,6 +1445,33 @@ "license": "CC-BY-4.0", "peer": true }, + "node_modules/chai": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-5.2.0.tgz", + "integrity": "sha512-mCuXncKXk5iCLhfhwTc0izo0gtEmpz5CtG2y8GiOINBlMVS6v8TMRc5TaLWKS6692m9+dVVfzgeVxR5UxWHTYw==", + "dev": true, + "license": "MIT", + "dependencies": { + "assertion-error": "^2.0.1", + "check-error": "^2.1.1", + "deep-eql": "^5.0.1", + "loupe": "^3.1.0", + "pathval": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/check-error": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.1.tgz", + "integrity": "sha512-OAlb+T7V4Op9OwdkjmguYRqncdlx5JiofwOAUkmTF+jNdHwzTaTs4sRAGpzLF3oOz5xAyDGrPgeIDFQmDOTiJw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 16" + } + }, "node_modules/client-only": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz", @@ -1369,7 +1490,6 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "license": "MIT", - "peer": true, "dependencies": { "ms": "^2.1.3" }, @@ -1382,6 +1502,16 @@ } } }, + "node_modules/deep-eql": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz", + "integrity": "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/electron-to-chromium": { "version": "1.5.122", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.122.tgz", @@ -1389,12 +1519,18 @@ "license": "ISC", "peer": true }, + "node_modules/es-module-lexer": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.6.0.tgz", + "integrity": "sha512-qqnD1yMU6tk/jnaMosogGySTZP8YtUgAffA9nMN+E/rjxcfRQ6IEk7IiozUjgxKoFHBGjTLnrHB/YC45r/59EQ==", + "dev": true, + "license": "MIT" + }, "node_modules/esbuild": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.20.2.tgz", "integrity": "sha512-WdOOppmUNU+IbZ0PaDiTst80zjnrOkyJNHoKupIcVyU8Lvla3Ugx94VzkQ32Ijqd7UhHJy75gNWDMUekcrSJ6g==", "hasInstallScript": true, - "peer": true, "bin": { "esbuild": "bin/esbuild" }, @@ -1437,6 +1573,26 @@ "node": ">=6" } }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/expect-type": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.2.0.tgz", + "integrity": "sha512-80F22aiJ3GLyVnS/B3HzgR6RelZVumzj9jkL0Rhz4h0xYbNW9PjlQz5h3J/SShErbXBc295vseR4/MIbVmUbeA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -1446,7 +1602,6 @@ "os": [ "darwin" ], - "peer": true, "engines": { "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } @@ -1521,6 +1676,13 @@ "loose-envify": "cli.js" } }, + "node_modules/loupe": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.1.3.tgz", + "integrity": "sha512-kkIp7XSkP78ZxJEsSxW3712C6teJVoeHHwgo9zJ380de7IYyJ2ISlxojcH2pC5OFLewESmnRi/+XCDIEEVyoug==", + "dev": true, + "license": "MIT" + }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -1531,12 +1693,21 @@ "yallist": "^3.0.2" } }, + "node_modules/magic-string": { + "version": "0.30.17", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz", + "integrity": "sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/nanoid": { "version": "3.3.7", @@ -1548,7 +1719,6 @@ "url": "https://github.com/sponsors/ai" } ], - "peer": true, "bin": { "nanoid": "bin/nanoid.cjs" }, @@ -1613,12 +1783,28 @@ "license": "MIT", "peer": true }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, + "node_modules/pathval": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.0.tgz", + "integrity": "sha512-vE7JKRyES09KiunauX7nd2Q9/L7lhok4smP9RZTDeD4MVs72Dp2qNFVz39Nz5a0FVEW0BJR6C0DYrq6unoziZA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14.16" + } + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", - "license": "ISC", - "peer": true + "license": "ISC" }, "node_modules/postcss": { "version": "8.4.31", @@ -1710,7 +1896,6 @@ "version": "4.14.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.14.1.tgz", "integrity": "sha512-4LnHSdd3QK2pa1J6dFbfm1HN0D7vSK/ZuZTsdyUAlA6Rr1yTouUTL13HaDOGJVgby461AhrNGBS7sCGXXtT+SA==", - "peer": true, "dependencies": { "@types/estree": "1.0.5" }, @@ -1759,15 +1944,35 @@ "semver": "bin/semver.js" } }, + "node_modules/siginfo": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", + "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", + "dev": true, + "license": "ISC" + }, "node_modules/source-map-js": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", "integrity": "sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==", - "peer": true, "engines": { "node": ">=0.10.0" } }, + "node_modules/stackback": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", + "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", + "dev": true, + "license": "MIT" + }, + "node_modules/std-env": { + "version": "3.8.1", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.8.1.tgz", + "integrity": "sha512-vj5lIj3Mwf9D79hBkltk5qmkFI+biIKWS2IBxEyEU3AX1tUf7AoL8nSazCOiiqQsGKIq01SClsKEzweu34uwvA==", + "dev": true, + "license": "MIT" + }, "node_modules/streamsearch": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", @@ -1800,6 +2005,50 @@ } } }, + "node_modules/tinybench": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", + "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyexec": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-0.3.2.tgz", + "integrity": "sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinypool": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/tinypool/-/tinypool-1.0.2.tgz", + "integrity": "sha512-al6n+QEANGFOMf/dmUMsuS5/r9B06uwlyNjZZql/zv8J7ybHCgoihBNORZCY2mzUuAnomQa2JdhyHKzZxPCrFA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.0.0 || >=20.0.0" + } + }, + "node_modules/tinyrainbow": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-2.0.0.tgz", + "integrity": "sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/tinyspy": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-3.0.2.tgz", + "integrity": "sha512-n1cw8k1k0x4pgA2+9XrOkFydTerNcJ1zWCO5Nn9scWHTD+5tp8dghT2x1uduQePZTZgd3Tupf+x9BxJjeJi77Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/tslib": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", @@ -1862,7 +2111,6 @@ "version": "5.2.8", "resolved": "https://registry.npmjs.org/vite/-/vite-5.2.8.tgz", "integrity": "sha512-OyZR+c1CE8yeHw5V5t59aXsUPPVTHMDjEZz8MgguLL/Q7NblxhZUlTu9xSPqlsUO/y+X7dlU05jdhvyycD55DA==", - "peer": true, "dependencies": { "esbuild": "^0.20.1", "postcss": "^8.4.38", @@ -1913,6 +2161,29 @@ } } }, + "node_modules/vite-node": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/vite-node/-/vite-node-3.0.9.tgz", + "integrity": "sha512-w3Gdx7jDcuT9cNn9jExXgOyKmf5UOTb6WMHz8LGAm54eS1Elf5OuBhCxl6zJxGhEeIkgsE1WbHuoL0mj/UXqXg==", + "dev": true, + "license": "MIT", + "dependencies": { + "cac": "^6.7.14", + "debug": "^4.4.0", + "es-module-lexer": "^1.6.0", + "pathe": "^2.0.3", + "vite": "^5.0.0 || ^6.0.0" + }, + "bin": { + "vite-node": "vite-node.mjs" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, "node_modules/vite/node_modules/postcss": { "version": "8.4.38", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.38.tgz", @@ -1931,7 +2202,6 @@ "url": "https://github.com/sponsors/ai" } ], - "peer": true, "dependencies": { "nanoid": "^3.3.7", "picocolors": "^1.0.0", @@ -1941,6 +2211,93 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/vitest": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-3.0.9.tgz", + "integrity": "sha512-BbcFDqNyBlfSpATmTtXOAOj71RNKDDvjBM/uPfnxxVGrG+FSH2RQIwgeEngTaTkuU/h0ScFvf+tRcKfYXzBybQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/expect": "3.0.9", + "@vitest/mocker": "3.0.9", + "@vitest/pretty-format": "^3.0.9", + "@vitest/runner": "3.0.9", + "@vitest/snapshot": "3.0.9", + "@vitest/spy": "3.0.9", + "@vitest/utils": "3.0.9", + "chai": "^5.2.0", + "debug": "^4.4.0", + "expect-type": "^1.1.0", + "magic-string": "^0.30.17", + "pathe": "^2.0.3", + "std-env": "^3.8.0", + "tinybench": "^2.9.0", + "tinyexec": "^0.3.2", + "tinypool": "^1.0.2", + "tinyrainbow": "^2.0.0", + "vite": "^5.0.0 || ^6.0.0", + "vite-node": "3.0.9", + "why-is-node-running": "^2.3.0" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@types/debug": "^4.1.12", + "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0", + "@vitest/browser": "3.0.9", + "@vitest/ui": "3.0.9", + "happy-dom": "*", + "jsdom": "*" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@types/debug": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + } + } + }, + "node_modules/why-is-node-running": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz", + "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==", + "dev": true, + "license": "MIT", + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", diff --git a/package.json b/package.json index 4513dec..e359540 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,15 @@ "scripts": { "build": "npm run build --workspaces", "format": "prettier --write .", - "format:check": "prettier --check ." + "format:check": "prettier --check .", + "test": "vitest" }, "author": "", "license": "MIT", "devDependencies": { "@types/node": "^22.13.10", "prettier": "^3.5.3", - "prettier-plugin-organize-imports": "^4.1.0" + "prettier-plugin-organize-imports": "^4.1.0", + "vitest": "^3.0.9" } } diff --git a/plugins/plugin-tools/src/config.spec.ts b/plugins/plugin-tools/src/config.spec.ts new file mode 100644 index 0000000..59b44cb --- /dev/null +++ b/plugins/plugin-tools/src/config.spec.ts @@ -0,0 +1,224 @@ +import {JunoConfig} from '@junobuild/config'; +import * as configLoader from '@junobuild/config-loader'; +import {beforeEach, describe, expect, it, vi} from 'vitest'; +import { + assertJunoConfig, + container, + icpIds, + orbiterId, + satelliteId, + useDockerContainer +} from './config'; +import {JunoPluginError} from './error'; + +vi.mock('@junobuild/config-loader', async () => { + const actual = await vi.importActual( + '@junobuild/config-loader' + ); + + return { + ...actual, + junoConfigExist: vi.fn(), + readJunoConfig: vi.fn() + }; +}); + +describe('config', () => { + describe('useDockerContainer', () => { + it('returns true if container is true and mode is development', () => { + expect(useDockerContainer({params: {container: true}, mode: 'development'})).toBe(true); + }); + + it('returns false if container is false', () => { + expect(useDockerContainer({params: {container: false}, mode: 'development'})).toBe(false); + }); + + it('returns false in production mode', () => { + expect(useDockerContainer({params: {container: true}, mode: 'production'})).toBe(false); + }); + + it('returns true if container has matching mode in modes[]', () => { + expect( + useDockerContainer({ + params: { + container: { + modes: ['development', 'test'] + } + }, + mode: 'development' + }) + ).toBe(true); + }); + + it('returns false if container has non-matching mode in modes[]', () => { + expect( + useDockerContainer({ + params: { + container: { + modes: ['test'] + } + }, + mode: 'production' + }) + ).toBe(false); + }); + + it('returns true if container has no modes[] (default to development)', () => { + expect( + useDockerContainer({ + params: { + container: { + url: 'http://custom' + } + }, + mode: 'development' + }) + ).toBe(true); + }); + }); + + describe('satelliteId', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('returns docker satellite ID in dev mode with container true', async () => { + const id = await satelliteId({params: {container: true}, mode: 'development'}); + expect(id).toBe('jx5yt-yyaaa-aaaal-abzbq-cai'); + }); + + it('reads config if not using docker', async () => { + vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(true); + + vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValue({ + satellite: {ids: {production: 'prod-sat-id'}} + }); + + const id = await satelliteId({params: {container: false}, mode: 'production'}); + expect(id).toBe('prod-sat-id'); + }); + + it('throws if satellite ID is missing', async () => { + vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(true); + vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValue({ + satellite: {} + } as unknown as JunoConfig); + + await expect(() => satelliteId({params: {}, mode: 'production'})).rejects.toThrow( + JunoPluginError + ); + }); + }); + + describe('orbiterId', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('returns undefined if using docker', async () => { + const id = await orbiterId({params: {container: true}, mode: 'development'}); + expect(id).toBeUndefined(); + }); + + it('returns orbiter ID from config', async () => { + vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(true); + vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValue({ + orbiter: {id: 'orb-id'} + } as unknown as JunoConfig); + + const id = await orbiterId({params: {}, mode: 'production'}); + expect(id).toBe('orb-id'); + }); + }); + + describe('icpIds', () => { + it('returns static ICP IDs', () => { + expect(icpIds()).toEqual({ + internetIdentityId: 'rdmx6-jaaaa-aaaaa-aaadq-cai', + icpLedgerId: 'ryjl3-tyaaa-aaaaa-aaaba-cai', + icpIndexId: 'qhbym-qaaaa-aaaaa-aaafq-cai' + }); + }); + }); + + describe('container', () => { + it('returns default container URL if container is true', () => { + expect(container({params: {container: true}, mode: 'development'})).toBe( + 'http://127.0.0.1:5987' + ); + }); + + it('returns custom container URL if set', () => { + expect( + container({ + params: {container: {url: 'http://custom-url'}}, + mode: 'development' + }) + ).toBe('http://custom-url'); + }); + + it('returns undefined if not using docker', () => { + expect(container({params: {container: false}, mode: 'development'})).toBeUndefined(); + }); + + it('returns default URL if container is true', () => { + const url = container({params: {container: true}, mode: 'development'}); + expect(url).toBe('http://127.0.0.1:5987'); + }); + + it('returns undefined in production when container is true', () => { + const url = container({params: {container: true}, mode: 'production'}); + expect(url).toBeUndefined(); + }); + + it('returns custom URL from container object', () => { + const url = container({ + params: { + container: { + url: 'http://custom-container.local' + } + }, + mode: 'development' + }); + expect(url).toBe('http://custom-container.local'); + }); + + it('falls back to default URL if container object has no url field', () => { + const url = container({ + params: { + container: { + modes: ['development'] + } + }, + mode: 'development' + }); + expect(url).toBe('http://127.0.0.1:5987'); + }); + + it('returns undefined if container is false', () => { + const url = container({ + params: { + container: false + }, + mode: 'development' + }); + expect(url).toBeUndefined(); + }); + }); + + describe('assertJunoConfig', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('throws if config does not exist', async () => { + vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(false); + await expect(assertJunoConfig()).rejects.toThrow(JunoPluginError); + }); + + it('resolves if config exists', async () => { + vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(true); + await expect(assertJunoConfig()).resolves.toBeUndefined(); + }); + }); +}); diff --git a/plugins/plugin-tools/src/init.spec.ts b/plugins/plugin-tools/src/init.spec.ts new file mode 100644 index 0000000..da0c6df --- /dev/null +++ b/plugins/plugin-tools/src/init.spec.ts @@ -0,0 +1,94 @@ +import type {JunoConfig} from '@junobuild/config'; +import * as configLoader from '@junobuild/config-loader'; +import {beforeEach, describe, expect, it, MockInstance, vi} from 'vitest'; +import {initConfig} from './init'; +import type {ConfigArgs} from './types'; + +vi.mock('@junobuild/config-loader', async () => { + const actual = await vi.importActual( + '@junobuild/config-loader' + ); + + return { + ...actual, + junoConfigExist: vi.fn(), + readJunoConfig: vi.fn() + }; +}); + +describe('init', () => { + describe('initConfig (with config-loader mocks)', () => { + const args: ConfigArgs = { + params: {}, + mode: 'development' + }; + + let spyJunoConfigExist: MockInstance; + let spyReadJunoConfig: MockInstance; + + beforeEach(() => { + vi.clearAllMocks(); + + spyJunoConfigExist = vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(true); + spyReadJunoConfig = vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValue({ + satellite: {ids: {development: 'mock-satellite-id'}}, + orbiter: {id: 'mock-orbiter-id'} + }); + }); + + it('returns config when not using Docker container', async () => { + const result = await initConfig(args); + + expect(result).toEqual({ + satelliteId: 'mock-satellite-id', + orbiterId: 'mock-orbiter-id', + icpIds: { + internetIdentityId: 'rdmx6-jaaaa-aaaaa-aaadq-cai', + icpLedgerId: 'ryjl3-tyaaa-aaaaa-aaaba-cai', + icpIndexId: 'qhbym-qaaaa-aaaaa-aaafq-cai' + }, + container: undefined + }); + + expect(spyJunoConfigExist).toHaveBeenCalled(); + expect(spyReadJunoConfig).toHaveBeenCalled(); + }); + + it('skips assertJunoConfig when using Docker container', async () => { + const dockerArgs: ConfigArgs = { + params: {container: true}, + mode: 'development' + }; + + const result = await initConfig(dockerArgs); + + expect(result).toEqual({ + satelliteId: 'jx5yt-yyaaa-aaaal-abzbq-cai', // fallback to docker const + orbiterId: undefined, + icpIds: { + internetIdentityId: 'rdmx6-jaaaa-aaaaa-aaadq-cai', + icpLedgerId: 'ryjl3-tyaaa-aaaaa-aaaba-cai', + icpIndexId: 'qhbym-qaaaa-aaaaa-aaafq-cai' + }, + container: 'http://127.0.0.1:5987' + }); + + expect(spyJunoConfigExist).not.toHaveBeenCalled(); + expect(spyReadJunoConfig).not.toHaveBeenCalled(); + }); + + it('throws if config does not exist', async () => { + vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(false); + + await expect(initConfig(args)).rejects.toThrow(/No Juno configuration found/); + }); + + it('throws if satelliteId is missing in config', async () => { + vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValueOnce({ + satellite: {} + } as unknown as JunoConfig); + + await expect(initConfig(args)).rejects.toThrow(/A satellite ID for development must be set/); + }); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index 285e1e4..f4cc564 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,5 +11,6 @@ "resolveJsonModule": true, "skipLibCheck": true, "declaration": true - } + }, + "exclude": ["**/src/**/*.test.ts", "**/src/**/*.spec.ts", "**/src/**/*.mock.ts"] } diff --git a/tsconfig.spec.json b/tsconfig.spec.json new file mode 100644 index 0000000..db1da5f --- /dev/null +++ b/tsconfig.spec.json @@ -0,0 +1,17 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "allowArbitraryExtensions": true, + "baseUrl": ".", + "types": ["vitest/globals", "node"] + }, + "exclude": [] +} diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..93584ef --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,11 @@ +import {defineConfig} from 'vitest/config'; + +export default defineConfig({ + test: { + watch: false, + passWithNoTests: true, + typecheck: { + tsconfig: 'tsconfig.spec.json' + } + } +}); From 7b3cab10eee25949e6b26f8ee41ee26bdae0125e Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 23 Mar 2025 11:38:48 +0100 Subject: [PATCH 2/7] test: plugins --- plugins/nextjs-plugin/src/index.spec.ts | 114 ++++++++++++++++++++++++ plugins/vite-plugin/src/index.spec.ts | 57 ++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 plugins/nextjs-plugin/src/index.spec.ts create mode 100644 plugins/vite-plugin/src/index.spec.ts diff --git a/plugins/nextjs-plugin/src/index.spec.ts b/plugins/nextjs-plugin/src/index.spec.ts new file mode 100644 index 0000000..86a3997 --- /dev/null +++ b/plugins/nextjs-plugin/src/index.spec.ts @@ -0,0 +1,114 @@ +import * as pluginTools from '@junobuild/plugin-tools'; +import {JunoPluginError} from '@junobuild/plugin-tools'; +import {beforeEach, describe, expect, it, vi} from 'vitest'; +import {withJuno} from './index'; + +vi.mock('@junobuild/plugin-tools', async () => { + const actual = + await vi.importActual('@junobuild/plugin-tools'); + + return { + ...actual, + initConfig: vi.fn() + }; +}); + +describe('withJuno', () => { + beforeEach(() => { + vi.clearAllMocks(); + // @ts-expect-error + process.env.NODE_ENV = 'development'; + }); + + it('merges config and sets all env vars', async () => { + const spy = vi.spyOn(pluginTools, 'initConfig').mockResolvedValue({ + satelliteId: 'sat-id', + orbiterId: 'orb-id', + icpIds: { + internetIdentityId: 'ii-id', + icpLedgerId: 'ledger-id', + icpIndexId: 'index-id' + }, + container: 'http://localhost:1234' + }); + + const result = await withJuno(); + + expect(spy).toHaveBeenCalledWith({ + params: undefined, + mode: 'development' + }); + + expect(result).toEqual({ + output: 'export', + env: { + NEXT_PUBLIC_SATELLITE_ID: 'sat-id', + NEXT_PUBLIC_ORBITER_ID: 'orb-id', + NEXT_PUBLIC_INTERNET_IDENTITY_ID: 'ii-id', + NEXT_PUBLIC_ICP_LEDGER_ID: 'ledger-id', + NEXT_PUBLIC_ICP_INDEX_ID: 'index-id', + NEXT_PUBLIC_CONTAINER: 'http://localhost:1234' + } + }); + }); + + it('respects custom env prefix', async () => { + vi.spyOn(pluginTools, 'initConfig').mockResolvedValue({ + satelliteId: 'sat-id', + orbiterId: undefined, + icpIds: undefined, + container: undefined + }); + + const result = await withJuno({prefix: 'CUSTOM_'}); + + expect(result.env?.CUSTOM_SATELLITE_ID).toBe('sat-id'); + expect(result.env?.NEXT_PUBLIC_SATELLITE_ID).toBeUndefined(); + }); + + it('merges with existing nextConfig', async () => { + vi.spyOn(pluginTools, 'initConfig').mockResolvedValue({ + satelliteId: 'sat-id', + orbiterId: undefined, + icpIds: undefined, + container: undefined + }); + + const result = await withJuno({ + nextConfig: { + output: 'standalone', + env: { + FOO: 'bar' + } + } + }); + + expect(result).toEqual({ + output: 'standalone', + env: { + FOO: 'bar', + NEXT_PUBLIC_SATELLITE_ID: 'sat-id' + } + }); + }); + + it('logs and returns base config on JunoPluginError in non-production', async () => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + vi.spyOn(pluginTools, 'initConfig').mockRejectedValue( + new JunoPluginError('Juno config missing') + ); + + const result = await withJuno({ + nextConfig: {output: 'standalone'} + }); + + expect(warn).toHaveBeenCalledWith('Juno config missing'); + expect(result).toEqual({output: 'standalone'}); + }); + + it('throws unknown errors', async () => { + vi.spyOn(pluginTools, 'initConfig').mockRejectedValue(new Error('Boom')); + + await expect(() => withJuno()).rejects.toThrow('Boom'); + }); +}); diff --git a/plugins/vite-plugin/src/index.spec.ts b/plugins/vite-plugin/src/index.spec.ts new file mode 100644 index 0000000..cab9c2b --- /dev/null +++ b/plugins/vite-plugin/src/index.spec.ts @@ -0,0 +1,57 @@ +import * as pluginTools from '@junobuild/plugin-tools'; +import type {UserConfig} from 'vite'; +import {beforeEach, describe, expect, it, vi} from 'vitest'; +import Juno from './index'; + +vi.mock('@junobuild/plugin-tools', async () => { + const actual = + await vi.importActual('@junobuild/plugin-tools'); + + return { + ...actual, + initConfig: vi.fn() + }; +}); + +describe('vite-plugin-juno', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('calls initConfig and returns expected define values', async () => { + const spyInitConfig = vi.spyOn(pluginTools, 'initConfig').mockResolvedValue({ + satelliteId: 'sat-id', + orbiterId: 'orb-id', + icpIds: { + internetIdentityId: 'ii-id', + icpLedgerId: 'ledger-id', + icpIndexId: 'index-id' + }, + container: 'http://localhost:1234' + }); + + const plugin = Juno() as unknown as { + config: ( + {envPrefix}: UserConfig, + {mode}: {mode: string; command: string} + ) => Promise<{define: Record}>; + }; + const result = await plugin.config({}, {mode: 'development', command: 'serve'}); + + expect(spyInitConfig).toHaveBeenCalledWith({ + params: undefined, + mode: 'development' + }); + + expect(result).toEqual({ + define: { + 'import.meta.env.VITE_SATELLITE_ID': JSON.stringify('sat-id'), + 'import.meta.env.VITE_ORBITER_ID': JSON.stringify('orb-id'), + 'import.meta.env.VITE_INTERNET_IDENTITY_ID': JSON.stringify('ii-id'), + 'import.meta.env.VITE_ICP_LEDGER_ID': JSON.stringify('ledger-id'), + 'import.meta.env.VITE_ICP_INDEX_ID': JSON.stringify('index-id'), + 'import.meta.env.VITE_CONTAINER': JSON.stringify('http://localhost:1234') + } + }); + }); +}); From a44511ae0b810715f3b7fcea997a766b76010c3f Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 23 Mar 2025 14:31:39 +0100 Subject: [PATCH 3/7] chore: lint for test --- plugins/nextjs-plugin/src/index.spec.ts | 2 +- tsconfig.eslint.json | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tsconfig.eslint.json diff --git a/plugins/nextjs-plugin/src/index.spec.ts b/plugins/nextjs-plugin/src/index.spec.ts index 86a3997..43618f8 100644 --- a/plugins/nextjs-plugin/src/index.spec.ts +++ b/plugins/nextjs-plugin/src/index.spec.ts @@ -16,7 +16,7 @@ vi.mock('@junobuild/plugin-tools', async () => { describe('withJuno', () => { beforeEach(() => { vi.clearAllMocks(); - // @ts-expect-error + // @ts-expect-error we want to mock development env process.env.NODE_ENV = 'development'; }); diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 0000000..459a279 --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,3 @@ +{ + "extends": "./tsconfig.spec.json" +} From 59026ef79740717aa0e977ddb5db56bd943a77d6 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 23 Mar 2025 14:34:20 +0100 Subject: [PATCH 4/7] test: prefix TEST_ --- package.json | 3 ++- plugins/nextjs-plugin/src/index.spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3155089..90bc93e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "build": "npm run build --workspaces", "format": "prettier --write .", "format:check": "prettier --check .", - "lint": "eslint --max-warnings 0 ." + "lint": "eslint --max-warnings 0 .", + "test": "vitest" }, "author": "", "license": "MIT", diff --git a/plugins/nextjs-plugin/src/index.spec.ts b/plugins/nextjs-plugin/src/index.spec.ts index 43618f8..21496f4 100644 --- a/plugins/nextjs-plugin/src/index.spec.ts +++ b/plugins/nextjs-plugin/src/index.spec.ts @@ -60,9 +60,9 @@ describe('withJuno', () => { container: undefined }); - const result = await withJuno({prefix: 'CUSTOM_'}); + const result = await withJuno({prefix: 'TEST_'}); - expect(result.env?.CUSTOM_SATELLITE_ID).toBe('sat-id'); + expect(result.env?.TEST_SATELLITE_ID).toBe('sat-id'); expect(result.env?.NEXT_PUBLIC_SATELLITE_ID).toBeUndefined(); }); From b38737dd4af8704c16e5ddad2ace4eef554ea782 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 23 Mar 2025 14:36:11 +0100 Subject: [PATCH 5/7] chore: unused import --- plugins/nextjs-plugin/src/index.spec.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/plugins/nextjs-plugin/src/index.spec.ts b/plugins/nextjs-plugin/src/index.spec.ts index 21496f4..051d7bb 100644 --- a/plugins/nextjs-plugin/src/index.spec.ts +++ b/plugins/nextjs-plugin/src/index.spec.ts @@ -3,16 +3,6 @@ import {JunoPluginError} from '@junobuild/plugin-tools'; import {beforeEach, describe, expect, it, vi} from 'vitest'; import {withJuno} from './index'; -vi.mock('@junobuild/plugin-tools', async () => { - const actual = - await vi.importActual('@junobuild/plugin-tools'); - - return { - ...actual, - initConfig: vi.fn() - }; -}); - describe('withJuno', () => { beforeEach(() => { vi.clearAllMocks(); From 52dd8507d7f61689b1662589200c44dc51b0a8b2 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 23 Mar 2025 14:36:22 +0100 Subject: [PATCH 6/7] chore: unused import --- plugins/vite-plugin/src/index.spec.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/plugins/vite-plugin/src/index.spec.ts b/plugins/vite-plugin/src/index.spec.ts index cab9c2b..063112c 100644 --- a/plugins/vite-plugin/src/index.spec.ts +++ b/plugins/vite-plugin/src/index.spec.ts @@ -3,16 +3,6 @@ import type {UserConfig} from 'vite'; import {beforeEach, describe, expect, it, vi} from 'vitest'; import Juno from './index'; -vi.mock('@junobuild/plugin-tools', async () => { - const actual = - await vi.importActual('@junobuild/plugin-tools'); - - return { - ...actual, - initConfig: vi.fn() - }; -}); - describe('vite-plugin-juno', () => { beforeEach(() => { vi.clearAllMocks(); From 56755f7deefe9df73acebc51fc397ab942a2f942 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 23 Mar 2025 14:51:12 +0100 Subject: [PATCH 7/7] feat: build before test --- .github/workflows/checks.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index db46c5c..e539f57 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -45,6 +45,8 @@ jobs: uses: actions/checkout@v4 - name: Prepare uses: ./.github/actions/prepare + - name: Build + run: npm run build - name: Test run: npm run test