fix typing errors

This commit is contained in:
Sebastian Sdorra
2019-10-19 17:15:53 +02:00
parent 6e7a08a3bb
commit 5debee5b49
11 changed files with 206 additions and 1210 deletions

View File

@@ -1,14 +0,0 @@
[ignore]
.*/node_modules/module-deps/.*
# This dir is used as yarn's cache (on Jenkins) - we don't want flow checks here.
.*/.cache/.*
[include]
[libs]
[lints]
[options]
[strict]

File diff suppressed because it is too large Load Diff

View File

@@ -11,6 +11,12 @@
"dependencies": {
"react": "^16.10.2"
},
"devDependencies": {
"@types/enzyme": "^3.10.3",
"@types/jest": "^24.0.19",
"@types/react": "^16.9.9",
"typescript": "^3.6.4"
},
"babel": {
"presets": [
"@scm-manager/babel-preset"

View File

@@ -1,34 +1,36 @@
import React from 'react';
import ExtensionPoint from './ExtensionPoint';
import { shallow, mount } from 'enzyme';
import '@scm-manager/ui-tests/enzyme';
import binder from './binder';
import React from "react";
import ExtensionPoint from "./ExtensionPoint";
import { shallow, mount } from "enzyme";
import "@scm-manager/ui-tests/enzyme";
import binder from "./binder";
jest.mock('./binder');
jest.mock("./binder");
describe('ExtensionPoint test', () => {
const mockedBinder = binder as jest.Mocked<typeof binder>;
describe("ExtensionPoint test", () => {
beforeEach(() => {
binder.hasExtension.mockReset();
binder.getExtension.mockReset();
binder.getExtensions.mockReset();
mockedBinder.hasExtension.mockReset();
mockedBinder.getExtension.mockReset();
mockedBinder.getExtensions.mockReset();
});
it('should render nothing, if no extension was bound', () => {
binder.hasExtension.mockReturnValue(true);
binder.getExtensions.mockReturnValue([]);
it("should render nothing, if no extension was bound", () => {
mockedBinder.hasExtension.mockReturnValue(true);
mockedBinder.getExtensions.mockReturnValue([]);
const rendered = shallow(<ExtensionPoint name="something.special" />);
expect(rendered.text()).toBe('');
expect(rendered.text()).toBe("");
});
it('should render the given component', () => {
it("should render the given component", () => {
const label = () => {
return <label>Extension One</label>;
};
binder.hasExtension.mockReturnValue(true);
binder.getExtension.mockReturnValue(label);
mockedBinder.hasExtension.mockReturnValue(true);
mockedBinder.getExtension.mockReturnValue(label);
const rendered = mount(<ExtensionPoint name="something.special" />);
expect(rendered.text()).toBe('Extension One');
expect(rendered.text()).toBe("Extension One");
});
// We use this wrapper since Enzyme cannot handle React Fragments (see https://github.com/airbnb/enzyme/issues/1213)
@@ -37,7 +39,7 @@ describe('ExtensionPoint test', () => {
return <div>{super.render()}</div>;
}
}
it('should render the given components', () => {
it("should render the given components", () => {
const labelOne = () => {
return <label>Extension One</label>;
};
@@ -45,18 +47,18 @@ describe('ExtensionPoint test', () => {
return <label>Extension Two</label>;
};
binder.hasExtension.mockReturnValue(true);
binder.getExtensions.mockReturnValue([labelOne, labelTwo]);
mockedBinder.hasExtension.mockReturnValue(true);
mockedBinder.getExtensions.mockReturnValue([labelOne, labelTwo]);
const rendered = mount(
<ExtensionPointEnzymeFix name="something.special" renderAll={true} />,
<ExtensionPointEnzymeFix name="something.special" renderAll={true} />
);
const text = rendered.text();
expect(text).toContain('Extension One');
expect(text).toContain('Extension Two');
expect(text).toContain("Extension One");
expect(text).toContain("Extension Two");
});
it('should render the given component, with the given props', () => {
it("should render the given component, with the given props", () => {
type Props = {
value: string;
};
@@ -65,51 +67,51 @@ describe('ExtensionPoint test', () => {
return <label>{props.value}</label>;
};
binder.hasExtension.mockReturnValue(true);
binder.getExtension.mockReturnValue(label);
mockedBinder.hasExtension.mockReturnValue(true);
mockedBinder.getExtension.mockReturnValue(label);
const rendered = mount(
<ExtensionPoint
name="something.special"
props={{
value: 'Awesome',
value: "Awesome"
}}
/>,
/>
);
const text = rendered.text();
expect(text).toContain('Awesome');
expect(text).toContain("Awesome");
});
it('should render children, if no extension is bound', () => {
it("should render children, if no extension is bound", () => {
const rendered = mount(
<ExtensionPoint name="something.special">
<p>Cool stuff</p>
</ExtensionPoint>,
</ExtensionPoint>
);
const text = rendered.text();
expect(text).toContain('Cool stuff');
expect(text).toContain("Cool stuff");
});
it('should not render children, if an extension was bound', () => {
it("should not render children, if an extension was bound", () => {
const label = () => {
return <label>Bound Extension</label>;
};
binder.hasExtension.mockReturnValue(true);
binder.getExtension.mockReturnValue(label);
mockedBinder.hasExtension.mockReturnValue(true);
mockedBinder.getExtension.mockReturnValue(label);
const rendered = mount(
<ExtensionPoint name="something.special">
<p>Cool stuff</p>
</ExtensionPoint>,
</ExtensionPoint>
);
const text = rendered.text();
expect(text).toContain('Bound Extension');
expect(text).toContain("Bound Extension");
});
it('should pass the context of the parent component', () => {
it("should pass the context of the parent component", () => {
const UserContext = React.createContext({
name: 'anonymous',
name: "anonymous"
});
type HelloProps = {
@@ -128,14 +130,14 @@ describe('ExtensionPoint test', () => {
);
};
binder.hasExtension.mockReturnValue(true);
binder.getExtension.mockReturnValue(HelloUser);
mockedBinder.hasExtension.mockReturnValue(true);
mockedBinder.getExtension.mockReturnValue(HelloUser);
const App = () => {
return (
<UserContext.Provider
value={{
name: 'Trillian',
name: "Trillian"
}}
>
<ExtensionPoint name="hello" />
@@ -145,6 +147,6 @@ describe('ExtensionPoint test', () => {
const rendered = mount(<App />);
const text = rendered.text();
expect(text).toBe('Hello Trillian');
expect(text).toBe("Hello Trillian");
});
});

View File

@@ -1,11 +1,11 @@
import * as React from 'react';
import binder from './binder';
import * as React from "react";
import binder from "./binder";
type Props = {
name: string;
renderAll?: boolean;
props?: object;
children?: React.Node;
children?: React.ReactNode;
};
/**

View File

@@ -1,65 +1,69 @@
import { Binder } from './binder';
import { Binder } from "./binder";
describe('binder tests', () => {
let binder;
describe("binder tests", () => {
let binder: Binder;
beforeEach(() => {
binder = new Binder();
});
it('should return an empty array for non existing extension points', () => {
const extensions = binder.getExtensions('hitchhiker');
it("should return an empty array for non existing extension points", () => {
const extensions = binder.getExtensions("hitchhiker");
expect(extensions).toEqual([]);
});
it('should return the binded extensions', () => {
binder.bind('hitchhicker.trillian', 'heartOfGold');
binder.bind('hitchhicker.trillian', 'earth');
it("should return the binded extensions", () => {
binder.bind("hitchhicker.trillian", "heartOfGold");
binder.bind("hitchhicker.trillian", "earth");
const extensions = binder.getExtensions('hitchhicker.trillian');
expect(extensions).toEqual(['heartOfGold', 'earth']);
const extensions = binder.getExtensions("hitchhicker.trillian");
expect(extensions).toEqual(["heartOfGold", "earth"]);
});
it('should return the first bound extension', () => {
binder.bind('hitchhicker.trillian', 'heartOfGold');
binder.bind('hitchhicker.trillian', 'earth');
it("should return the first bound extension", () => {
binder.bind("hitchhicker.trillian", "heartOfGold");
binder.bind("hitchhicker.trillian", "earth");
expect(binder.getExtension('hitchhicker.trillian')).toBe('heartOfGold');
expect(binder.getExtension("hitchhicker.trillian")).toBe("heartOfGold");
});
it('should return null if no extension was bound', () => {
expect(binder.getExtension('hitchhicker.trillian')).toBe(null);
it("should return null if no extension was bound", () => {
expect(binder.getExtension("hitchhicker.trillian")).toBe(null);
});
it('should return true, if an extension is bound', () => {
binder.bind('hitchhicker.trillian', 'heartOfGold');
expect(binder.hasExtension('hitchhicker.trillian')).toBe(true);
it("should return true, if an extension is bound", () => {
binder.bind("hitchhicker.trillian", "heartOfGold");
expect(binder.hasExtension("hitchhicker.trillian")).toBe(true);
});
it('should return false, if no extension is bound', () => {
expect(binder.hasExtension('hitchhicker.trillian')).toBe(false);
it("should return false, if no extension is bound", () => {
expect(binder.hasExtension("hitchhicker.trillian")).toBe(false);
});
it('should return only extensions which predicates matches', () => {
type Props = {
category: string
};
it("should return only extensions which predicates matches", () => {
binder.bind(
'hitchhicker.trillian',
'heartOfGold',
(props: object) => props.category === 'a',
"hitchhicker.trillian",
"heartOfGold",
(props: Props) => props.category === "a"
);
binder.bind(
'hitchhicker.trillian',
'earth',
(props: object) => props.category === 'b',
"hitchhicker.trillian",
"earth",
(props: Props) => props.category === "b"
);
binder.bind(
'hitchhicker.trillian',
'earth2',
(props: object) => props.category === 'a',
"hitchhicker.trillian",
"earth2",
(props: Props) => props.category === "a"
);
const extensions = binder.getExtensions('hitchhicker.trillian', {
category: 'b',
const extensions = binder.getExtensions("hitchhicker.trillian", {
category: "b"
});
expect(extensions).toEqual(['earth']);
expect(extensions).toEqual(["earth"]);
});
});

View File

@@ -1,7 +1,7 @@
type Predicate = (props: object) => boolean;
type Predicate = (props: any) => boolean;
type ExtensionRegistration = {
predicate: (props: object) => boolean;
predicate: Predicate;
extension: any;
};

View File

@@ -1,2 +1,2 @@
export { default as binder } from './binder';
export { default as ExtensionPoint } from './ExtensionPoint';
export { default as binder } from "./binder";
export { default as ExtensionPoint } from "./ExtensionPoint";

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React from "react";
type Props = {
value: string;

View File

@@ -0,0 +1,67 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
"checkJs": true, /* Report errors in .js files. */
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"skipLibCheck": true
},
"include": [
"src/*"
]
}

View File

@@ -2563,11 +2563,26 @@
dependencies:
"@babel/types" "^7.3.0"
"@types/cheerio@*":
version "0.22.13"
resolved "https://registry.yarnpkg.com/@types/cheerio/-/cheerio-0.22.13.tgz#5eecda091a24514185dcba99eda77e62bf6523e6"
integrity sha512-OZd7dCUOUkiTorf97vJKwZnSja/DmHfuBAroe1kREZZTCf/tlFecwHhsOos3uVHxeKGZDwzolIrCUApClkdLuA==
dependencies:
"@types/node" "*"
"@types/diff@^4.0.1":
version "4.0.2"
resolved "https://registry.yarnpkg.com/@types/diff/-/diff-4.0.2.tgz#2e9bb89f9acc3ab0108f0f3dc4dbdcf2fff8a99c"
integrity sha512-mIenTfsIe586/yzsyfql69KRnA75S8SVXQbTLpDejRrjH0QSJcpu3AUOi/Vjnt9IOsXKxPhJfGpQUNMueIU1fQ==
"@types/enzyme@^3.10.3":
version "3.10.3"
resolved "https://registry.yarnpkg.com/@types/enzyme/-/enzyme-3.10.3.tgz#02b6c5ac7d0472005944a652e79045e2f6c66804"
integrity sha512-f/Kcb84sZOSZiBPCkr4He9/cpuSLcKRyQaEE20Q30Prx0Dn6wcyMAWI0yofL6yvd9Ht9G7EVkQeRqK0n5w8ILw==
dependencies:
"@types/cheerio" "*"
"@types/react" "*"
"@types/events@*":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
@@ -2612,6 +2627,18 @@
"@types/istanbul-lib-coverage" "*"
"@types/istanbul-lib-report" "*"
"@types/jest-diff@*":
version "20.0.1"
resolved "https://registry.yarnpkg.com/@types/jest-diff/-/jest-diff-20.0.1.tgz#35cc15b9c4f30a18ef21852e255fdb02f6d59b89"
integrity sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA==
"@types/jest@^24.0.19":
version "24.0.19"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.19.tgz#f7036058d2a5844fe922609187c0ad8be430aff5"
integrity sha512-YYiqfSjocv7lk5H/T+v5MjATYjaTMsUkbDnjGqSMoO88jWdtJXJV4ST/7DKZcoMHMBvB2SeSfyOzZfkxXHR5xg==
dependencies:
"@types/jest-diff" "*"
"@types/lodash.merge@^4.6.4":
version "4.6.6"
resolved "https://registry.yarnpkg.com/@types/lodash.merge/-/lodash.merge-4.6.6.tgz#b84b403c1d31bc42d51772d1cd5557fa008cd3d6"
@@ -2677,6 +2704,14 @@
"@types/prop-types" "*"
csstype "^2.2.0"
"@types/react@^16.9.9":
version "16.9.9"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.9.tgz#a62c6f40f04bc7681be5e20975503a64fe783c3a"
integrity sha512-L+AudFJkDukk+ukInYvpoAPyJK5q1GanFOINOJnM0w6tUgITuWvJ4jyoBPFL7z4/L8hGLd+K/6xR5uUjXu0vVg==
dependencies:
"@types/prop-types" "*"
csstype "^2.2.0"
"@types/stack-utils@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
@@ -3366,11 +3401,6 @@ babel-code-frame@^6.22.0:
esutils "^2.0.2"
js-tokens "^3.0.2"
babel-core@7.0.0-bridge.0:
version "7.0.0-bridge.0"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
integrity sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==
babel-eslint@^10.0.3:
version "10.0.3"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.0.3.tgz#81a2c669be0f205e19462fed2482d33e4687a88a"
@@ -6948,7 +6978,7 @@ gitconfiglocal@^1.0.0:
dependencies:
ini "^1.3.2"
gitdiff-parser@^0.1.2, "gitdiff-parser@https://github.com/scm-manager/gitdiff-parser#6baa7278824ecd17a199d842ca720d0453f68982":
gitdiff-parser@^0.1.2:
version "0.1.2"
resolved "https://github.com/scm-manager/gitdiff-parser#6baa7278824ecd17a199d842ca720d0453f68982"
@@ -13575,6 +13605,11 @@ typescript@^3.4:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.3.tgz#fea942fabb20f7e1ca7164ff626f1a9f3f70b4da"
integrity sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==
typescript@^3.6.4:
version "3.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d"
integrity sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==
ua-parser-js@^0.7.18:
version "0.7.20"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.20.tgz#7527178b82f6a62a0f243d1f94fd30e3e3c21098"