@pagopa/dx-cli 0.22.0 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,43 +1,45 @@
|
|
|
1
|
+
import fc from "fast-check";
|
|
1
2
|
/**
|
|
2
3
|
* Tests for the CLI environment schema.
|
|
3
4
|
* Validates that `cliEnvSchema` correctly parses `process.env`.
|
|
4
5
|
*/
|
|
5
6
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { z } from "zod";
|
|
6
8
|
import { cliEnvSchema } from "../env.js";
|
|
9
|
+
// The accepted stringbool values mirror those recognised by z.stringbool().
|
|
10
|
+
const CI_TRUTHY = ["true", "1", "yes", "y", "on"];
|
|
11
|
+
const CI_FALSEY = ["false", "0", "no", "n", "off"];
|
|
12
|
+
const CI_ACCEPTED = [...CI_TRUTHY, ...CI_FALSEY];
|
|
7
13
|
describe("cliEnvSchema", () => {
|
|
8
14
|
afterEach(() => {
|
|
9
15
|
vi.unstubAllEnvs();
|
|
10
16
|
});
|
|
11
17
|
describe("CI field", () => {
|
|
12
|
-
it("
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
it("should be true for truthy string-bool values", () => {
|
|
19
|
+
fc.assert(fc.property(fc.constantFrom(...CI_TRUTHY), (value) => {
|
|
20
|
+
vi.stubEnv("CI", value);
|
|
21
|
+
const result = cliEnvSchema.safeParse(process.env);
|
|
22
|
+
expect(result.success).toBe(true);
|
|
23
|
+
expect(result.success && result.data.CI).toBe(true);
|
|
24
|
+
}));
|
|
17
25
|
});
|
|
18
|
-
it("
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
it("should be false for falsey string-bool values or when unset", () => {
|
|
27
|
+
fc.assert(fc.property(fc.constantFrom(...CI_FALSEY, undefined), (value) => {
|
|
28
|
+
vi.stubEnv("CI", value);
|
|
29
|
+
const result = cliEnvSchema.safeParse(process.env);
|
|
30
|
+
expect(result.success).toBe(true);
|
|
31
|
+
expect(result.success && result.data.CI).toBe(false);
|
|
32
|
+
}));
|
|
23
33
|
});
|
|
24
|
-
it("
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
it("should not parse unrecognised values", () => {
|
|
35
|
+
fc.assert(fc.property(
|
|
36
|
+
// Every string not in the accepted list
|
|
37
|
+
fc.string().filter((s) => !CI_ACCEPTED.includes(s.toLowerCase())), (value) => {
|
|
38
|
+
vi.stubEnv("CI", value);
|
|
39
|
+
const result = cliEnvSchema.safeParse(process.env);
|
|
40
|
+
expect(result.success).toBe(false);
|
|
41
|
+
expect(result.error).toBeInstanceOf(z.ZodError);
|
|
42
|
+
}));
|
|
29
43
|
});
|
|
30
|
-
it("captures CI=1 for numeric-style env vars", () => {
|
|
31
|
-
vi.stubEnv("CI", "1");
|
|
32
|
-
const result = cliEnvSchema.safeParse(process.env);
|
|
33
|
-
expect(result.success).toBe(true);
|
|
34
|
-
expect(result.success && result.data.CI).toBe("1");
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
it("passes through an object with unrelated env keys without failing", () => {
|
|
38
|
-
vi.stubEnv("CI", "true");
|
|
39
|
-
const result = cliEnvSchema.safeParse(process.env);
|
|
40
|
-
expect(result.success).toBe(true);
|
|
41
|
-
expect(result.success && result.data.CI).toBe("true");
|
|
42
44
|
});
|
|
43
45
|
});
|
|
@@ -9,9 +9,7 @@
|
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
export const cliEnvSchema = z
|
|
11
11
|
.object({
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
// convention used by `is-interactive` and `ora`.
|
|
15
|
-
CI: z.string().optional(),
|
|
12
|
+
// Use a truthy value to enable CI mode.
|
|
13
|
+
CI: z.stringbool().default(false),
|
|
16
14
|
})
|
|
17
15
|
.loose();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagopa/dx-cli",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A CLI useful to manage DX tools.",
|
|
6
6
|
"repository": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"semver": "^7.7.4",
|
|
49
49
|
"yaml": "^2.8.4",
|
|
50
50
|
"zod": "^4.4.2",
|
|
51
|
-
"@pagopa/dx-savemoney": "^0.2.
|
|
51
|
+
"@pagopa/dx-savemoney": "^0.2.6"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@tsconfig/node24": "24.0.4",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"@types/semver": "^7.7.1",
|
|
59
59
|
"@vitest/coverage-v8": "^3.2.4",
|
|
60
60
|
"eslint": "^10.3.0",
|
|
61
|
+
"fast-check": "^4.8.0",
|
|
61
62
|
"memfs": "^4.57.2",
|
|
62
63
|
"plop": "^4.0.5",
|
|
63
64
|
"prettier": "3.8.3",
|