-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#9430: extracting first util lib #9491
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,7 @@ describe("DataPanel state", () => { | |
|
||
describe("Add/Remove Bricks", () => { | ||
let editor: EditorState; | ||
let consoleErrorSpy: jest.SpyInstance; | ||
|
||
const source = formStateFactory({ | ||
formStateConfig: { | ||
|
@@ -155,6 +156,12 @@ describe("Add/Remove Bricks", () => { | |
initialState, | ||
actions.addModComponentFormState(source), | ||
); | ||
|
||
consoleErrorSpy = jest.spyOn(console, "error").mockImplementation(); | ||
}); | ||
|
||
afterEach(() => { | ||
consoleErrorSpy.mockRestore(); | ||
}); | ||
|
||
test("Add Brick", async () => { | ||
|
@@ -178,6 +185,42 @@ describe("Add/Remove Bricks", () => { | |
).toBeArrayOfSize(initialBricks.length + 1); | ||
}); | ||
|
||
test("Add Brick - bad pipeline path error", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this test just to ensure there was no regression with this existing debug util code. |
||
// Add a Brick | ||
expect(() => | ||
editorSlice.reducer( | ||
editor, | ||
actions.addNode({ | ||
block: standardBrick, | ||
pipelinePath: "badPath.to.modComponent", | ||
pipelineIndex: 0, | ||
}), | ||
), | ||
).toThrowError( | ||
"Invalid pipeline path for mod component form state: badPath.to.modComponent", | ||
); | ||
|
||
expect(consoleErrorSpy).toHaveBeenCalledWith( | ||
"Invalid pipeline path for mod component form state: %s", | ||
"badPath.to.modComponent", | ||
{ | ||
block: { | ||
config: {}, | ||
id: "test/teapot", | ||
instanceId: "00000001-0000-4000-A000-000000000000", | ||
outputKey: "teapotOutput", | ||
}, | ||
element: expect.any(Object), | ||
invalidPath: { | ||
invalidPath: "badPath", | ||
values: expect.any(Object), | ||
}, | ||
pipelineIndex: 0, | ||
pipelinePath: "badPath.to.modComponent", | ||
}, | ||
); | ||
}); | ||
|
||
test("Remove Brick with Integration Dependency", async () => { | ||
// Get initial bricks and integration dependencies | ||
const initialBricks = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2024 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
const config = { | ||
silent: true, | ||
modulePaths: ["/src"], | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx"], | ||
transform: { | ||
"\\.[jt]sx?$": "@swc/jest", | ||
}, | ||
moduleNameMapper: { | ||
"^@/(.*)$": "<rootDir>/src/$1", | ||
}, | ||
}; | ||
|
||
module.exports = config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "@pixiebrix/utils", | ||
"version": "1.0.0", | ||
"description": "PixieBrix Utility Library", | ||
"scripts": { | ||
"test": "TZ=UTC jest", | ||
"lint": "echo 'missing eslint'", | ||
"build": "echo 'buildless package'", | ||
"build:typecheck": "tsc --noEmit" | ||
}, | ||
"license": "AGPL-3.0", | ||
"repository": "https://github.com/pixiebrix/pixiebrix-extension", | ||
"dependencies": { | ||
"formik": "^2.4.6" | ||
}, | ||
"devDependencies": { | ||
"@swc/core": "^1.7.42", | ||
"@swc/jest": "^0.2.37", | ||
"eslint": "^8.57.0", | ||
"typescript": "^5.6.3" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ type InvalidPathInformation = { | |
* @param path period separated path | ||
*/ | ||
export function getInvalidPath( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: as an aside, given this method uses Formik's getIn vs. lodash's (I'm not sure if there are any differences?) we might consider moving it to a formikDebugUtils module or similar in the future Or, if there are no differences in getIn implementation, we might consider dropping the Formik dependency from this library in favor of lodash |
||
value: UnknownObject, | ||
value: Record<string, unknown>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UnknownObject comes from a global type def, which we might eventually want to move to the root as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might also consider using typefest's UnknownRecord instead: https://github.com/sindresorhus/type-fest/blob/main/source/unknown-record.d.ts. There's is maybe technically more accurate — ours only supports string keys vs. strings/symbols/numbers: https://www.totaltypescript.com/concepts/propertykey-type Although, ours is helpful for distinguishing against mistaken Array uses |
||
path: string, | ||
): InvalidPathInformation { | ||
const parts = path.split("."); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
// You can see the full details at https://github.com/sindresorhus/tsconfig/blob/main/tsconfig.json | ||
// Note: `strict: true` enables many flags that aren’t explicitly listed in that file | ||
"extends": "@sindresorhus/tsconfig", | ||
"compilerOptions": { | ||
"sourceMap": true, | ||
"module": "esnext", | ||
"target": "es2023", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we consider defining a config these can extend from? E.g., in some libraries we might be able to enforce stricter rules (e.g., Update: I see you already mentioned the duplication in the PR description There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think we should define a base tsconfig. That's the follow-up I mentioned in the PR description |
||
"moduleResolution": "bundler", | ||
"resolveJsonModule": true, | ||
"baseUrl": ".", | ||
"outDir": null, | ||
"declaration": false, | ||
|
||
// TODO: Drop these lines to make TS stricter https://github.com/pixiebrix/pixiebrix-extension/issues/775 | ||
"strictFunctionTypes": false, | ||
"noPropertyAccessFromIndexSignature": false, | ||
"noImplicitReturns": false, | ||
"noUnusedParameters": false, | ||
"paths": { | ||
"@/*": ["src/*"] | ||
} | ||
}, | ||
"exclude": ["node_modules"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to the root package.json