Skip to content

Commit f72c9c2

Browse files
committed
style(tests): apply prettier formatting
1 parent dd1cb33 commit f72c9c2

4 files changed

Lines changed: 123 additions & 73 deletions

File tree

tests/init-cli.unit.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ function spm(args: string): string {
2323

2424
describe("spm init", () => {
2525
beforeEach(() => mkdirSync(TMP, { recursive: true }));
26-
afterEach(() => rmSync(TMP, { recursive: true, force: true }));
26+
afterEach(() => {
27+
rmSync(TMP, { recursive: true, force: true });
28+
});
2729

2830
it("creates .spm.json in existing directory (default format)", () => {
2931
spm(`init ${TMP}`);
@@ -74,9 +76,7 @@ describe("spm init", () => {
7476

7577
it("respects --title and --scope", () => {
7678
spm(`init ${TMP} --title "My Project" --scope application`);
77-
const doc = JSON.parse(
78-
readFileSync(join(TMP, ".spm.json"), "utf8"),
79-
);
79+
const doc = JSON.parse(readFileSync(join(TMP, ".spm.json"), "utf8"));
8080
assert.equal(doc.metadata.title, "My Project");
8181
assert.equal(doc.metadata.scope, "application");
8282
});

tests/mutate.unit.test.ts

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ function makeDoc(nodes: Node[] = []): SysProMDocument {
1717
describe("addNode", () => {
1818
it("adds to nodes array", () => {
1919
const doc = makeDoc();
20-
const newDoc = addNodeOp({ doc, node: { id: "I1", type: "intent", name: "Test" } });
20+
const newDoc = addNodeOp({
21+
doc,
22+
node: { id: "I1", type: "intent", name: "Test" },
23+
});
2124
assert.equal(newDoc.nodes.length, 1);
2225
assert.equal(newDoc.nodes[0].id, "I1");
2326
// Original should be unchanged
@@ -27,7 +30,8 @@ describe("addNode", () => {
2730
it("rejects duplicate ID", () => {
2831
const doc = makeDoc([{ id: "I1", type: "intent", name: "Existing" }]);
2932
assert.throws(
30-
() => addNodeOp({ doc, node: { id: "I1", type: "concept", name: "New" } }),
33+
() =>
34+
addNodeOp({ doc, node: { id: "I1", type: "concept", name: "New" } }),
3135
/already exists/,
3236
);
3337
});
@@ -98,10 +102,14 @@ describe("removeNode", () => {
98102
describe("updateNode", () => {
99103
it("updates specified fields", () => {
100104
const doc = makeDoc([{ id: "I1", type: "intent", name: "Old" }]);
101-
const newDoc = updateNodeOp({ doc, id: "I1", fields: {
102-
name: "New",
103-
description: "Updated",
104-
}});
105+
const newDoc = updateNodeOp({
106+
doc,
107+
id: "I1",
108+
fields: {
109+
name: "New",
110+
description: "Updated",
111+
},
112+
});
105113
assert.equal(newDoc.nodes[0].name, "New");
106114
assert.equal(newDoc.nodes[0].description, "Updated");
107115
});
@@ -130,27 +138,38 @@ describe("addRelationship", () => {
130138
{ id: "I1", type: "intent", name: "A" },
131139
{ id: "I2", type: "intent", name: "B" },
132140
]);
133-
const newDoc = addRelationshipOp({ doc, rel: {
134-
from: "I1",
135-
to: "I2",
136-
type: "refines",
137-
}});
141+
const newDoc = addRelationshipOp({
142+
doc,
143+
rel: {
144+
from: "I1",
145+
to: "I2",
146+
type: "refines",
147+
},
148+
});
138149
assert.equal(newDoc.relationships?.length, 1);
139150
assert.equal(newDoc.relationships?.[0].type, "refines");
140151
});
141152

142153
it("throws for missing from node", () => {
143154
const doc = makeDoc([{ id: "I2", type: "intent", name: "B" }]);
144155
assert.throws(
145-
() => addRelationshipOp({ doc, rel: { from: "I1", to: "I2", type: "refines" } }),
156+
() =>
157+
addRelationshipOp({
158+
doc,
159+
rel: { from: "I1", to: "I2", type: "refines" },
160+
}),
146161
/Node not found.*I1/,
147162
);
148163
});
149164

150165
it("throws for missing to node", () => {
151166
const doc = makeDoc([{ id: "I1", type: "intent", name: "A" }]);
152167
assert.throws(
153-
() => addRelationshipOp({ doc, rel: { from: "I1", to: "I2", type: "refines" } }),
168+
() =>
169+
addRelationshipOp({
170+
doc,
171+
rel: { from: "I1", to: "I2", type: "refines" },
172+
}),
154173
/Node not found.*I2/,
155174
);
156175
});
@@ -165,7 +184,12 @@ describe("removeRelationship", () => {
165184
],
166185
relationships: [{ from: "I1", to: "I2", type: "refines" }],
167186
};
168-
const newDoc = removeRelationshipOp({ doc, from: "I1", type: "refines", to: "I2" });
187+
const newDoc = removeRelationshipOp({
188+
doc,
189+
from: "I1",
190+
type: "refines",
191+
to: "I2",
192+
});
169193
assert.equal(newDoc.relationships?.length ?? 0, 0);
170194
});
171195

@@ -178,7 +202,8 @@ describe("removeRelationship", () => {
178202
relationships: [],
179203
};
180204
assert.throws(
181-
() => removeRelationshipOp({ doc, from: "I1", type: "refines", to: "I2" }),
205+
() =>
206+
removeRelationshipOp({ doc, from: "I1", type: "refines", to: "I2" }),
182207
/not found/,
183208
);
184209
});

tests/resolve-input.unit.test.ts

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,23 @@ describe("resolveInput", () => {
5757

5858
it("finds glob match *.spm.json", () => {
5959
writeFileSync(join(TMP, "project.spm.json"), "{}");
60-
assert.equal(
61-
resolveInput(undefined, TMP),
62-
join(TMP, "project.spm.json"),
63-
);
60+
assert.equal(resolveInput(undefined, TMP), join(TMP, "project.spm.json"));
6461
});
6562

6663
it("finds glob match *.spm.md", () => {
6764
writeFileSync(join(TMP, "project.spm.md"), "");
68-
assert.equal(
69-
resolveInput(undefined, TMP),
70-
join(TMP, "project.spm.md"),
71-
);
65+
assert.equal(resolveInput(undefined, TMP), join(TMP, "project.spm.md"));
7266
});
7367

7468
it("finds glob match *.spm/ directory", () => {
7569
mkdirSync(join(TMP, "project.spm"));
76-
assert.equal(
77-
resolveInput(undefined, TMP),
78-
join(TMP, "project.spm"),
79-
);
70+
assert.equal(resolveInput(undefined, TMP), join(TMP, "project.spm"));
8071
});
8172

8273
it("prefers *.spm.json over *.spm.md", () => {
8374
writeFileSync(join(TMP, "project.spm.json"), "{}");
8475
writeFileSync(join(TMP, "project.spm.md"), "");
85-
assert.equal(
86-
resolveInput(undefined, TMP),
87-
join(TMP, "project.spm.json"),
88-
);
76+
assert.equal(resolveInput(undefined, TMP), join(TMP, "project.spm.json"));
8977
});
9078

9179
it("errors on multiple *.spm.json matches", () => {
@@ -151,18 +139,12 @@ describe("resolveInput", () => {
151139

152140
it("finds .SysProM.json (case-insensitive)", () => {
153141
writeFileSync(join(TMP, ".SysProM.json"), "{}");
154-
assert.equal(
155-
resolveInput(undefined, TMP),
156-
join(TMP, ".SysProM.json"),
157-
);
142+
assert.equal(resolveInput(undefined, TMP), join(TMP, ".SysProM.json"));
158143
});
159144

160145
it("finds Project.SPM.JSON (case-insensitive glob)", () => {
161146
writeFileSync(join(TMP, "Project.SPM.JSON"), "{}");
162-
assert.equal(
163-
resolveInput(undefined, TMP),
164-
join(TMP, "Project.SPM.JSON"),
165-
);
147+
assert.equal(resolveInput(undefined, TMP), join(TMP, "Project.SPM.JSON"));
166148
});
167149

168150
it("finds .SYSPROM/ directory (case-insensitive)", () => {
@@ -181,25 +163,33 @@ describe("resolveInput", () => {
181163
return result;
182164
})();
183165

184-
it("errors on case-variant exact matches (.spm.json vs .SPM.json)", {
185-
skip: !caseSensitiveFs && "case-insensitive filesystem",
186-
}, () => {
187-
writeFileSync(join(TMP, ".spm.json"), "{}");
188-
writeFileSync(join(TMP, ".SPM.json"), "{}");
189-
assert.throws(
190-
() => resolveInput(undefined, TMP),
191-
/Multiple SysProM documents found/,
192-
);
193-
});
194-
195-
it("errors on case-variant glob matches (a.spm.json vs A.SPM.JSON)", {
196-
skip: !caseSensitiveFs && "case-insensitive filesystem",
197-
}, () => {
198-
writeFileSync(join(TMP, "a.spm.json"), "{}");
199-
writeFileSync(join(TMP, "A.SPM.JSON"), "{}");
200-
assert.throws(
201-
() => resolveInput(undefined, TMP),
202-
/Multiple SysProM documents found/,
203-
);
204-
});
166+
it(
167+
"errors on case-variant exact matches (.spm.json vs .SPM.json)",
168+
{
169+
skip: !caseSensitiveFs && "case-insensitive filesystem",
170+
},
171+
() => {
172+
writeFileSync(join(TMP, ".spm.json"), "{}");
173+
writeFileSync(join(TMP, ".SPM.json"), "{}");
174+
assert.throws(
175+
() => resolveInput(undefined, TMP),
176+
/Multiple SysProM documents found/,
177+
);
178+
},
179+
);
180+
181+
it(
182+
"errors on case-variant glob matches (a.spm.json vs A.SPM.JSON)",
183+
{
184+
skip: !caseSensitiveFs && "case-insensitive filesystem",
185+
},
186+
() => {
187+
writeFileSync(join(TMP, "a.spm.json"), "{}");
188+
writeFileSync(join(TMP, "A.SPM.JSON"), "{}");
189+
assert.throws(
190+
() => resolveInput(undefined, TMP),
191+
/Multiple SysProM documents found/,
192+
);
193+
},
194+
);
205195
});

tests/task-cli.unit.test.ts

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@ function makeChangeDoc(
1818
describe("addPlanTask", () => {
1919
it("appends task when plan already exists", () => {
2020
const doc = makeChangeDoc([{ description: "existing task", done: false }]);
21-
const newDoc = addPlanTaskOp({ doc, changeId: "CH1", description: "new task" });
21+
const newDoc = addPlanTaskOp({
22+
doc,
23+
changeId: "CH1",
24+
description: "new task",
25+
});
2226
assert.equal(newDoc.nodes[0].plan?.length, 2);
2327
assert.equal(newDoc.nodes[0].plan?.[1].description, "new task");
2428
assert.equal(newDoc.nodes[0].plan?.[1].done, false);
2529
});
2630

2731
it("creates plan array when plan is undefined", () => {
2832
const doc = makeChangeDoc();
29-
const newDoc = addPlanTaskOp({ doc, changeId: "CH1", description: "first task" });
33+
const newDoc = addPlanTaskOp({
34+
doc,
35+
changeId: "CH1",
36+
description: "first task",
37+
});
3038
assert.equal(newDoc.nodes[0].plan?.length, 1);
3139
assert.equal(newDoc.nodes[0].plan?.[0].description, "first task");
3240
assert.equal(newDoc.nodes[0].plan?.[0].done, false);
@@ -50,41 +58,63 @@ describe("addPlanTask", () => {
5058
describe("updatePlanTask", () => {
5159
it("sets done: true at a valid index", () => {
5260
const doc = makeChangeDoc([{ description: "task A", done: false }]);
53-
const newDoc = updatePlanTaskOp({ doc, changeId: "CH1", taskIndex: 0, done: true });
61+
const newDoc = updatePlanTaskOp({
62+
doc,
63+
changeId: "CH1",
64+
taskIndex: 0,
65+
done: true,
66+
});
5467
assert.equal(newDoc.nodes[0].plan?.[0].done, true);
5568
});
5669

5770
it("sets done: false at a valid index (undone)", () => {
5871
const doc = makeChangeDoc([{ description: "task A", done: true }]);
59-
const newDoc = updatePlanTaskOp({ doc, changeId: "CH1", taskIndex: 0, done: false });
72+
const newDoc = updatePlanTaskOp({
73+
doc,
74+
changeId: "CH1",
75+
taskIndex: 0,
76+
done: false,
77+
});
6078
assert.equal(newDoc.nodes[0].plan?.[0].done, false);
6179
});
6280

6381
it("throws out-of-range for index equal to plan length", () => {
6482
const doc = makeChangeDoc([{ description: "task A", done: false }]);
6583
assert.throws(
66-
() => updatePlanTaskOp({ doc, changeId: "CH1", taskIndex: 1, done: true }),
84+
() =>
85+
updatePlanTaskOp({ doc, changeId: "CH1", taskIndex: 1, done: true }),
6786
/Task index 1 out of range/,
6887
);
6988
});
7089

7190
it("throws out-of-range for negative index", () => {
7291
const doc = makeChangeDoc([{ description: "task A", done: false }]);
7392
assert.throws(
74-
() => updatePlanTaskOp({ doc, changeId: "CH1", taskIndex: -1, done: true }),
93+
() =>
94+
updatePlanTaskOp({ doc, changeId: "CH1", taskIndex: -1, done: true }),
7595
/Task index -1 out of range/,
7696
);
7797
});
7898

7999
it("throws when plan is undefined", () => {
80100
const doc = makeChangeDoc();
81-
assert.throws(() => updatePlanTaskOp({ doc, changeId: "CH1", taskIndex: 0, done: true }), /out of range/);
101+
assert.throws(
102+
() =>
103+
updatePlanTaskOp({ doc, changeId: "CH1", taskIndex: 0, done: true }),
104+
/out of range/,
105+
);
82106
});
83107

84108
it("throws Node not found for unknown change ID", () => {
85109
const doc = makeChangeDoc([{ description: "task A", done: false }]);
86110
assert.throws(
87-
() => updatePlanTaskOp({ doc, changeId: "MISSING", taskIndex: 0, done: true }),
111+
() =>
112+
updatePlanTaskOp({
113+
doc,
114+
changeId: "MISSING",
115+
taskIndex: 0,
116+
done: true,
117+
}),
88118
/Node not found.*MISSING/,
89119
);
90120
});
@@ -100,7 +130,12 @@ describe("updatePlanTask", () => {
100130
{ description: "task A", done: false },
101131
{ description: "task B", done: false },
102132
]);
103-
const newDoc = updatePlanTaskOp({ doc, changeId: "CH1", taskIndex: 0, done: true });
133+
const newDoc = updatePlanTaskOp({
134+
doc,
135+
changeId: "CH1",
136+
taskIndex: 0,
137+
done: true,
138+
});
104139
assert.equal(newDoc.nodes[0].plan?.[1].done, false);
105140
});
106141
});

0 commit comments

Comments
 (0)