-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.test.js
More file actions
89 lines (74 loc) · 2.88 KB
/
commit.test.js
File metadata and controls
89 lines (74 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { describe, it } from "node:test";
import assert from "node:assert";
import { getArgs, COMMIT_TYPES, DEFAULT_MESSAGE } from "./commit.js";
describe("getArgs", () => {
it("restituisce help: true se primo argomento è --help", () => {
assert.deepStrictEqual(getArgs(["--help"]), { help: true });
});
it("restituisce help: true se primo argomento è -h", () => {
assert.deepStrictEqual(getArgs(["-h"]), { help: true });
});
it("nessun argomento: type undefined, message default", () => {
const out = getArgs([]);
assert.strictEqual(out.type, undefined);
assert.strictEqual(out.message, DEFAULT_MESSAGE);
assert.strictEqual(out.noPush, false);
assert.strictEqual(out.branchName, "main");
});
it("solo tipo: message default", () => {
const out = getArgs(["fix"]);
assert.strictEqual(out.type, "fix");
assert.strictEqual(out.message, DEFAULT_MESSAGE);
});
it("tipo e messaggio", () => {
const out = getArgs(["feat", "nuova funzionalità"]);
assert.strictEqual(out.type, "feat");
assert.strictEqual(out.message, "nuova funzionalità");
});
it("tipo, messaggio multiplo e --no-push", () => {
const out = getArgs(["fix", "corretto bug", "nel login", "--no-push"]);
assert.strictEqual(out.type, "fix");
assert.strictEqual(out.message, "corretto bug nel login");
assert.strictEqual(out.noPush, true);
});
it("-n imposta noPush", () => {
const out = getArgs(["refactoring", "semplificato", "-n"]);
assert.strictEqual(out.noPush, true);
});
it("--branch nome estrae branch per first", () => {
const out = getArgs(["first", "https://github.com/u/r.git", "--branch", "develop"]);
assert.strictEqual(out.branchName, "develop");
});
it("branchName default main se --branch assente", () => {
const out = getArgs(["feat", "x"]);
assert.strictEqual(out.branchName, "main");
});
});
describe("COMMIT_TYPES / tipo -> config", () => {
it("fix mappa al config fix", () => {
const config = COMMIT_TYPES.fix;
assert.strictEqual(config.label, "fix");
assert.strictEqual(config.prefix, "Fix");
});
it("feat mappa al config feat", () => {
const config = COMMIT_TYPES.feat;
assert.strictEqual(config.label, "feat");
});
it("refactoring mappa al config refactoring", () => {
const config = COMMIT_TYPES.refactoring;
assert.strictEqual(config.label, "refactoring");
});
it("first mappa al config first", () => {
const config = COMMIT_TYPES.first;
assert.strictEqual(config.label, "first");
});
it("tipo sconosciuto usa default", () => {
const config = COMMIT_TYPES.xyz || COMMIT_TYPES.default;
assert.strictEqual(config, COMMIT_TYPES.default);
assert.strictEqual(config.label, "commit");
});
it("undefined type usa default", () => {
const config = COMMIT_TYPES[undefined] || COMMIT_TYPES.default;
assert.strictEqual(config.label, "commit");
});
});