Skip to content

Commit ed0c24f

Browse files
committed
some more jest syntax fun to check Verror infos
1 parent 625d517 commit ed0c24f

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

test/integration-local/feature-toggles.integration.test.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jest.mock("fs", () => ({
1111
access: mockAccess,
1212
}));
1313

14+
const VError = require("verror");
15+
1416
const { stateFromInfo } = require("../__common__/from-info");
1517
const { FEATURE, mockConfig: config } = require("../__common__/mockdata");
1618

@@ -99,21 +101,41 @@ describe("local integration test", () => {
99101
};
100102
mockReadFile.mockImplementationOnce((path, cb) => cb(null, Buffer.from(JSON.stringify(configForConflict))));
101103

102-
await expect(
103-
toggles.initializeFeatures({ config: configForRuntime, configFile: "toggles.json" })
104-
).rejects.toMatchInlineSnapshot(
104+
const caught = await toggles
105+
.initializeFeatures({ config: configForRuntime, configFile: "toggles.json" })
106+
.catch((err) => err);
107+
expect(caught).toMatchInlineSnapshot(
105108
`[FeatureTogglesError: initialization aborted, could not process configuration: feature is configured twice]`
106109
);
110+
expect(VError.info(caught)).toMatchInlineSnapshot(`
111+
{
112+
"featureKey": "test/feature_a",
113+
"sourceConflicting": "FILE",
114+
"sourceExisting": "RUNTIME",
115+
"sourceFilepathConflicting": "toggles.json",
116+
}
117+
`);
107118
});
108119

109120
test("init config conflict between file A and file B throws", async () => {
110121
mockReadFile.mockImplementationOnce((path, cb) => cb(null, Buffer.from(JSON.stringify(configForFile))));
111122
mockReadFile.mockImplementationOnce((path, cb) => cb(null, Buffer.from(JSON.stringify(configForFile))));
112-
await expect(
113-
toggles.initializeFeatures({ configFiles: ["toggles-1.json", "toggles-2.json"] })
114-
).rejects.toMatchInlineSnapshot(
123+
124+
const caught = await toggles
125+
.initializeFeatures({ configFiles: ["toggles-1.json", "toggles-2.json"] })
126+
.catch((err) => err);
127+
expect(caught).toMatchInlineSnapshot(
115128
`[FeatureTogglesError: initialization aborted, could not process configuration: feature is configured twice]`
116129
);
130+
expect(VError.info(caught)).toMatchInlineSnapshot(`
131+
{
132+
"featureKey": "test/feature_c",
133+
"sourceConflicting": "FILE",
134+
"sourceExisting": "FILE",
135+
"sourceFilepathConflicting": "toggles-2.json",
136+
"sourceFilepathExisting": "toggles-1.json",
137+
}
138+
`);
117139
});
118140

119141
test("init config conflict between file and auto preserves", async () => {

0 commit comments

Comments
 (0)