From 86a28d074b4a5590aa87638d2c3cf6439037abd2 Mon Sep 17 00:00:00 2001 From: Tommy Chen Date: Sun, 11 Feb 2024 12:19:16 +0800 Subject: [PATCH] test(cli): Use vitest in integration tests --- .../jest-preset/integration/jest-preset.cjs | 17 -- internal/jest-preset/integration/setup.cjs | 3 - jest.integration.config.ts | 8 - package.json | 4 +- .../__tests__/__snapshots__/index.ts.snap | 20 +- .../generate-cjs/__tests__/index.ts | 1 + .../__tests__/__snapshots__/index.ts.snap | 8 +- .../generate-loader-error/__tests__/index.ts | 1 + .../__tests__/__snapshots__/index.ts.snap | 2 +- .../generate-mixed/__tests__/index.ts | 1 + .../__tests__/__snapshots__/index.ts.snap | 2 +- .../generate-mjs/__tests__/index.ts | 1 + .../__tests__/__snapshots__/index.ts.snap | 24 +-- .../generate-multi-errors/__tests__/index.ts | 1 + .../__tests__/__snapshots__/index.ts.snap | 2 +- .../generate-package-type/__tests__/index.ts | 1 + .../__tests__/__snapshots__/index.ts.snap | 2 +- .../generate-ts-cjs/__tests__/index.ts | 1 + .../__tests__/__snapshots__/index.ts.snap | 2 +- .../generate-ts-mjs/__tests__/index.ts | 1 + .../__tests__/__snapshots__/index.ts.snap | 20 +- .../generate-validate/__tests__/index.ts | 1 + packages/cli/integration/jest.config.js | 3 - .../__tests__/__snapshots__/index.ts.snap | 10 +- .../integration/migrate/__tests__/index.ts | 1 + packages/cli/integration/utils/run.ts | 2 + .../__tests__/__snapshots__/index.ts.snap | 8 +- .../validate-failed/__tests__/index.ts | 1 + .../validate-passed/__tests__/index.ts | 1 + packages/cli/package.json | 4 +- .../__tests__/__snapshots__/error.ts.snap | 193 ------------------ .../__snapshots__/set-option.ts.snap | 7 - packages/cli/vitest.config.integration.ts | 1 + pnpm-lock.yaml | 6 + 34 files changed, 75 insertions(+), 285 deletions(-) delete mode 100644 internal/jest-preset/integration/jest-preset.cjs delete mode 100644 internal/jest-preset/integration/setup.cjs delete mode 100644 jest.integration.config.ts delete mode 100644 packages/cli/integration/jest.config.js delete mode 100644 packages/cli/src/commands/generate/__tests__/__snapshots__/error.ts.snap delete mode 100644 packages/cli/src/commands/generate/__tests__/__snapshots__/set-option.ts.snap create mode 100644 packages/cli/vitest.config.integration.ts diff --git a/internal/jest-preset/integration/jest-preset.cjs b/internal/jest-preset/integration/jest-preset.cjs deleted file mode 100644 index c1995bf1d..000000000 --- a/internal/jest-preset/integration/jest-preset.cjs +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; - -const { join } = require("node:path"); -const preset = require("../jest-preset.cjs"); - -/** @type import("jest").Config */ -module.exports = { - ...preset, - roots: [""], - // `testTimeout` is not working in projects currently. - // https://github.com/facebook/jest/issues/9696 - // testTimeout: 60000, - setupFilesAfterEnv: [ - ...(preset.setupFilesAfterEnv || []), - join(__dirname, "setup.cjs") - ] -}; diff --git a/internal/jest-preset/integration/setup.cjs b/internal/jest-preset/integration/setup.cjs deleted file mode 100644 index 4b0e210a7..000000000 --- a/internal/jest-preset/integration/setup.cjs +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; - -jest.setTimeout(60000); diff --git a/jest.integration.config.ts b/jest.integration.config.ts deleted file mode 100644 index 46904f12a..000000000 --- a/jest.integration.config.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* eslint-disable node/no-unpublished-import */ -import type { Config } from "jest"; - -const config: Config = { - projects: ["/packages/*/integration/jest.config.js"] -}; - -export default config; diff --git a/package.json b/package.json index 36f0475b1..c2e0edf1c 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,7 @@ "watch": "npm run build -- --watch", "test": "npm-run-all test:*", "test:unit": "cross-env BUILD_TARGET=node ESM_IMPORT_DISABLED=1 jest", - "test:integration": "npm-run-all test:integration:*", - "test:integration:jest": "jest --config jest.integration.config.ts", - "test:integration:vitest": "vitest --workspace vitest.workspace.integration.ts", + "test:integration": "vitest --workspace vitest.workspace.integration.ts", "test:browser": "jest --config integration/browser/jest.config.js", "preinstall": "npx only-allow pnpm", "prepare": "husky install", diff --git a/packages/cli/integration/generate-cjs/__tests__/__snapshots__/index.ts.snap b/packages/cli/integration/generate-cjs/__tests__/__snapshots__/index.ts.snap index 472e7cc87..0159fdb3c 100644 --- a/packages/cli/integration/generate-cjs/__tests__/__snapshots__/index.ts.snap +++ b/packages/cli/integration/generate-cjs/__tests__/__snapshots__/index.ts.snap @@ -1,12 +1,12 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`when key in the set argument is invalid should print the error 1`] = ` -"error - Invalid JSONPath expression "tolerations[?@.key=='key2'].value": Lexical error on line 1. Unrecognized text. +exports[`when key in the set argument is invalid > should print the error 1`] = ` +"error - Invalid JSONPath expression "tolerations[?@.key=='key2'].value": Lexical error on line 1. Unrecognized text. tolerations[?@.key=='key2'].valu ------------^" `; -exports[`when multiple set arguments are provided should output YAML 1`] = ` +exports[`when multiple set arguments are provided > should output YAML 1`] = ` "--- apiVersion: apps/v1 kind: Deployment @@ -52,7 +52,7 @@ spec: - port: 80" `; -exports[`when nested value in the set argument is invalid should print the error 1`] = ` +exports[`when nested value in the set argument is invalid > should print the error 1`] = ` "kosko generate [components..] Generate Kubernetes manifests @@ -92,7 +92,7 @@ Examples: The specified value "3" is not a string." `; -exports[`when output = json should output JSON 1`] = ` +exports[`when output = json > should output JSON 1`] = ` "{ "apiVersion": "v1", "kind": "List", @@ -171,7 +171,7 @@ exports[`when output = json should output JSON 1`] = ` }" `; -exports[`when output = yaml should output YAML 1`] = ` +exports[`when output = yaml > should output YAML 1`] = ` "--- apiVersion: apps/v1 kind: Deployment @@ -217,7 +217,7 @@ spec: - port: 80" `; -exports[`when output is invalid should print the error 1`] = ` +exports[`when output is invalid > should print the error 1`] = ` "kosko generate [components..] Generate Kubernetes manifests @@ -258,7 +258,7 @@ Invalid values: Argument: output, Given: "foo", Choices: "yaml", "json"" `; -exports[`when output is not set should output YAML 1`] = ` +exports[`when output is not set > should output YAML 1`] = ` "--- apiVersion: apps/v1 kind: Deployment @@ -304,7 +304,7 @@ spec: - port: 80" `; -exports[`when value in the set argument is invalid should print the error 1`] = ` +exports[`when value in the set argument is invalid > should print the error 1`] = ` "kosko generate [components..] Generate Kubernetes manifests diff --git a/packages/cli/integration/generate-cjs/__tests__/index.ts b/packages/cli/integration/generate-cjs/__tests__/index.ts index 19719fcf1..1e04a02f2 100644 --- a/packages/cli/integration/generate-cjs/__tests__/index.ts +++ b/packages/cli/integration/generate-cjs/__tests__/index.ts @@ -1,6 +1,7 @@ import execa from "execa"; import { dirname } from "node:path"; import { runNodeCLI } from "../../utils/run"; +import { describe, beforeAll, beforeEach, test, expect } from "vitest"; const testDir = dirname(__dirname); diff --git a/packages/cli/integration/generate-loader-error/__tests__/__snapshots__/index.ts.snap b/packages/cli/integration/generate-loader-error/__tests__/__snapshots__/index.ts.snap index 52540cae5..9072890bf 100644 --- a/packages/cli/integration/generate-loader-error/__tests__/__snapshots__/index.ts.snap +++ b/packages/cli/integration/generate-loader-error/__tests__/__snapshots__/index.ts.snap @@ -1,13 +1,13 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`should print the error 1`] = ` -"components/nginx.ts - 1 error +"components/nginx.ts - 1 error - ✖ ResolveError: Validation error + ✖ ResolveError: Validation error Kind: v1/Pod Name: test-pod /spec must have required property 'containers' -error - Generate failed (Total 1 error)" +error - Generate failed (Total 1 error)" `; diff --git a/packages/cli/integration/generate-loader-error/__tests__/index.ts b/packages/cli/integration/generate-loader-error/__tests__/index.ts index 03c263ab8..403f017f6 100644 --- a/packages/cli/integration/generate-loader-error/__tests__/index.ts +++ b/packages/cli/integration/generate-loader-error/__tests__/index.ts @@ -1,6 +1,7 @@ import execa from "execa"; import { dirname } from "node:path"; import { runNodeCLI } from "../../utils/run"; +import { beforeEach, test, expect } from "vitest"; const testDir = dirname(__dirname); diff --git a/packages/cli/integration/generate-mixed/__tests__/__snapshots__/index.ts.snap b/packages/cli/integration/generate-mixed/__tests__/__snapshots__/index.ts.snap index 239bc1acc..184731839 100644 --- a/packages/cli/integration/generate-mixed/__tests__/__snapshots__/index.ts.snap +++ b/packages/cli/integration/generate-mixed/__tests__/__snapshots__/index.ts.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`should import CJS environment 1`] = ` "--- diff --git a/packages/cli/integration/generate-mixed/__tests__/index.ts b/packages/cli/integration/generate-mixed/__tests__/index.ts index a62554b7a..1bb1d5aa4 100644 --- a/packages/cli/integration/generate-mixed/__tests__/index.ts +++ b/packages/cli/integration/generate-mixed/__tests__/index.ts @@ -1,6 +1,7 @@ import execa from "execa"; import { dirname } from "node:path"; import { runNodeCLI } from "../../utils/run"; +import { beforeEach, test, expect } from "vitest"; const testDir = dirname(__dirname); let result: execa.ExecaReturnValue; diff --git a/packages/cli/integration/generate-mjs/__tests__/__snapshots__/index.ts.snap b/packages/cli/integration/generate-mjs/__tests__/__snapshots__/index.ts.snap index bba64fd15..d8d2e0d28 100644 --- a/packages/cli/integration/generate-mjs/__tests__/__snapshots__/index.ts.snap +++ b/packages/cli/integration/generate-mjs/__tests__/__snapshots__/index.ts.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`should import ESM files 1`] = ` "--- diff --git a/packages/cli/integration/generate-mjs/__tests__/index.ts b/packages/cli/integration/generate-mjs/__tests__/index.ts index 8ddac98bf..8d5d92799 100644 --- a/packages/cli/integration/generate-mjs/__tests__/index.ts +++ b/packages/cli/integration/generate-mjs/__tests__/index.ts @@ -1,6 +1,7 @@ import execa from "execa"; import { dirname } from "node:path"; import { runNodeCLI } from "../../utils/run"; +import { beforeEach, test, expect } from "vitest"; const testDir = dirname(__dirname); let result: execa.ExecaReturnValue; diff --git a/packages/cli/integration/generate-multi-errors/__tests__/__snapshots__/index.ts.snap b/packages/cli/integration/generate-multi-errors/__tests__/__snapshots__/index.ts.snap index 51e9928e2..39d1c511b 100644 --- a/packages/cli/integration/generate-multi-errors/__tests__/__snapshots__/index.ts.snap +++ b/packages/cli/integration/generate-multi-errors/__tests__/__snapshots__/index.ts.snap @@ -1,18 +1,18 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`when bail is not set should print the error 1`] = ` -"components/foo.js - 1 error +exports[`when bail is not set > should print the error 1`] = ` +"components/foo.js - 1 error - ✖ ResolveError: Validation error + ✖ ResolveError: Validation error Index: [0] Kind: v1/Pod Name: foo /spec must have required property 'containers' -components/nginx.js - 2 errors +components/nginx.js - 2 errors - ✖ ResolveError: Validation error + ✖ ResolveError: Validation error Index: [0] Kind: apps/v1/Deployment Name: nginx @@ -20,7 +20,7 @@ exports[`when bail is not set should print the error 1`] = ` /spec must have required property 'selector' /spec must have required property 'template' - ✖ ResolveError: Validation error + ✖ ResolveError: Validation error Index: [1] Kind: v1/Service Name: nginx @@ -28,18 +28,18 @@ exports[`when bail is not set should print the error 1`] = ` /spec/ports/0/port must be integer /spec/type must be equal to one of the allowed values: ["ClusterIP","ExternalName","LoadBalancer","NodePort"] -error - Generate failed (Total 3 errors)" +error - Generate failed (Total 3 errors)" `; -exports[`when bail is true should print the error 1`] = ` -"components/foo.js - 1 error +exports[`when bail is true > should print the error 1`] = ` +"components/foo.js - 1 error - ✖ ResolveError: Validation error + ✖ ResolveError: Validation error Index: [0] Kind: v1/Pod Name: foo /spec must have required property 'containers' -error - Generate failed (Only the first error is displayed because \`bail\` option is enabled)" +error - Generate failed (Only the first error is displayed because \`bail\` option is enabled)" `; diff --git a/packages/cli/integration/generate-multi-errors/__tests__/index.ts b/packages/cli/integration/generate-multi-errors/__tests__/index.ts index 77f9ed687..c777f32cf 100644 --- a/packages/cli/integration/generate-multi-errors/__tests__/index.ts +++ b/packages/cli/integration/generate-multi-errors/__tests__/index.ts @@ -1,6 +1,7 @@ import execa from "execa"; import { dirname } from "node:path"; import { runNodeCLI } from "../../utils/run"; +import { beforeEach, beforeAll, describe, test, expect } from "vitest"; const testDir = dirname(__dirname); diff --git a/packages/cli/integration/generate-package-type/__tests__/__snapshots__/index.ts.snap b/packages/cli/integration/generate-package-type/__tests__/__snapshots__/index.ts.snap index bba64fd15..d8d2e0d28 100644 --- a/packages/cli/integration/generate-package-type/__tests__/__snapshots__/index.ts.snap +++ b/packages/cli/integration/generate-package-type/__tests__/__snapshots__/index.ts.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`should import ESM files 1`] = ` "--- diff --git a/packages/cli/integration/generate-package-type/__tests__/index.ts b/packages/cli/integration/generate-package-type/__tests__/index.ts index 8ddac98bf..8d5d92799 100644 --- a/packages/cli/integration/generate-package-type/__tests__/index.ts +++ b/packages/cli/integration/generate-package-type/__tests__/index.ts @@ -1,6 +1,7 @@ import execa from "execa"; import { dirname } from "node:path"; import { runNodeCLI } from "../../utils/run"; +import { beforeEach, test, expect } from "vitest"; const testDir = dirname(__dirname); let result: execa.ExecaReturnValue; diff --git a/packages/cli/integration/generate-ts-cjs/__tests__/__snapshots__/index.ts.snap b/packages/cli/integration/generate-ts-cjs/__tests__/__snapshots__/index.ts.snap index 0f37a30df..63f69cbc1 100644 --- a/packages/cli/integration/generate-ts-cjs/__tests__/__snapshots__/index.ts.snap +++ b/packages/cli/integration/generate-ts-cjs/__tests__/__snapshots__/index.ts.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`should import ts files 1`] = ` "--- diff --git a/packages/cli/integration/generate-ts-cjs/__tests__/index.ts b/packages/cli/integration/generate-ts-cjs/__tests__/index.ts index 4d399d063..588f1f099 100644 --- a/packages/cli/integration/generate-ts-cjs/__tests__/index.ts +++ b/packages/cli/integration/generate-ts-cjs/__tests__/index.ts @@ -1,6 +1,7 @@ import execa from "execa"; import { dirname } from "node:path"; import { runNodeCLI } from "../../utils/run"; +import { beforeEach, test, expect } from "vitest"; const testDir = dirname(__dirname); let result: execa.ExecaReturnValue; diff --git a/packages/cli/integration/generate-ts-mjs/__tests__/__snapshots__/index.ts.snap b/packages/cli/integration/generate-ts-mjs/__tests__/__snapshots__/index.ts.snap index 8a7e6cc6b..480e6cead 100644 --- a/packages/cli/integration/generate-ts-mjs/__tests__/__snapshots__/index.ts.snap +++ b/packages/cli/integration/generate-ts-mjs/__tests__/__snapshots__/index.ts.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`should load loaders specified in args 1`] = ` "apiVersion: v1 diff --git a/packages/cli/integration/generate-ts-mjs/__tests__/index.ts b/packages/cli/integration/generate-ts-mjs/__tests__/index.ts index a18fd4c1b..7231e62fa 100644 --- a/packages/cli/integration/generate-ts-mjs/__tests__/index.ts +++ b/packages/cli/integration/generate-ts-mjs/__tests__/index.ts @@ -1,5 +1,6 @@ import { dirname } from "node:path"; import { runNodeCLI } from "../../utils/run"; +import { test, expect } from "vitest"; const testDir = dirname(__dirname); diff --git a/packages/cli/integration/generate-validate/__tests__/__snapshots__/index.ts.snap b/packages/cli/integration/generate-validate/__tests__/__snapshots__/index.ts.snap index a491806f7..b57be6692 100644 --- a/packages/cli/integration/generate-validate/__tests__/__snapshots__/index.ts.snap +++ b/packages/cli/integration/generate-validate/__tests__/__snapshots__/index.ts.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`when validate is false should print the manifest 1`] = ` +exports[`when validate is false > should print the manifest 1`] = ` "apiVersion: v1 kind: Pod metadata: @@ -8,26 +8,26 @@ metadata: spec: {}" `; -exports[`when validate is not set should print the error 1`] = ` -"components/foo.js - 1 error +exports[`when validate is not set > should print the error 1`] = ` +"components/foo.js - 1 error - ✖ ResolveError: Validation error + ✖ ResolveError: Validation error Kind: v1/Pod Name: foo /spec must have required property 'containers' -error - Generate failed (Total 1 error)" +error - Generate failed (Total 1 error)" `; -exports[`when validate is true should print the error 1`] = ` -"components/foo.js - 1 error +exports[`when validate is true > should print the error 1`] = ` +"components/foo.js - 1 error - ✖ ResolveError: Validation error + ✖ ResolveError: Validation error Kind: v1/Pod Name: foo /spec must have required property 'containers' -error - Generate failed (Total 1 error)" +error - Generate failed (Total 1 error)" `; diff --git a/packages/cli/integration/generate-validate/__tests__/index.ts b/packages/cli/integration/generate-validate/__tests__/index.ts index f1e75ecf2..085b24604 100644 --- a/packages/cli/integration/generate-validate/__tests__/index.ts +++ b/packages/cli/integration/generate-validate/__tests__/index.ts @@ -2,6 +2,7 @@ import execa from "execa"; import { dirname } from "node:path"; import { runNodeCLI } from "../../utils/run"; +import { beforeEach, beforeAll, describe, test, expect } from "vitest"; const testDir = dirname(__dirname); diff --git a/packages/cli/integration/jest.config.js b/packages/cli/integration/jest.config.js deleted file mode 100644 index b69622d47..000000000 --- a/packages/cli/integration/jest.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - preset: "@kosko/jest-preset/integration" -}; diff --git a/packages/cli/integration/migrate/__tests__/__snapshots__/index.ts.snap b/packages/cli/integration/migrate/__tests__/__snapshots__/index.ts.snap index 838a28e6b..52195eeee 100644 --- a/packages/cli/integration/migrate/__tests__/__snapshots__/index.ts.snap +++ b/packages/cli/integration/migrate/__tests__/__snapshots__/index.ts.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`when filename is not given should print the error 1`] = ` +exports[`when filename is not given > should print the error 1`] = ` "kosko migrate Migrate YAML into components @@ -23,7 +23,7 @@ Examples: Missing required argument: filename" `; -exports[`when path is - should print the output 1`] = ` +exports[`when path is - > should print the output 1`] = ` ""use strict"; const { Deployment } = require("kubernetes-models/apps/v1/Deployment"); @@ -78,7 +78,7 @@ const deployment = new Deployment({ module.exports = [deployment];" `; -exports[`when path is a directory should print the output 1`] = ` +exports[`when path is a directory > should print the output 1`] = ` ""use strict"; const { Deployment } = require("kubernetes-models/apps/v1/Deployment"); @@ -205,7 +205,7 @@ const deployment1 = new Deployment({ module.exports = [deployment, service, deployment1];" `; -exports[`when path is a file should print the output 1`] = ` +exports[`when path is a file > should print the output 1`] = ` ""use strict"; const { Deployment } = require("kubernetes-models/apps/v1/Deployment"); diff --git a/packages/cli/integration/migrate/__tests__/index.ts b/packages/cli/integration/migrate/__tests__/index.ts index 2b0a40a40..21c67970d 100644 --- a/packages/cli/integration/migrate/__tests__/index.ts +++ b/packages/cli/integration/migrate/__tests__/index.ts @@ -2,6 +2,7 @@ import execa from "execa"; import { join } from "node:path"; import { readFile } from "node:fs/promises"; import { runNodeCLI } from "../../utils/run"; +import { beforeEach, beforeAll, describe, test, expect } from "vitest"; const fixtureDir = join(__dirname, "..", "__fixtures__"); diff --git a/packages/cli/integration/utils/run.ts b/packages/cli/integration/utils/run.ts index 9f3e79538..a66a7ee5b 100644 --- a/packages/cli/integration/utils/run.ts +++ b/packages/cli/integration/utils/run.ts @@ -12,6 +12,8 @@ export async function runNodeCLI( ...options, env: { LC_ALL: "en_US", + // Disable colors to make snapshot testing easier + NO_COLOR: "1", ...options.env } }); diff --git a/packages/cli/integration/validate-failed/__tests__/__snapshots__/index.ts.snap b/packages/cli/integration/validate-failed/__tests__/__snapshots__/index.ts.snap index 2515b9661..57ebd7450 100644 --- a/packages/cli/integration/validate-failed/__tests__/__snapshots__/index.ts.snap +++ b/packages/cli/integration/validate-failed/__tests__/__snapshots__/index.ts.snap @@ -1,13 +1,13 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`should print the error 1`] = ` -"components/foo.js - 1 error +"components/foo.js - 1 error - ✖ ResolveError: Validation error + ✖ ResolveError: Validation error Kind: v1/Pod Name: foo /spec must have required property 'containers' -error - Generate failed (Total 1 error)" +error - Generate failed (Total 1 error)" `; diff --git a/packages/cli/integration/validate-failed/__tests__/index.ts b/packages/cli/integration/validate-failed/__tests__/index.ts index ba1728dc3..32b4ce3a0 100644 --- a/packages/cli/integration/validate-failed/__tests__/index.ts +++ b/packages/cli/integration/validate-failed/__tests__/index.ts @@ -2,6 +2,7 @@ import execa from "execa"; import { dirname } from "node:path"; import { runNodeCLI } from "../../utils/run"; +import { beforeEach, test, expect } from "vitest"; const testDir = dirname(__dirname); diff --git a/packages/cli/integration/validate-passed/__tests__/index.ts b/packages/cli/integration/validate-passed/__tests__/index.ts index 9e9df1f49..741eede2a 100644 --- a/packages/cli/integration/validate-passed/__tests__/index.ts +++ b/packages/cli/integration/validate-passed/__tests__/index.ts @@ -1,6 +1,7 @@ import execa from "execa"; import { dirname } from "node:path"; import { runNodeCLI } from "../../utils/run"; +import { beforeEach, test, expect } from "vitest"; const testDir = dirname(__dirname); diff --git a/packages/cli/package.json b/packages/cli/package.json index e883635f8..488d6ff1a 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -77,6 +77,7 @@ "@kosko/jest-preset": "workspace:^", "@kosko/plugin": "workspace:^", "@kosko/test-utils": "workspace:^", + "@kosko/vitest-config": "workspace:^", "@types/bl": "^5.0.2", "@types/exit": "^0.1.31", "@types/jsonpath": "^0.2.0", @@ -86,7 +87,8 @@ "fast-glob": "^3.2.12", "kubernetes-models": "^4.1.0", "pkg-dir": "^5.0.0", - "replace-string": "^3.1.0" + "replace-string": "^3.1.0", + "vitest": "^1.2.2" }, "jest": { "preset": "@kosko/jest-preset" diff --git a/packages/cli/src/commands/generate/__tests__/__snapshots__/error.ts.snap b/packages/cli/src/commands/generate/__tests__/__snapshots__/error.ts.snap deleted file mode 100644 index 49e31bf1a..000000000 --- a/packages/cli/src/commands/generate/__tests__/__snapshots__/error.ts.snap +++ /dev/null @@ -1,193 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`when error is a AggregateError should group errors by their path 1`] = ` -"a/b.js - 2 errors - - ✖ ResolveError: first resolve err - - ✖ GenerateError: first generate err - -c/d.js - 2 errors - - ✖ ResolveError: second resolve err - - ✖ ResolveError: second generate err - -Other 2 errors - - ✖ Error: first other err - - at new Promise () - - ✖ Error: second other err - - at new Promise () - -" -`; - -exports[`when error is a GenerateError with cause should print index 1`] = ` -"a.js - 1 error - - ✖ GenerateError: test err - Error: test err cause - at new Promise () - -" -`; - -exports[`when error is a GenerateError with path not in cwd should print the full path 1`] = ` -"/bar/a.js - 1 error - - ✖ GenerateError: test err - -" -`; - -exports[`when error is a GenerateError with path should treat as a normal error 1`] = ` -"a.js - 1 error - - ✖ GenerateError: test err - -" -`; - -exports[`when error is a GenerateError without path should treat as a normal error 1`] = ` -"Other 1 error - - ✖ GenerateError: test err - - at new Promise () - -" -`; - -exports[`when error is a ResolveError with ValidationError cause should print validation error 1`] = ` -"a/b.js - 1 error - - ✖ ResolveError: validation err - - /a/b is required - /c/d must be an integer - /e/f must be one of enums: ["foo","bar"] - -" -`; - -exports[`when error is a ResolveError with cause should print index 1`] = ` -"a.js - 1 error - - ✖ ResolveError: test err - Error: test err cause - at new Promise () - -" -`; - -exports[`when error is a ResolveError with component should print index 1`] = ` -"a.js - 1 error - - ✖ ResolveError: test err - Kind: kosko.dev/v1/Test - Name: bar - -" -`; - -exports[`when error is a ResolveError with component.namespace should print index 1`] = ` -"a.js - 1 error - - ✖ ResolveError: test err - Kind: kosko.dev/v1/Test - Namespace: foo - Name: bar - -" -`; - -exports[`when error is a ResolveError with index should print index 1`] = ` -"a.js - 1 error - - ✖ ResolveError: test err - Index: [1, 3, 5] - -" -`; - -exports[`when error is a ResolveError with path not in cwd should print the full path 1`] = ` -"/bar/a.js - 1 error - - ✖ ResolveError: test err - -" -`; - -exports[`when error is a ResolveError with path should treat as a normal error 1`] = ` -"a.js - 1 error - - ✖ ResolveError: test err - -" -`; - -exports[`when error is a ResolveError without path should treat as a normal error 1`] = ` -"Other 1 error - - ✖ ResolveError: test err - - at new Promise () - -" -`; - -exports[`when error is a nested AggregatedError should flatten errors 1`] = ` -"Other 3 errors - - ✖ Error: root err - - at new Promise () - - ✖ Error: child err - - at new Promise () - - ✖ Error: grandchild err - - at new Promise () - -" -`; - -exports[`when error is a string should print as an error 1`] = ` -"Other 1 error - - ✖ Error: test err - -" -`; - -exports[`when error is an Error should print in other error section 1`] = ` -"Other 1 error - - ✖ Error: test err - - at new Promise () - -" -`; - -exports[`when error is an object with message only should print as an error 1`] = ` -"Other 1 error - - ✖ Error: test err - -" -`; - -exports[`when error is an object with name and message should print as an error 1`] = ` -"Other 1 error - - ✖ TestError: test err - -" -`; diff --git a/packages/cli/src/commands/generate/__tests__/__snapshots__/set-option.ts.snap b/packages/cli/src/commands/generate/__tests__/__snapshots__/set-option.ts.snap deleted file mode 100644 index 7c23d4b0e..000000000 --- a/packages/cli/src/commands/generate/__tests__/__snapshots__/set-option.ts.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`CLI Variables Env Reducer should fail on incorrect JSON path 1`] = ` -"Lexical error on line 1. Unrecognized text. -phoneNumbers[?@.type=='home'].num --------------^" -`; diff --git a/packages/cli/vitest.config.integration.ts b/packages/cli/vitest.config.integration.ts new file mode 100644 index 000000000..4f3ac4719 --- /dev/null +++ b/packages/cli/vitest.config.integration.ts @@ -0,0 +1 @@ +export { integration as default } from "@kosko/vitest-config"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0722a1e53..ae3c3c6e9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -321,6 +321,9 @@ importers: '@kosko/test-utils': specifier: workspace:^ version: link:../../internal/test-utils + '@kosko/vitest-config': + specifier: workspace:^ + version: link:../../internal/vitest-config '@types/bl': specifier: ^5.0.2 version: 5.0.2 @@ -351,6 +354,9 @@ importers: replace-string: specifier: ^3.1.0 version: 3.1.0 + vitest: + specifier: ^1.2.2 + version: 1.2.2(@types/node@18.11.14) packages/common-utils: devDependencies: