From 21919474d136d573a59095cd9065928ebf862f3e Mon Sep 17 00:00:00 2001 From: zirkelc Date: Sun, 21 Jul 2024 13:08:43 +0200 Subject: [PATCH] test: merge configs --- .github/workflows/ci.yml | 4 +- package.json | 13 ++--- packages/core/package.json | 14 +----- packages/core/vitest.configt.ts | 4 ++ packages/store-s3/package.json | 7 +-- .../{store-s3.test.ts => store.e2e.test.ts} | 0 .../store.unit.test.ts} | 2 +- .../utils.unit.test.ts} | 4 +- packages/store-s3/vitest.configt.ts | 4 ++ pnpm-lock.yaml | 50 +++++++++++++++++++ vitest.root.ts | 34 +++++++++++++ vitest.workspace.ts | 26 ++-------- 12 files changed, 108 insertions(+), 54 deletions(-) create mode 100644 packages/core/vitest.configt.ts rename packages/store-s3/tests/{store-s3.test.ts => store.e2e.test.ts} (100%) rename packages/store-s3/{src/store.test.ts => tests/store.unit.test.ts} (99%) rename packages/store-s3/{src/utils.test.ts => tests/utils.unit.test.ts} (98%) create mode 100644 packages/store-s3/vitest.configt.ts create mode 100644 vitest.root.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f046cd4..0143435 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,4 +58,6 @@ jobs: - name: Coverage if: ${{ steps.install.conclusion == 'success' }} - uses: davelosert/vitest-coverage-report-action@v2 \ No newline at end of file + uses: davelosert/vitest-coverage-report-action@v2 + with: + vite-config-path: vitest.root.ts \ No newline at end of file diff --git a/package.json b/package.json index 86a267e..422d703 100644 --- a/package.json +++ b/package.json @@ -21,15 +21,9 @@ "scripts": { "build": "turbo build", "test": "vitest run", - "test:ci": "vitest run --coverage.enabled --coverage.provider=v8 --coverage.reporter=json-summary --coverage.reporter=json --coverage.all", - "test:unit": "vitest run --project unit", - "test:e2e": "vitest run --project e2e", - "test:unit:cov": "vitest run --project unit --coverage.enabled --coverage.reporter=v8 --coverage.all", - "test:e2e:cov": "vitest run --project e2e --coverage.enabled --coverage.reporter=v8 --coverage.all", + "test:ci": "vitest --coverage.enabled", "lint": "biome check . --write --no-errors-on-unmatched", - "prepare": "husky", - "release:patch": "pnpm -r release:patch", - "release:alpha": "pnpm -r release:alpha" + "prepare": "husky" }, "keywords": [], "author": "", @@ -54,7 +48,8 @@ "tsx": "^4.16.2", "turbo": "^2.0.9", "typescript": "^5.5.3", - "vitest": "^2.0.3" + "vitest": "^2.0.3", + "vitest-github-actions-reporter": "^0.11.1" }, "lint-staged": { "*.{ts,json}": ["biome check --write --no-errors-on-unmatched"] diff --git a/packages/core/package.json b/packages/core/package.json index ba80efa..5d18406 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -8,10 +8,6 @@ "module": "./src/index.ts", "exports": { ".": { - "require": { - "types": "./src/index.ts", - "default": "./src/index.ts" - }, "import": { "types": "./src/index.ts", "default": "./src/index.ts" @@ -24,10 +20,6 @@ "module": "./dist/index.cjs", "exports": { ".": { - "require": { - "types": "./dist/index.d.cts", - "default": "./dist/index.cjs" - }, "import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" @@ -37,11 +29,7 @@ }, "scripts": { "test": "vitest", - "build": "tsc --noEmit", - "bundle": "tsup ./src/index.ts --format cjs,esm --dts --clean", - "prepublishOnly": "pnpm run build && pnpm run bundle", - "release:patch": "pnpm version patch && pnpm publish --no-git-checks", - "release:alpha": "pnpm version prerelease --preid alpha && pnpm publish --tag alpha --no-git-checks" + "build": "tsup ./src/index.ts --format esm --dts --clean" }, "keywords": [], "author": "", diff --git a/packages/core/vitest.configt.ts b/packages/core/vitest.configt.ts new file mode 100644 index 0000000..5c94ff1 --- /dev/null +++ b/packages/core/vitest.configt.ts @@ -0,0 +1,4 @@ +import { defineProject, mergeConfig } from "vitest/config"; +import configShared from "../../vitest.root.js"; + +export default mergeConfig(configShared, defineProject({})); diff --git a/packages/store-s3/package.json b/packages/store-s3/package.json index a547006..7bdb18a 100644 --- a/packages/store-s3/package.json +++ b/packages/store-s3/package.json @@ -28,12 +28,7 @@ }, "scripts": { "build": "tsup src/index.ts --format esm --dts --clean", - "test": "vitest --root ../..", - "test:unit": "vitest --project unit --root ../..", - "test:e2e": "vitest --project e2e --root ../..", - "prepublishOnly": "pnpm run build && pnpm run bundle", - "release:patch": "pnpm version patch && pnpm publish --no-git-checks", - "release:alpha": "pnpm version prerelease --preid alpha && pnpm publish --tag alpha --no-git-checks" + "test": "vitest" }, "keywords": [], "author": "", diff --git a/packages/store-s3/tests/store-s3.test.ts b/packages/store-s3/tests/store.e2e.test.ts similarity index 100% rename from packages/store-s3/tests/store-s3.test.ts rename to packages/store-s3/tests/store.e2e.test.ts diff --git a/packages/store-s3/src/store.test.ts b/packages/store-s3/tests/store.unit.test.ts similarity index 99% rename from packages/store-s3/src/store.test.ts rename to packages/store-s3/tests/store.unit.test.ts index ecc0b41..95944ec 100644 --- a/packages/store-s3/src/store.test.ts +++ b/packages/store-s3/tests/store.unit.test.ts @@ -13,7 +13,7 @@ import { type S3Reference, type S3ReferenceFormat, S3Store, -} from "./store.js"; +} from "../src/store.js"; const bucket = "bucket"; const key = "key"; diff --git a/packages/store-s3/src/utils.test.ts b/packages/store-s3/tests/utils.unit.test.ts similarity index 98% rename from packages/store-s3/src/utils.test.ts rename to packages/store-s3/tests/utils.unit.test.ts index 474b4b6..8962b9a 100644 --- a/packages/store-s3/src/utils.test.ts +++ b/packages/store-s3/tests/utils.unit.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "vitest"; -import { STORE_NAME } from "./store.js"; +import { STORE_NAME } from "../src/store.js"; import { formatS3ObjectArn, formatS3Reference, @@ -10,7 +10,7 @@ import { parseS3ObjectArn, parseS3Reference, uuidKey, -} from "./utils.js"; +} from "../src/utils.js"; const nonStringValues = [null, undefined, "", 42, true, false, {}]; diff --git a/packages/store-s3/vitest.configt.ts b/packages/store-s3/vitest.configt.ts new file mode 100644 index 0000000..5c94ff1 --- /dev/null +++ b/packages/store-s3/vitest.configt.ts @@ -0,0 +1,4 @@ +import { defineProject, mergeConfig } from "vitest/config"; +import configShared from "../../vitest.root.js"; + +export default mergeConfig(configShared, defineProject({})); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c4d065b..4322e60 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -63,6 +63,9 @@ importers: vitest: specifier: ^2.0.3 version: 2.0.3(@types/node@20.14.11)(@vitest/ui@2.0.3) + vitest-github-actions-reporter: + specifier: ^0.11.1 + version: 0.11.1(vitest@2.0.3(@types/node@20.14.11)(@vitest/ui@2.0.3)) examples/base64: dependencies: @@ -206,6 +209,12 @@ packages: 2-thenable@1.0.0: resolution: {integrity: sha512-HqiDzaLDFCXkcCO/SwoyhRwqYtINFHF7t9BDRq4x90TOKNAJpiqUt9X5lQ08bwxYzc067HUywDjGySpebHcUpw==} + '@actions/core@1.10.1': + resolution: {integrity: sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==} + + '@actions/http-client@2.2.1': + resolution: {integrity: sha512-KhC/cZsq7f8I4LfZSJKgCvEwfkE8o1538VoBeoGzokVLLnbFDEAdFD3UhoMklxo2un9NJVBdANOresx7vTHlHw==} + '@ampproject/remapping@2.3.0': resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} engines: {node: '>=6.0.0'} @@ -906,6 +915,10 @@ packages: cpu: [x64] os: [win32] + '@fastify/busboy@2.1.1': + resolution: {integrity: sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==} + engines: {node: '>=14'} + '@hapi/hoek@9.3.0': resolution: {integrity: sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==} @@ -3502,6 +3515,10 @@ packages: engines: {node: '>=18.0.0'} hasBin: true + tunnel@0.0.6: + resolution: {integrity: sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==} + engines: {node: '>=0.6.11 <=0.7.0 || >=0.7.3'} + turbo-darwin-64@2.0.9: resolution: {integrity: sha512-owlGsOaExuVGBUfrnJwjkL1BWlvefjSKczEAcpLx4BI7Oh6ttakOi+JyomkPkFlYElRpjbvlR2gP8WIn6M/+xQ==} cpu: [x64] @@ -3577,6 +3594,10 @@ packages: undici-types@5.26.5: resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + undici@5.28.4: + resolution: {integrity: sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==} + engines: {node: '>=14.0'} + uni-global@1.0.0: resolution: {integrity: sha512-WWM3HP+siTxzIWPNUg7hZ4XO8clKi6NoCAJJWnuRL+BAqyFXF8gC03WNyTefGoUXYc47uYgXxpKLIEvo65PEHw==} @@ -3651,6 +3672,12 @@ packages: terser: optional: true + vitest-github-actions-reporter@0.11.1: + resolution: {integrity: sha512-ZHHB0wBgOPhMYCB17WKVlJZa+5SdudBZFoVoebwfq3ioIUTeLQGYHwh85vpdJAxRghLP8d0qI/6eCTueGyDVXA==} + engines: {node: '>=14.16.0'} + peerDependencies: + vitest: '>=0.28.5' + vitest@2.0.3: resolution: {integrity: sha512-o3HRvU93q6qZK4rI2JrhKyZMMuxg/JRt30E6qeQs6ueaiz5hr1cPj+Sk2kATgQzMMqsa2DiNI0TIK++1ULx8Jw==} engines: {node: ^18.0.0 || >=20.0.0} @@ -3804,6 +3831,16 @@ snapshots: d: 1.0.2 es5-ext: 0.10.64 + '@actions/core@1.10.1': + dependencies: + '@actions/http-client': 2.2.1 + uuid: 8.3.2 + + '@actions/http-client@2.2.1': + dependencies: + tunnel: 0.0.6 + undici: 5.28.4 + '@ampproject/remapping@2.3.0': dependencies: '@jridgewell/gen-mapping': 0.3.5 @@ -4865,6 +4902,8 @@ snapshots: '@esbuild/win32-x64@0.23.0': optional: true + '@fastify/busboy@2.1.1': {} + '@hapi/hoek@9.3.0': {} '@hapi/topo@5.1.0': @@ -8005,6 +8044,8 @@ snapshots: optionalDependencies: fsevents: 2.3.3 + tunnel@0.0.6: {} + turbo-darwin-64@2.0.9: optional: true @@ -8093,6 +8134,10 @@ snapshots: undici-types@5.26.5: {} + undici@5.28.4: + dependencies: + '@fastify/busboy': 2.1.1 + uni-global@1.0.0: dependencies: type: 2.7.3 @@ -8158,6 +8203,11 @@ snapshots: '@types/node': 20.14.11 fsevents: 2.3.3 + vitest-github-actions-reporter@0.11.1(vitest@2.0.3(@types/node@20.14.11)(@vitest/ui@2.0.3)): + dependencies: + '@actions/core': 1.10.1 + vitest: 2.0.3(@types/node@20.14.11)(@vitest/ui@2.0.3) + vitest@2.0.3(@types/node@20.14.11)(@vitest/ui@2.0.3): dependencies: '@ampproject/remapping': 2.3.0 diff --git a/vitest.root.ts b/vitest.root.ts new file mode 100644 index 0000000..3c08d29 --- /dev/null +++ b/vitest.root.ts @@ -0,0 +1,34 @@ +import GithubActionsReporter from "vitest-github-actions-reporter"; +import { defineConfig } from "vitest/config"; + +// load region from config to prevent error "ConfigError: Missing region in config" +// https://github.com/aws/aws-sdk-js/pull/1391 +process.env.AWS_SDK_LOAD_CONFIG = "1"; + +export default defineConfig({ + test: { + // https://github.com/sapphi-red/vitest-github-actions-reporter + reporters: process.env.GITHUB_ACTIONS + ? ["default", new GithubActionsReporter()] + : "default", + + // https://vitest.dev/config/#typecheck + typecheck: { + enabled: true, + ignoreSourceErrors: false, + }, + + // https://vitest.dev/guide/coverage.html + coverage: { + provider: "v8", + // json-summary is required for https://github.com/davelosert/vitest-coverage-report-action + reporter: ["json-summary", "json", "text-summary"], + thresholds: { + lines: 80, + statements: 80, + functions: 80, + branches: 80, + }, + }, + }, +}); diff --git a/vitest.workspace.ts b/vitest.workspace.ts index 3bc91b1..0350edf 100644 --- a/vitest.workspace.ts +++ b/vitest.workspace.ts @@ -1,22 +1,4 @@ -import { configDefaults, defineWorkspace } from "vitest/config"; - -export default defineWorkspace([ - { - test: { - name: "unit", - include: ["**/*.{test,spec}.?(c|m)[jt]s?(x)"], - exclude: [...configDefaults.exclude, "**/tests/**"], - - // https://vitest.dev/config/#typecheck - typecheck: { - enabled: true, - }, - }, - }, - { - test: { - name: "e2e", - include: ["**/tests/*.{test,spec}.?(c|m)[jt]s?(x)"], - }, - }, -]); +/** + * @see https://vitest.dev/guide/workspace.html + */ +export default ["packages/*"];