Skip to content

Commit

Permalink
test(cli): Use vitest in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Feb 11, 2024
1 parent 0880c31 commit acf4a85
Show file tree
Hide file tree
Showing 33 changed files with 73 additions and 285 deletions.
17 changes: 0 additions & 17 deletions internal/jest-preset/integration/jest-preset.cjs

This file was deleted.

3 changes: 0 additions & 3 deletions internal/jest-preset/integration/setup.cjs

This file was deleted.

8 changes: 0 additions & 8 deletions jest.integration.config.ts

This file was deleted.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
"[31merror[39m - Invalid JSONPath expression "tolerations[[email protected]=='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[[email protected]=='key2'].value": Lexical error on line 1. Unrecognized text.
tolerations[[email protected]=='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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/cli/integration/generate-cjs/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
"[1mcomponents/nginx.ts[22m - 1 error
"components/nginx.ts - 1 error
[31m✖ ResolveError: Validation error[39m
✖ ResolveError: Validation error
Kind: v1/Pod
Name: test-pod
/spec must have required property 'containers'
[31merror[39m - Generate failed (Total 1 error)"
error - Generate failed (Total 1 error)"
`;
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
"---
Expand Down
1 change: 1 addition & 0 deletions packages/cli/integration/generate-mixed/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
"---
Expand Down
1 change: 1 addition & 0 deletions packages/cli/integration/generate-mjs/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
// 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`] = `
"[1mcomponents/foo.js[22m - 1 error
exports[`when bail is not set > should print the error 1`] = `
"components/foo.js - 1 error
[31m✖ ResolveError: Validation error[39m
✖ ResolveError: Validation error
Index: [0]
Kind: v1/Pod
Name: foo
/spec must have required property 'containers'
[1mcomponents/nginx.js[22m - 2 errors
components/nginx.js - 2 errors
[31m✖ ResolveError: Validation error[39m
✖ ResolveError: Validation error
Index: [0]
Kind: apps/v1/Deployment
Name: nginx
/spec must have required property 'selector'
/spec must have required property 'template'
[31m✖ ResolveError: Validation error[39m
✖ ResolveError: Validation error
Index: [1]
Kind: v1/Service
Name: nginx
/spec/ports/0/port must be integer
/spec/type must be equal to one of the allowed values: ["ClusterIP","ExternalName","LoadBalancer","NodePort"]
[31merror[39m - Generate failed (Total 3 errors)"
error - Generate failed (Total 3 errors)"
`;

exports[`when bail is true should print the error 1`] = `
"[1mcomponents/foo.js[22m - 1 error
exports[`when bail is true > should print the error 1`] = `
"components/foo.js - 1 error
[31m✖ ResolveError: Validation error[39m
✖ ResolveError: Validation error
Index: [0]
Kind: v1/Pod
Name: foo
/spec must have required property 'containers'
[31merror[39m - 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)"
`;
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
"---
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
"---
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { dirname } from "node:path";
import { runNodeCLI } from "../../utils/run";
import { test, expect } from "vitest";

const testDir = dirname(__dirname);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
// 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:
name: foo
spec: {}"
`;

exports[`when validate is not set should print the error 1`] = `
"[1mcomponents/foo.js[22m - 1 error
exports[`when validate is not set > should print the error 1`] = `
"components/foo.js - 1 error
[31m✖ ResolveError: Validation error[39m
✖ ResolveError: Validation error
Kind: v1/Pod
Name: foo
/spec must have required property 'containers'
[31merror[39m - Generate failed (Total 1 error)"
error - Generate failed (Total 1 error)"
`;

exports[`when validate is true should print the error 1`] = `
"[1mcomponents/foo.js[22m - 1 error
exports[`when validate is true > should print the error 1`] = `
"components/foo.js - 1 error
[31m✖ ResolveError: Validation error[39m
✖ ResolveError: Validation error
Kind: v1/Pod
Name: foo
/spec must have required property 'containers'
[31merror[39m - Generate failed (Total 1 error)"
error - Generate failed (Total 1 error)"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 0 additions & 3 deletions packages/cli/integration/jest.config.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions packages/cli/integration/migrate/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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__");

Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
"[1mcomponents/foo.js[22m - 1 error
"components/foo.js - 1 error
[31m✖ ResolveError: Validation error[39m
✖ ResolveError: Validation error
Kind: v1/Pod
Name: foo
/spec must have required property 'containers'
[31merror[39m - Generate failed (Total 1 error)"
error - Generate failed (Total 1 error)"
`;
Loading

0 comments on commit acf4a85

Please sign in to comment.