mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Fix lint for non @k8slens/core packages
- Update eslint config to be tighter in control Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
fcef072859
commit
6184c2f03b
29 files changed
+291
-292
No files matched your search
+25
-37
@@ -17,6 +17,7 @@ import {
|
||||
ComputedChannelAdminMessage,
|
||||
} from "./computed-channel-administration-channel.injectable";
|
||||
import { computedChannelFeature } from "../feature";
|
||||
import type { RenderResult } from "@testing-library/react";
|
||||
|
||||
const testChannel: MessageChannel<string> = { id: "some-channel-id" };
|
||||
const testChannel2: MessageChannel<string> = { id: "some-other-channel-id" };
|
||||
@@ -110,7 +111,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
});
|
||||
|
||||
describe("when observing the computed value in a component in di-1", () => {
|
||||
let rendered: any;
|
||||
let rendered: RenderResult;
|
||||
|
||||
beforeEach(() => {
|
||||
const render = renderFor(di2);
|
||||
@@ -118,13 +119,10 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
rendered = render(<TestComponent someComputed={computedTestChannel} />);
|
||||
});
|
||||
|
||||
const scenarioName = scenarioIsAsync ? "when all messages are propagated" : "immediately";
|
||||
|
||||
// eslint-disable-next-line jest/valid-title
|
||||
describe(scenarioName, () => {
|
||||
describe(scenarioIsAsync ? "when all messages are propagated" : "immediately", () => {
|
||||
beforeEach((done) => {
|
||||
if (scenarioIsAsync) {
|
||||
messageBridgeFake.messagePropagationRecursive(act).then(done);
|
||||
void messageBridgeFake.messagePropagationRecursive(act).then(done);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
@@ -155,15 +153,13 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
);
|
||||
});
|
||||
|
||||
scenarioIsAsync &&
|
||||
if (scenarioIsAsync) {
|
||||
it("computed test channel value is observed as the pending value", () => {
|
||||
expect(observedValue).toBe("some-pending-value");
|
||||
});
|
||||
}
|
||||
|
||||
const scenarioName = scenarioIsAsync ? "when admin messages are propagated" : "immediately";
|
||||
|
||||
// eslint-disable-next-line jest/valid-title
|
||||
describe(scenarioName, () => {
|
||||
describe(scenarioIsAsync ? "when admin messages are propagated" : "immediately", () => {
|
||||
beforeEach((done) => {
|
||||
if (scenarioIsAsync) {
|
||||
void messageBridgeFake.messagePropagation().then(done);
|
||||
@@ -179,10 +175,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
});
|
||||
});
|
||||
|
||||
const scenarioName = scenarioIsAsync ? "when returning value-messages propagate" : "immediately";
|
||||
|
||||
// eslint-disable-next-line jest/valid-title
|
||||
describe(scenarioName, () => {
|
||||
describe(scenarioIsAsync ? "when returning value-messages propagate" : "immediately", () => {
|
||||
beforeEach((done) => {
|
||||
if (scenarioIsAsync) {
|
||||
void messageBridgeFake.messagePropagation().then(done);
|
||||
@@ -208,10 +201,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
});
|
||||
});
|
||||
|
||||
const scenarioName = scenarioIsAsync ? "when value-messages propagate" : "immediately";
|
||||
|
||||
// eslint-disable-next-line jest/valid-title
|
||||
describe(scenarioName, () => {
|
||||
describe(scenarioIsAsync ? "when value-messages propagate" : "immediately", () => {
|
||||
beforeEach((done) => {
|
||||
if (scenarioIsAsync) {
|
||||
void messageBridgeFake.messagePropagation().then(done);
|
||||
@@ -237,10 +227,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
stopObserving();
|
||||
});
|
||||
|
||||
const scenarioName = scenarioIsAsync ? "when admin-messages propagate" : "immediately";
|
||||
|
||||
// eslint-disable-next-line jest/valid-title
|
||||
describe(scenarioName, () => {
|
||||
describe(scenarioIsAsync ? "when admin-messages propagate" : "immediately", () => {
|
||||
beforeEach((done) => {
|
||||
if (scenarioIsAsync) {
|
||||
void messageBridgeFake.messagePropagation().then(done);
|
||||
@@ -289,15 +276,13 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
);
|
||||
});
|
||||
|
||||
scenarioIsAsync &&
|
||||
if (scenarioIsAsync) {
|
||||
it("computed test channel value is observed as the pending value again", () => {
|
||||
expect(observedValue).toBe("some-pending-value");
|
||||
});
|
||||
}
|
||||
|
||||
const scenarioName = scenarioIsAsync ? "when admin messages propagate" : "immediately";
|
||||
|
||||
// eslint-disable-next-line jest/valid-title
|
||||
describe(scenarioName, () => {
|
||||
describe(scenarioIsAsync ? "when admin messages propagate" : "immediately", () => {
|
||||
beforeEach((done) => {
|
||||
if (scenarioIsAsync) {
|
||||
latestAdminMessage = undefined;
|
||||
@@ -315,14 +300,14 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
});
|
||||
});
|
||||
|
||||
scenarioIsAsync &&
|
||||
if (scenarioIsAsync) {
|
||||
it("computed test channel value is still observed as the pending value", () => {
|
||||
expect(observedValue).toBe("some-pending-value");
|
||||
});
|
||||
}
|
||||
|
||||
const scenarioTitle = scenarioIsAsync ? "when value-messages propagate back" : "immediately";
|
||||
|
||||
// eslint-disable-next-line jest/valid-title
|
||||
describe(scenarioTitle, () => {
|
||||
beforeEach((done) => {
|
||||
if (scenarioIsAsync) {
|
||||
@@ -381,17 +366,23 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
},
|
||||
);
|
||||
|
||||
scenarioIsAsync && (await messageBridgeFake.messagePropagation());
|
||||
if (scenarioIsAsync) {
|
||||
await messageBridgeFake.messagePropagation();
|
||||
}
|
||||
|
||||
stopObserving();
|
||||
|
||||
scenarioIsAsync && (await messageBridgeFake.messagePropagation());
|
||||
if (scenarioIsAsync) {
|
||||
await messageBridgeFake.messagePropagation();
|
||||
}
|
||||
|
||||
runInAction(() => {
|
||||
someOtherObservable.set("some-value");
|
||||
});
|
||||
|
||||
scenarioIsAsync && (await messageBridgeFake.messagePropagation());
|
||||
if (scenarioIsAsync) {
|
||||
await messageBridgeFake.messagePropagation();
|
||||
}
|
||||
|
||||
expect(observedValue).toBe("some-value");
|
||||
});
|
||||
@@ -439,10 +430,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
expect(nonReactiveValue).toBe("some-initial-value");
|
||||
});
|
||||
|
||||
const scenarioName = scenarioIsAsync ? "when messages would be propagated" : "immediately";
|
||||
|
||||
// eslint-disable-next-line jest/valid-title
|
||||
describe(scenarioName, () => {
|
||||
describe(scenarioIsAsync ? "when messages would be propagated" : "immediately", () => {
|
||||
beforeEach((done) => {
|
||||
if (scenarioIsAsync) {
|
||||
void messageBridgeFake.messagePropagation().then(done);
|
||||
|
||||
+24
-28
@@ -1,42 +1,38 @@
|
||||
import { onLoadOfApplicationInjectionToken } from "@k8slens/application";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { iter } from "@k8slens/utilities";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { filter, groupBy, nth, map, toPairs } from "lodash/fp";
|
||||
import { reaction } from "mobx";
|
||||
import { computedChannelObserverInjectionToken } from "./computed-channel.injectable";
|
||||
|
||||
export const duplicateChannelObserverGuardInjectable = getInjectable({
|
||||
id: "duplicate-channel-observer-guard",
|
||||
|
||||
instantiate: (di) => {
|
||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||
const computedObservers = computedInjectMany(computedChannelObserverInjectionToken);
|
||||
|
||||
return {
|
||||
run: () => {
|
||||
reaction(
|
||||
() => computedInjectMany(computedChannelObserverInjectionToken).get(),
|
||||
(observers) => {
|
||||
const duplicateObserverChannelIds = pipeline(
|
||||
observers,
|
||||
groupBy((observer) => observer.channel.id),
|
||||
toPairs,
|
||||
filter(([, channelObservers]) => channelObservers.length > 1),
|
||||
map(nth(0)),
|
||||
);
|
||||
reaction(
|
||||
() => computedObservers.get(),
|
||||
(observers) => {
|
||||
const observersByChannelId = iter
|
||||
.chain(observers.values())
|
||||
.map((observer) => [observer.channel.id, observer] as const)
|
||||
.groupIntoMap();
|
||||
const duplicateIds = iter
|
||||
.chain(observersByChannelId.entries())
|
||||
.filter(([, channelObservers]) => channelObservers.length > 1)
|
||||
.map(([id]) => id)
|
||||
.toArray();
|
||||
|
||||
if (duplicateObserverChannelIds.length) {
|
||||
throw new Error(
|
||||
`Tried to register duplicate channel observer for channels "${duplicateObserverChannelIds.join(
|
||||
'", "',
|
||||
)}"`,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
};
|
||||
},
|
||||
if (duplicateIds.length) {
|
||||
throw new Error(`Tried to register duplicate channel observer for channels "${duplicateIds.join('", "')}"`);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
});
|
||||
Reference in new issue
Block a user