-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Summary: This implements `KindError`, an error type to act as the basis for our various `KAError` versions. This includes code to combine messages and stack traces in a meaningful way between a source error and the error being constructed around that. Also: - Enable no-default-exports lint rule - Named exports provide an explicit API that is easy to search, rename, etc. - Required updating to @babel/eslint-parser - Excludes index.js and types.js from coverage data - Adds jest-when This doesn't add any of the useful helper methods from mobile yet or anything sentry specific. The sentry stuff will be in a different package than core and the helpers will be added in an upcoming PR (either to KindError or a more specific derivation). Some of the helpers should be unnecessary now as the constructor uses an `options` arg to simplify the provision of various options. Issue: FEI-3997 ## Test plan: `yarn test` `yarn flow` `yarn lint` `yarn build` I also want to create some sort of E2E/integration test (see FEI-4058 for details on that) Author: somewhatabstract Reviewers: somewhatabstract, lillialexis Required Reviewers: Approved By: lillialexis Checks: ✅ codecov/project, ✅ CodeQL, ✅ Test (macOS-latest, 14.x), ✅ Test (macOS-latest, 12.x), ✅ Test (ubuntu-latest, 12.x), ✅ Gather coverage (ubuntu-latest, 14.x), ✅ Lint and flow check (ubuntu-latest, 14.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 14.x), ✅ Analyze (javascript), ⏭ dependabot Pull Request URL: #16
- Loading branch information
1 parent
22b238d
commit fbc363d
Showing
19 changed files
with
1,238 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"babel": { | ||
"configFile": "./build-settings/babel.config.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/wonder-stuff-core/src/__tests__/__snapshots__/build-caused-by-message.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`#buildCausedByMessage should default nullish and whitespace strings to (empty message) 1`] = ` | ||
"(empty message) | ||
caused by | ||
(empty message)" | ||
`; | ||
|
||
exports[`#buildCausedByMessage should default nullish and whitespace strings to (empty message) 2`] = ` | ||
"(empty message) | ||
caused by | ||
(empty message)" | ||
`; | ||
|
||
exports[`#buildCausedByMessage should default nullish and whitespace strings to (empty message) 3`] = ` | ||
"(empty message) | ||
caused by | ||
(empty message)" | ||
`; | ||
|
||
exports[`#buildCausedByMessage should default nullish and whitespace strings to (empty message) 4`] = ` | ||
"(empty message) | ||
caused by | ||
(empty message)" | ||
`; |
11 changes: 11 additions & 0 deletions
11
packages/wonder-stuff-core/src/__tests__/__snapshots__/kind-error.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`KindError #constructor should throw if the kind has whitespace like K I N D 1`] = `"kind must not contain whitespace"`; | ||
|
||
exports[`KindError #constructor should throw if the kind has whitespace like KI | ||
ND 1`] = `"kind must not contain whitespace"`; | ||
|
||
exports[`KindError #constructor should throw if the prefix has whitespace like P R E F I X 1`] = `"prefix must not contain whitespace"`; | ||
|
||
exports[`KindError #constructor should throw if the prefix has whitespace like PRE | ||
FIX 1`] = `"prefix must not contain whitespace"`; |
35 changes: 35 additions & 0 deletions
35
packages/wonder-stuff-core/src/__tests__/build-caused-by-message.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// @flow | ||
import {buildCausedByMessage} from "../build-caused-by-message.js"; | ||
|
||
describe("#buildCausedByMessage", () => { | ||
it("should combine the strings into a 'caused by' message", () => { | ||
// Arrange | ||
const consequence = "No more Halloween candy"; | ||
const cause = "Gluttonous parents"; | ||
|
||
// Act | ||
const result = buildCausedByMessage(consequence, cause); | ||
|
||
// Assert | ||
expect(result).toMatchInlineSnapshot(` | ||
"No more Halloween candy | ||
caused by | ||
Gluttonous parents" | ||
`); | ||
}); | ||
|
||
it.each([null, undefined, " ", "\n\t\t"])( | ||
"should default nullish and whitespace strings to (empty message)", | ||
(testCase) => { | ||
// Arrange | ||
const consequence = testCase; | ||
const cause = testCase; | ||
|
||
// Act | ||
const result = buildCausedByMessage(consequence, cause); | ||
|
||
// Assert | ||
expect(result).toMatchSnapshot(); | ||
}, | ||
); | ||
}); |
141 changes: 141 additions & 0 deletions
141
packages/wonder-stuff-core/src/__tests__/clone-metadata.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// @flow | ||
import {cloneMetadata} from "../clone-metadata.js"; | ||
|
||
describe("#cloneMetadata", () => { | ||
it.each([undefined, null])( | ||
"should return the metadata when it is %s", | ||
(value) => { | ||
// Arrange | ||
|
||
// Act | ||
const result = cloneMetadata(value); | ||
|
||
// Assert | ||
expect(result).toBe(value); | ||
}, | ||
); | ||
|
||
it("should freeze the clone", () => { | ||
// Arrange | ||
const spy = jest.spyOn(Object, "freeze"); | ||
|
||
// Act | ||
const result = cloneMetadata({}); | ||
|
||
// Assert | ||
expect(spy).toHaveBeenCalledWith(result); | ||
}); | ||
|
||
it("should clone a simple object", () => { | ||
// Arrange | ||
const metadata = { | ||
string: "bar", | ||
number: "42", | ||
boolean: "true", | ||
undefined: undefined, | ||
null: null, | ||
}; | ||
|
||
// Act | ||
const result = cloneMetadata(metadata); | ||
metadata.string = "baz"; | ||
metadata.number = "43"; | ||
metadata.boolean = "false"; | ||
metadata.undefined = "foo"; | ||
// $FlowIgnore[incompatible-type] | ||
delete metadata.null; | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
string: "bar", | ||
number: "42", | ||
boolean: "true", | ||
undefined: undefined, | ||
null: null, | ||
}); | ||
expect(result).not.toEqual(metadata); | ||
}); | ||
|
||
it("should clone arrays", () => { | ||
// Arrange | ||
const metadata = { | ||
array: [1, 2, 3], | ||
}; | ||
|
||
// Act | ||
const result = cloneMetadata(metadata); | ||
metadata.array.push(4); | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
array: [1, 2, 3], | ||
}); | ||
expect(result).not.toEqual(metadata); | ||
}); | ||
|
||
it("should clone objects", () => { | ||
// Arrange | ||
const metadata = { | ||
object: { | ||
a: 1, | ||
b: 2, | ||
}, | ||
}; | ||
|
||
// Act | ||
const result = cloneMetadata(metadata); | ||
metadata.object.a = 3; | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
object: { | ||
a: 1, | ||
b: 2, | ||
}, | ||
}); | ||
expect(result).not.toEqual(metadata); | ||
}); | ||
|
||
it("should clone nested objects and arrays", () => { | ||
// Arrange | ||
const metadata = { | ||
object: { | ||
a: 1, | ||
b: 2, | ||
c: { | ||
d: 3, | ||
e: [ | ||
4, | ||
5, | ||
{ | ||
nested: "in here", | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
// Act | ||
const result = cloneMetadata(metadata); | ||
metadata.object.c.e[2].nested = "in there"; | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
object: { | ||
a: 1, | ||
b: 2, | ||
c: { | ||
d: 3, | ||
e: [ | ||
4, | ||
5, | ||
{ | ||
nested: "in here", | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
expect(result).not.toEqual(metadata); | ||
}); | ||
}); |
Oops, something went wrong.