Skip to content

Commit c0fc559

Browse files
committed
more consistent naming in tests
1 parent e2a12af commit c0fc559

File tree

10 files changed

+274
-284
lines changed

10 files changed

+274
-284
lines changed

test/docs.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { readFileSync } = require("fs");
44
const { join } = require("path");
55

66
describe("docs", () => {
7-
it("documentation README / overview consistency check", async () => {
7+
test("documentation README / overview consistency check", async () => {
88
const headings = ["Getting Started", "Features", "Peers"];
99
const readmeData = readFileSync(join(__dirname, "..", "README.md")).toString();
1010
const overviewData = readFileSync(join(__dirname, "..", "docs", "index.md")).toString();

test/featureToggles.test.js

Lines changed: 203 additions & 213 deletions
Large diffs are not rendered by default.

test/integration-local/featureToggles.integration.test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,22 @@ describe("local integration test", () => {
9191
});
9292

9393
describe("init", () => {
94-
it("init fails resolving for bad config paths", async () => {
94+
test("init fails resolving for bad config paths", async () => {
9595
const { readFile: readFileSpy } = require("fs");
9696
readFileSpy.mockImplementationOnce(fs.readFile);
9797
await expect(toggles.initializeFeatures({ configFile: "fantasy_name" })).rejects.toMatchInlineSnapshot(
9898
`[FeatureTogglesError: initialization aborted, could not read config file: ENOENT: no such file or directory, open 'fantasy_name']`
9999
);
100100
});
101101

102-
it("init fails processing for bad formats", async () => {
102+
test("init fails processing for bad formats", async () => {
103103
const badConfig = { ...config, bla: undefined };
104104
await expect(toggles.initializeFeatures({ config: badConfig })).rejects.toMatchInlineSnapshot(
105105
`[FeatureTogglesError: initialization aborted, could not process configuration: feature configuration is not an object]`
106106
);
107107
});
108108

109-
it("init config precedence", async () => {
109+
test("init config precedence", async () => {
110110
const { readFile: readFileSpy } = require("fs");
111111

112112
const configForRuntime = {
@@ -206,7 +206,7 @@ describe("local integration test", () => {
206206
});
207207

208208
describe("validations", () => {
209-
it("two regex validations", async () => {
209+
test("two regex validations", async () => {
210210
await toggles.initializeFeatures({
211211
config: {
212212
[FEATURE.A]: {
@@ -245,7 +245,7 @@ describe("local integration test", () => {
245245
expect(await toggles.changeFeatureValue(FEATURE.A, "foobar")).toBeUndefined();
246246
});
247247

248-
it("custom module validations just module from CWD", async () => {
248+
test("custom module validations just module from CWD", async () => {
249249
jest.mock("./virtual-validator-just-module", () => jest.fn(), { virtual: true });
250250
const mockValidator = require("./virtual-validator-just-module");
251251
await toggles.initializeFeatures({
@@ -262,7 +262,7 @@ describe("local integration test", () => {
262262
expect(mockValidator).toHaveBeenCalledWith("fallback", undefined, undefined);
263263
});
264264

265-
it("custom module validations with call from CWD", async () => {
265+
test("custom module validations with call from CWD", async () => {
266266
jest.mock("./virtual-validator-with-call", () => ({ validator: jest.fn() }), { virtual: true });
267267
const { validator: mockValidator } = require("./virtual-validator-with-call");
268268
await toggles.initializeFeatures({
@@ -279,7 +279,7 @@ describe("local integration test", () => {
279279
expect(mockValidator).toHaveBeenCalledWith("fallback", undefined, undefined);
280280
});
281281

282-
it("custom module validations just module from CONFIG_DIR", async () => {
282+
test("custom module validations just module from CONFIG_DIR", async () => {
283283
jest.mock("./virtual-validator-just-module", () => jest.fn(), { virtual: true });
284284
const mockValidator = require("./virtual-validator-just-module");
285285
const { readFile: readFileSpy } = require("fs");
@@ -301,7 +301,7 @@ describe("local integration test", () => {
301301
expect(mockValidator).toHaveBeenCalledWith("fallback", undefined, undefined);
302302
});
303303

304-
it("custom module validations with call from CONFIG_DIR", async () => {
304+
test("custom module validations with call from CONFIG_DIR", async () => {
305305
jest.mock("./virtual-validator-with-call", () => ({ validator: jest.fn() }), { virtual: true });
306306
const { validator: mockValidator } = require("./virtual-validator-with-call");
307307
const { readFile: readFileSpy } = require("fs");
@@ -329,7 +329,7 @@ describe("local integration test", () => {
329329
await toggles.initializeFeatures({ config });
330330
});
331331

332-
it("getFeaturesKeys, getFeatureValues, getFeaturesInfos", async () => {
332+
test("getFeaturesKeys, getFeatureValues, getFeaturesInfos", async () => {
333333
expect(toggles.getFeaturesKeys()).toEqual(Object.keys(config));
334334

335335
const featureStatesResult = await toggles.getFeaturesInfos();
@@ -361,7 +361,7 @@ describe("local integration test", () => {
361361
expect(redisWrapperLoggerSpy.warning).toHaveBeenCalledTimes(0);
362362
});
363363

364-
it("getFeatureValue, changeFeatureValue without scopes", async () => {
364+
test("getFeatureValue, changeFeatureValue without scopes", async () => {
365365
const oldValue = toggles.getFeatureValue(FEATURE.E);
366366

367367
const newValue = 9;
@@ -398,7 +398,7 @@ describe("local integration test", () => {
398398
expect(redisWrapperLoggerSpy.error).toHaveBeenCalledTimes(0);
399399
});
400400

401-
it("getFeatureValue with bad scopes", async () => {
401+
test("getFeatureValue with bad scopes", async () => {
402402
const oldRootValue = 5;
403403
const trapValue = 9;
404404
const badScopeMap1 = null; // not an object
@@ -443,7 +443,7 @@ describe("local integration test", () => {
443443
expect(toggles.getFeatureValue(FEATURE.E, badScopeMap3)).toEqual(oldRootValue);
444444
});
445445

446-
it("getFeatureValue, changeFeatureValue with scopes", async () => {
446+
test("getFeatureValue, changeFeatureValue with scopes", async () => {
447447
const rootOldValue = toggles.getFeatureValue(FEATURE.E);
448448

449449
const scopeMap = { component: "c1", tenant: "t1" };
@@ -541,7 +541,7 @@ describe("local integration test", () => {
541541
expect(redisWrapperLoggerSpy.error).toHaveBeenCalledTimes(0);
542542
});
543543

544-
it("getFeatureValue, changeFeatureValue with scopes and clearSubScopes, resetFeatureValue", async () => {
544+
test("getFeatureValue, changeFeatureValue with scopes and clearSubScopes, resetFeatureValue", async () => {
545545
const scopeMap = { component: "c1", tenant: "t1" };
546546
const subScopeMap = { layer: "l1", component: "c1", tenant: "t1" };
547547
const superScopeMap = { tenant: "t1" };
@@ -615,7 +615,7 @@ describe("local integration test", () => {
615615
expect(redisWrapperLoggerSpy.error).toHaveBeenCalledTimes(0);
616616
});
617617

618-
it("validateFeatureValue with invalid scopes", async () => {
618+
test("validateFeatureValue with invalid scopes", async () => {
619619
// valid
620620
expect(await toggles.validateFeatureValue(FEATURE.C, "", { tenant: "t1" })).toMatchInlineSnapshot(`[]`);
621621

@@ -668,7 +668,7 @@ describe("local integration test", () => {
668668
`);
669669
});
670670

671-
it("registerFeatureValueValidation, validateFeatureValue", async () => {
671+
test("registerFeatureValueValidation, validateFeatureValue", async () => {
672672
const successfulValidator = () => undefined;
673673
const failingValidator1 = () => {
674674
throw new Error("bla1");

test/plugin.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const cds = require("@sap/cds");
44
const { SERVICE_ENDPOINTS } = require("../src/plugin");
55

66
describe("plugin", () => {
7-
it("all endpoints are covered", async () => {
7+
test("all endpoints are covered", async () => {
88
const csn = await cds.load(["./src/service/feature-service.cds"]);
99
const csnEndpoints = Object.keys(csn.definitions).filter((name) => name.indexOf(".") !== -1);
1010
const coveredEndpoints = Object.values(SERVICE_ENDPOINTS).flat();

test/redisWrapper.test.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("redis wrapper test", () => {
5050
envMock._reset();
5151
});
5252

53-
it("_createMainClientAndConnect/_createSubscriberClientAndConnect shortcut", async () => {
53+
test("_createMainClientAndConnect/_createSubscriberClientAndConnect shortcut", async () => {
5454
const shortcutMain = "shortcutMain";
5555
const shortcutSubscriber = "shortcutSubscriber";
5656
redisWrapper._._setMainClient(shortcutMain);
@@ -64,7 +64,7 @@ describe("redis wrapper test", () => {
6464
expect(loggerSpy.error).not.toHaveBeenCalled();
6565
});
6666

67-
it("_createClientBase local", async () => {
67+
test("_createClientBase local", async () => {
6868
envMock.isOnCf = false;
6969
const client = redisWrapper._._createClientBase();
7070

@@ -84,7 +84,7 @@ describe("redis wrapper test", () => {
8484
expect(loggerSpy.error).not.toHaveBeenCalled();
8585
});
8686

87-
it("_createClientBase on CF", async () => {
87+
test("_createClientBase on CF", async () => {
8888
const mockUrl = "rediss://BAD_USERNAME:pwd@mockUrl";
8989
const mockUrlUsable = mockUrl.replace("BAD_USERNAME", "");
9090

@@ -101,7 +101,7 @@ describe("redis wrapper test", () => {
101101
expect(loggerSpy.error).not.toHaveBeenCalled();
102102
});
103103

104-
it("getMainClient", async () => {
104+
test("getMainClient", async () => {
105105
const client = await redisWrapper.getMainClient();
106106
expect(redis.createClient).toHaveBeenCalledTimes(1);
107107
expect(client.connect).toHaveBeenCalledTimes(1);
@@ -114,7 +114,7 @@ describe("redis wrapper test", () => {
114114
expect(loggerSpy.error).not.toHaveBeenCalled();
115115
});
116116

117-
it("getSubscriberClient", async () => {
117+
test("getSubscriberClient", async () => {
118118
const client = await redisWrapper.getSubscriberClient();
119119
expect(redis.createClient).toHaveBeenCalledTimes(1);
120120
expect(redisWrapper._._getSubscriberClient()).toBe(client);
@@ -126,7 +126,7 @@ describe("redis wrapper test", () => {
126126
expect(loggerSpy.error).not.toHaveBeenCalled();
127127
});
128128

129-
it("_clientExec", async () => {
129+
test("_clientExec", async () => {
130130
const result = await redisWrapper._._clientExec("SET", { key: "key", value: "value" });
131131
const client = redisWrapper._._getMainClient();
132132
expect(redis.createClient).toHaveBeenCalledTimes(1);
@@ -140,23 +140,23 @@ describe("redis wrapper test", () => {
140140
expect(loggerSpy.error).not.toHaveBeenCalled();
141141
});
142142

143-
it("type key", async () => {
143+
test("type key", async () => {
144144
const result = await redisWrapper.type("key");
145145
expect(mockClient.TYPE).toHaveBeenCalledTimes(1);
146146
expect(mockClient.TYPE).toHaveBeenCalledWith("key");
147147
expect(result).toBe("TYPE_return");
148148
expect(loggerSpy.error).not.toHaveBeenCalled();
149149
});
150150

151-
it("get key", async () => {
151+
test("get key", async () => {
152152
const result = await redisWrapper.get("key");
153153
expect(mockClient.GET).toHaveBeenCalledTimes(1);
154154
expect(mockClient.GET).toHaveBeenCalledWith("key");
155155
expect(result).toBe("GET_return");
156156
expect(loggerSpy.error).not.toHaveBeenCalled();
157157
});
158158

159-
it("getObject key", async () => {
159+
test("getObject key", async () => {
160160
const resultObj = { result: "result" };
161161
mockClient.GET.mockImplementationOnce(async () => JSON.stringify(resultObj));
162162
const result = await redisWrapper.getObject("key");
@@ -166,15 +166,15 @@ describe("redis wrapper test", () => {
166166
expect(loggerSpy.error).not.toHaveBeenCalled();
167167
});
168168

169-
it("set key value", async () => {
169+
test("set key value", async () => {
170170
const result = await redisWrapper.set("key", "value");
171171
expect(mockClient.SET).toHaveBeenCalledTimes(1);
172172
expect(mockClient.SET).toHaveBeenCalledWith("key", "value");
173173
expect(result).toBe("SET_return");
174174
expect(loggerSpy.error).not.toHaveBeenCalled();
175175
});
176176

177-
it("setObject key value", async () => {
177+
test("setObject key value", async () => {
178178
const inputObj = { input: "input" };
179179
const result = await redisWrapper.setObject("key", inputObj);
180180
expect(mockClient.SET).toHaveBeenCalledTimes(1);
@@ -183,15 +183,15 @@ describe("redis wrapper test", () => {
183183
expect(loggerSpy.error).not.toHaveBeenCalled();
184184
});
185185

186-
it("del key", async () => {
186+
test("del key", async () => {
187187
const result = await redisWrapper.del("key");
188188
expect(mockClient.DEL).toHaveBeenCalledTimes(1);
189189
expect(mockClient.DEL).toHaveBeenCalledWith("key");
190190
expect(result).toBe("DEL_return");
191191
expect(loggerSpy.error).not.toHaveBeenCalled();
192192
});
193193

194-
it("watchedGetSet", async () => {
194+
test("watchedGetSet", async () => {
195195
const oldValue = "oldValue";
196196
mockClient.GET.mockImplementationOnce(async () => oldValue);
197197
mockMultiClient.EXEC.mockImplementationOnce(async () => ["OK"]);
@@ -213,7 +213,7 @@ describe("redis wrapper test", () => {
213213
expect(loggerSpy.error).not.toHaveBeenCalled();
214214
});
215215

216-
it("watchedGetSetObject", async () => {
216+
test("watchedGetSetObject", async () => {
217217
const oldValue = { oldValue: "oldValue" };
218218
mockClient.GET.mockImplementationOnce(async () => JSON.stringify(oldValue));
219219
mockMultiClient.EXEC.mockImplementationOnce(async () => ["OK"]);
@@ -235,7 +235,7 @@ describe("redis wrapper test", () => {
235235
expect(loggerSpy.error).not.toHaveBeenCalled();
236236
});
237237

238-
it("watchedGetSetObject newValue = null", async () => {
238+
test("watchedGetSetObject newValue = null", async () => {
239239
const oldValue = { oldValue: "oldValue" };
240240
mockClient.GET.mockImplementationOnce(async () => JSON.stringify(oldValue));
241241
mockMultiClient.EXEC.mockImplementationOnce(async () => [1]);
@@ -257,7 +257,7 @@ describe("redis wrapper test", () => {
257257
expect(loggerSpy.error).not.toHaveBeenCalled();
258258
});
259259

260-
it("watchedGetSetObject oldValue = newValue", async () => {
260+
test("watchedGetSetObject oldValue = newValue", async () => {
261261
const oldValue = { oldValue: "oldValue" };
262262
mockClient.GET.mockImplementationOnce(async () => JSON.stringify(oldValue));
263263
const newValueCallback = jest.fn((oldValue) => oldValue);
@@ -276,7 +276,7 @@ describe("redis wrapper test", () => {
276276
expect(loggerSpy.error).not.toHaveBeenCalled();
277277
});
278278

279-
it("watchedGetSetObject 2x attempts on exec null reply", async () => {
279+
test("watchedGetSetObject 2x attempts on exec null reply", async () => {
280280
const oldValue1 = { oldValue1: "oldValue" };
281281
const oldValue2 = { oldValue2: "oldValue" };
282282
mockClient.GET.mockImplementationOnce(async () => JSON.stringify(oldValue1));
@@ -309,7 +309,7 @@ describe("redis wrapper test", () => {
309309
expect(loggerSpy.error).not.toHaveBeenCalled();
310310
});
311311

312-
it("watchedGetSetObject with exec keeps returning null", async () => {
312+
test("watchedGetSetObject with exec keeps returning null", async () => {
313313
const newValue1 = { newValue1: "newValue" };
314314
const oldValue1 = { oldValue1: "oldValue" };
315315
mockClient.GET.mockImplementation(async () => JSON.stringify(oldValue1));
@@ -334,7 +334,7 @@ describe("redis wrapper test", () => {
334334
mockMultiClient.EXEC.mockClear();
335335
});
336336

337-
it("watchedGetSetObject 2x attempts on exec throw", async () => {
337+
test("watchedGetSetObject 2x attempts on exec throw", async () => {
338338
const oldValue1 = { oldValue1: "oldValue" };
339339
const oldValue2 = { oldValue2: "oldValue" };
340340
mockClient.GET.mockImplementationOnce(async () => JSON.stringify(oldValue1));
@@ -369,7 +369,7 @@ describe("redis wrapper test", () => {
369369
expect(loggerSpy.error).not.toHaveBeenCalled();
370370
});
371371

372-
it("watchedGetSetObject with exec keeps throwing", async () => {
372+
test("watchedGetSetObject with exec keeps throwing", async () => {
373373
const newValue1 = { newValue1: "newValue" };
374374
const oldValue1 = { oldValue1: "oldValue" };
375375
mockClient.GET.mockImplementation(async () => JSON.stringify(oldValue1));
@@ -394,7 +394,7 @@ describe("redis wrapper test", () => {
394394
mockMultiClient.EXEC.mockClear();
395395
});
396396

397-
it("watchedHashGetSetObject", async () => {
397+
test("watchedHashGetSetObject", async () => {
398398
const oldValue = { oldValue: "oldValue" };
399399
mockClient.HGET.mockImplementationOnce(async () => JSON.stringify(oldValue));
400400
mockMultiClient.EXEC.mockImplementationOnce(async () => [1]);
@@ -416,15 +416,15 @@ describe("redis wrapper test", () => {
416416
expect(loggerSpy.error).not.toHaveBeenCalled();
417417
});
418418

419-
it("publishMessage", async () => {
419+
test("publishMessage", async () => {
420420
const result = await redisWrapper.publishMessage(channel, message);
421421
expect(mockClient.PUBLISH).toHaveBeenCalledTimes(1);
422422
expect(mockClient.PUBLISH).toHaveBeenCalledWith(channel, message);
423423
expect(result).toBe("PUBLISH_return");
424424
expect(loggerSpy.error).not.toHaveBeenCalled();
425425
});
426426

427-
it("_subscribedMessageHandler error", async () => {
427+
test("_subscribedMessageHandler error", async () => {
428428
const mockUrl = "rediss://BAD_USERNAME:pwd@mockUrl";
429429

430430
envMock.isOnCf = true;
@@ -446,7 +446,7 @@ describe("redis wrapper test", () => {
446446
);
447447
});
448448

449-
it("registerMessageHandler and subscribe", async () => {
449+
test("registerMessageHandler and subscribe", async () => {
450450
redisWrapper.registerMessageHandler(channel, mockMessageHandler);
451451
await redisWrapper.subscribe(channel);
452452

@@ -470,7 +470,7 @@ describe("redis wrapper test", () => {
470470
expect(loggerSpy.error).not.toHaveBeenCalled();
471471
});
472472

473-
it("removeMessageHandler and unsubscribe", async () => {
473+
test("removeMessageHandler and unsubscribe", async () => {
474474
redisWrapper._._getMessageHandlers().removeAllHandlers(channel);
475475
redisWrapper.registerMessageHandler(channel, mockMessageHandler);
476476
redisWrapper.registerMessageHandler(channel, mockMessageHandlerTwo);
@@ -490,7 +490,7 @@ describe("redis wrapper test", () => {
490490
expect(loggerSpy.error).not.toHaveBeenCalled();
491491
});
492492

493-
it("removeAllMessageHandlers", async () => {
493+
test("removeAllMessageHandlers", async () => {
494494
redisWrapper._._getMessageHandlers().removeAllHandlers(channel);
495495
redisWrapper.registerMessageHandler(channel, mockMessageHandler);
496496
redisWrapper.registerMessageHandler(channel, mockMessageHandlerTwo);

0 commit comments

Comments
 (0)