Unverified Commit 7451869c authored by Sebastian Malton's avatar Sebastian Malton Committed by GitHub
Browse files

add no-unused and react/recommended to eslint (#1523)


* add no-unused-vars and no-unused-imports

* added quotes: double, and remove ignore pattern

* move itif and describeif into utils
Signed-off-by: default avatarSebastian Malton <sebastian@malton.name>
parent 10eb0828
Showing with 239 additions and 189 deletions
+239 -189
const packageJson = require("./package.json");
module.exports = {
ignorePatterns: [
"**/node_modules/**/*",
"**/dist/**/*",
],
settings: {
react: {
version: packageJson.devDependencies.react || "detect",
}
},
overrides: [
{
files: [
"src/renderer/**/*.js",
"build/**/*.js",
"extensions/**/*.js"
"**/*.js"
],
extends: [
'eslint:recommended',
"eslint:recommended",
],
env: {
node: true
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
sourceType: "module",
},
plugins: [
"unused-imports"
],
rules: {
"indent": ["error", 2, {
"SwitchCase": 1,
}],
"no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"warn", {
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": true,
}
],
"quotes": ["error", "double", {
"avoidEscape": true,
"allowTemplateLiterals": true,
}],
"semi": ["error", "always"],
"object-shorthand": "error",
}
},
{
files: [
"build/*.ts",
"src/**/*.ts",
"integration/**/*.ts",
"src/extensions/**/*.ts*",
"extensions/**/*.ts*",
"__mocks__/*.ts",
"**/*.ts",
],
parser: "@typescript-eslint/parser",
extends: [
'plugin:@typescript-eslint/recommended',
"plugin:@typescript-eslint/recommended",
],
plugins: [
"unused-imports"
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
sourceType: "module",
},
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports-ts": "error",
"unused-imports/no-unused-vars-ts": [
"warn", {
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": true,
}
],
"indent": ["error", 2, {
"SwitchCase": 1,
}],
"quotes": ["error", "double", {
"avoidEscape": true,
"allowTemplateLiterals": true,
}],
"semi": "off",
"@typescript-eslint/semi": ["error"],
"object-shorthand": "error",
......@@ -64,21 +94,24 @@ module.exports = {
},
{
files: [
"src/renderer/**/*.tsx",
"**/*.tsx",
],
parser: "@typescript-eslint/parser",
plugins: [
"unused-imports"
],
extends: [
'plugin:@typescript-eslint/recommended',
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
sourceType: "module",
jsx: true,
},
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-empty-interface": "off",
......@@ -87,9 +120,23 @@ module.exports = {
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-empty-function": "off",
"react/display-name": "off",
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports-ts": "error",
"unused-imports/no-unused-vars-ts": [
"warn", {
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": true,
}
],
"indent": ["error", 2, {
"SwitchCase": 1,
}],
"quotes": ["error", "double", {
"avoidEscape": true,
"allowTemplateLiterals": true,
}],
"semi": "off",
"@typescript-eslint/semi": ["error"],
"object-shorthand": "error",
......
......@@ -4,9 +4,7 @@ module.exports = {
app: {
getVersion: jest.fn().mockReturnValue("3.0.0"),
getLocale: jest.fn().mockRejectedValue("en"),
getPath: jest.fn((name: string) => {
return "tmp";
}),
getPath: jest.fn(() => "tmp"),
},
remote: {
app: {
......
......@@ -92,12 +92,12 @@ class KubectlDownloader {
}
const downloadVersion = packageInfo.config.bundledKubectlVersion;
const baseDir = path.join(process.env.INIT_CWD, 'binaries', 'client');
const baseDir = path.join(process.env.INIT_CWD, "binaries", "client");
const downloads = [
{ platform: 'linux', arch: 'amd64', target: path.join(baseDir, 'linux', 'x64', 'kubectl') },
{ platform: 'darwin', arch: 'amd64', target: path.join(baseDir, 'darwin', 'x64', 'kubectl') },
{ platform: 'windows', arch: 'amd64', target: path.join(baseDir, 'windows', 'x64', 'kubectl.exe') },
{ platform: 'windows', arch: '386', target: path.join(baseDir, 'windows', 'ia32', 'kubectl.exe') }
{ platform: "linux", arch: "amd64", target: path.join(baseDir, "linux", "x64", "kubectl") },
{ platform: "darwin", arch: "amd64", target: path.join(baseDir, "darwin", "x64", "kubectl") },
{ platform: "windows", arch: "amd64", target: path.join(baseDir, "windows", "x64", "kubectl.exe") },
{ platform: "windows", arch: "386", target: path.join(baseDir, "windows", "ia32", "kubectl.exe") }
];
downloads.forEach((dlOpts) => {
......
const { notarize } = require('electron-notarize');
const { notarize } = require("electron-notarize");
exports.default = async function notarizing(context) {
const { electronPlatformName, appOutDir } = context;
if (electronPlatformName !== 'darwin') {
if (electronPlatformName !== "darwin") {
return;
}
if (!process.env.APPLEID || !process.env.APPLEIDPASS) {
......@@ -12,7 +12,7 @@ exports.default = async function notarizing(context) {
const appName = context.packager.appInfo.productFilename;
return await notarize({
appBundleId: 'io.kontena.lens-app',
appBundleId: "io.kontena.lens-app",
appPath: `${appOutDir}/${appName}.app`,
appleId: process.env.APPLEID,
appleIdPassword: process.env.APPLEIDPASS,
......
......@@ -2,10 +2,10 @@ import { LensMainExtension } from "@k8slens/extensions";
export default class ExampleExtensionMain extends LensMainExtension {
onActivate() {
console.log('EXAMPLE EXTENSION MAIN: ACTIVATED', this.name, this.id);
console.log("EXAMPLE EXTENSION MAIN: ACTIVATED", this.name, this.id);
}
onDeactivate() {
console.log('EXAMPLE EXTENSION MAIN: DEACTIVATED', this.name, this.id);
console.log("EXAMPLE EXTENSION MAIN: DEACTIVATED", this.name, this.id);
}
}
const path = require('path');
const path = require("path");
module.exports = [
{
entry: './main.ts',
entry: "./main.ts",
context: __dirname,
target: "electron-main",
mode: "production",
......@@ -10,7 +10,7 @@ module.exports = [
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
use: "ts-loader",
exclude: /node_modules/,
},
],
......@@ -23,16 +23,16 @@ module.exports = [
}
],
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
extensions: [ ".tsx", ".ts", ".js" ],
},
output: {
libraryTarget: "commonjs2",
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
},
{
entry: './renderer.tsx',
entry: "./renderer.tsx",
context: __dirname,
target: "electron-renderer",
mode: "production",
......@@ -40,7 +40,7 @@ module.exports = [
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
use: "ts-loader",
exclude: /node_modules/,
},
],
......@@ -53,13 +53,13 @@ module.exports = [
}
],
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
extensions: [ ".tsx", ".ts", ".js" ],
},
output: {
libraryTarget: "commonjs2",
globalObject: "this",
filename: 'renderer.js',
path: path.resolve(__dirname, 'dist'),
filename: "renderer.js",
path: path.resolve(__dirname, "dist"),
},
},
];
const path = require('path');
const path = require("path");
module.exports = [
{
entry: './renderer.tsx',
entry: "./renderer.tsx",
context: __dirname,
target: "electron-renderer",
mode: "production",
......@@ -10,7 +10,7 @@ module.exports = [
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
use: "ts-loader",
exclude: /node_modules/,
},
],
......@@ -23,13 +23,13 @@ module.exports = [
}
],
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
extensions: [ ".tsx", ".ts", ".js" ],
},
output: {
libraryTarget: "commonjs2",
globalObject: "this",
filename: 'renderer.js',
path: path.resolve(__dirname, 'dist'),
filename: "renderer.js",
path: path.resolve(__dirname, "dist"),
},
},
];
import path from "path";
const outputPath = path.resolve(__dirname, 'dist');
const outputPath = path.resolve(__dirname, "dist");
export default [
{
entry: './main.ts',
entry: "./main.ts",
context: __dirname,
target: "electron-main",
mode: "production",
......@@ -12,7 +12,7 @@ export default [
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
use: "ts-loader",
exclude: /node_modules/,
},
],
......@@ -22,12 +22,12 @@ export default [
"mobx": "var global.Mobx",
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
extensions: [".tsx", ".ts", ".js"],
},
output: {
libraryTarget: "commonjs2",
globalObject: "this",
filename: 'main.js',
filename: "main.js",
path: outputPath,
},
},
......
......@@ -7,15 +7,13 @@ export default class ClusterMetricsFeatureExtension extends LensRendererExtensio
{
title: "Metrics Stack",
components: {
Description: () => {
return (
<span>
Enable timeseries data visualization (Prometheus stack) for your cluster.
Install this only if you don't have existing Prometheus stack installed.
You can see preview of manifests <a href="https://github.com/lensapp/lens/tree/master/extensions/lens-metrics/resources" target="_blank">here</a>.
</span>
);
}
Description: () => (
<span>
Enable timeseries data visualization (Prometheus stack) for your cluster.
Install this only if you don&apos;t have existing Prometheus stack installed.
You can see preview of manifests <a href="https://github.com/lensapp/lens/tree/master/extensions/lens-metrics/resources" rel="noreferrer" target="_blank">here</a>.
</span>
)
},
feature: new MetricsFeature()
}
......
......@@ -54,8 +54,8 @@ export class MetricsFeature extends ClusterFeature.Feature {
const storageClassApi = K8sApi.forCluster(cluster, K8sApi.StorageClass);
const scs = await storageClassApi.list();
this.templateContext.persistence.enabled = scs.some(sc => (
sc.metadata?.annotations?.['storageclass.kubernetes.io/is-default-class'] === 'true' ||
sc.metadata?.annotations?.['storageclass.beta.kubernetes.io/is-default-class'] === 'true'
sc.metadata?.annotations?.["storageclass.kubernetes.io/is-default-class"] === "true" ||
sc.metadata?.annotations?.["storageclass.beta.kubernetes.io/is-default-class"] === "true"
));
super.applyResources(cluster, path.join(__dirname, "../resources/"));
......
const path = require('path');
const path = require("path");
module.exports = [
{
entry: './renderer.tsx',
entry: "./renderer.tsx",
context: __dirname,
target: "electron-renderer",
mode: "production",
......@@ -10,7 +10,7 @@ module.exports = [
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
use: "ts-loader",
exclude: /node_modules/,
},
],
......@@ -23,13 +23,13 @@ module.exports = [
}
],
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
extensions: [ ".tsx", ".ts", ".js" ],
},
output: {
libraryTarget: "commonjs2",
globalObject: "this",
filename: 'renderer.js',
path: path.resolve(__dirname, 'dist'),
filename: "renderer.js",
path: path.resolve(__dirname, "dist"),
},
node: {
__dirname: false
......
const path = require('path');
const path = require("path");
module.exports = [
{
entry: './renderer.tsx',
entry: "./renderer.tsx",
context: __dirname,
target: "electron-renderer",
mode: "production",
......@@ -10,7 +10,7 @@ module.exports = [
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
use: "ts-loader",
exclude: /node_modules/,
},
],
......@@ -23,13 +23,13 @@ module.exports = [
}
],
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
extensions: [ ".tsx", ".ts", ".js" ],
},
output: {
libraryTarget: "commonjs2",
globalObject: "this",
filename: 'renderer.js',
path: path.resolve(__dirname, 'dist'),
filename: "renderer.js",
path: path.resolve(__dirname, "dist"),
},
},
];
const path = require('path');
const path = require("path");
module.exports = [
{
entry: './renderer.tsx',
entry: "./renderer.tsx",
context: __dirname,
target: "electron-renderer",
mode: "production",
......@@ -10,7 +10,7 @@ module.exports = [
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
use: "ts-loader",
exclude: /node_modules/,
},
],
......@@ -23,13 +23,13 @@ module.exports = [
}
],
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
extensions: [ ".tsx", ".ts", ".js" ],
},
output: {
libraryTarget: "commonjs2",
globalObject: "this",
filename: 'renderer.js',
path: path.resolve(__dirname, 'dist'),
filename: "renderer.js",
path: path.resolve(__dirname, "dist"),
},
},
];
const path = require('path');
const path = require("path");
module.exports = [
{
entry: './main.ts',
entry: "./main.ts",
context: __dirname,
target: "electron-main",
mode: "production",
......@@ -10,7 +10,7 @@ module.exports = [
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
use: "ts-loader",
exclude: /node_modules/,
},
],
......@@ -23,17 +23,17 @@ module.exports = [
}
],
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
extensions: [ ".tsx", ".ts", ".js" ],
},
output: {
libraryTarget: "commonjs2",
globalObject: "this",
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
},
{
entry: './renderer.tsx',
entry: "./renderer.tsx",
context: __dirname,
target: "electron-renderer",
mode: "production",
......@@ -41,7 +41,7 @@ module.exports = [
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
use: "ts-loader",
exclude: /node_modules/,
},
],
......@@ -55,13 +55,13 @@ module.exports = [
}
],
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
extensions: [ ".tsx", ".ts", ".js" ],
},
output: {
libraryTarget: "commonjs2",
globalObject: "this",
filename: 'renderer.js',
path: path.resolve(__dirname, 'dist'),
filename: "renderer.js",
path: path.resolve(__dirname, "dist"),
},
},
];
......@@ -8,9 +8,6 @@ import { Application } from "spectron";
import * as util from "../helpers/utils";
import { spawnSync } from "child_process";
const describeif = (condition: boolean) => condition ? describe : describe.skip;
const itif = (condition: boolean) => condition ? it : it.skip;
jest.setTimeout(60000);
// FIXME (!): improve / simplify all css-selectors + use [data-test-id="some-id"] (already used in some tests below)
......@@ -82,18 +79,18 @@ describe("Lens integration tests", () => {
});
it('shows "add cluster"', async () => {
await app.electron.ipcRenderer.send('test-menu-item-click', "File", "Add Cluster");
await app.electron.ipcRenderer.send("test-menu-item-click", "File", "Add Cluster");
await app.client.waitUntilTextExists("h2", "Add Cluster");
});
describe("preferences page", () => {
it('shows "preferences"', async () => {
const appName: string = process.platform === "darwin" ? "Lens" : "File";
await app.electron.ipcRenderer.send('test-menu-item-click', appName, "Preferences");
await app.electron.ipcRenderer.send("test-menu-item-click", appName, "Preferences");
await app.client.waitUntilTextExists("h2", "Preferences");
});
it('ensures helm repos', async () => {
it("ensures helm repos", async () => {
await app.client.waitUntilTextExists("div.repos #message-bitnami", "bitnami"); // wait for the helm-cli to fetch the bitnami repo
await app.client.click("#HelmRepoSelect"); // click the repo select to activate the drop-down
await app.client.waitUntilTextExists("div.Select__option", ""); // wait for at least one option to appear (any text)
......@@ -101,12 +98,12 @@ describe("Lens integration tests", () => {
});
it.skip('quits Lens"', async () => {
await app.client.keys(['Meta', 'Q']);
await app.client.keys('Meta');
await app.client.keys(["Meta", "Q"]);
await app.client.keys("Meta");
});
});
describeif(ready)("workspaces", () => {
util.describeIf(ready)("workspaces", () => {
beforeAll(appStart, 20000);
afterAll(async () => {
......@@ -115,27 +112,27 @@ describe("Lens integration tests", () => {
}
});
it('creates new workspace', async () => {
it("creates new workspace", async () => {
await clickWhatsNew(app);
await app.client.click('#current-workspace .Icon');
await app.client.click("#current-workspace .Icon");
await app.client.click('a[href="/workspaces"]');
await app.client.click('.Workspaces button.Button');
await app.client.click(".Workspaces button.Button");
await app.client.keys("test-workspace");
await app.client.click('.Workspaces .Input.description input');
await app.client.click(".Workspaces .Input.description input");
await app.client.keys("test description");
await app.client.click('.Workspaces .workspace.editing .Icon');
await app.client.click(".Workspaces .workspace.editing .Icon");
await app.client.waitUntilTextExists(".workspace .name a", "test-workspace");
});
it('adds cluster in default workspace', async () => {
it("adds cluster in default workspace", async () => {
await addMinikubeCluster(app);
await app.client.waitUntilTextExists("pre.kube-auth-out", "Authentication proxy started");
await app.client.waitForExist(`iframe[name="minikube"]`);
await app.client.waitForVisible(".ClustersMenu .ClusterIcon.active");
});
it('adds cluster in test-workspace', async () => {
await app.client.click('#current-workspace .Icon');
it("adds cluster in test-workspace", async () => {
await app.client.click("#current-workspace .Icon");
await app.client.waitForVisible('.WorkspaceMenu li[title="test description"]');
await app.client.click('.WorkspaceMenu li[title="test description"]');
await addMinikubeCluster(app);
......@@ -143,10 +140,10 @@ describe("Lens integration tests", () => {
await app.client.waitForExist(`iframe[name="minikube"]`);
});
it('checks if default workspace has active cluster', async () => {
await app.client.click('#current-workspace .Icon');
await app.client.waitForVisible('.WorkspaceMenu > li:first-of-type');
await app.client.click('.WorkspaceMenu > li:first-of-type');
it("checks if default workspace has active cluster", async () => {
await app.client.click("#current-workspace .Icon");
await app.client.waitForVisible(".WorkspaceMenu > li:first-of-type");
await app.client.click(".WorkspaceMenu > li:first-of-type");
await app.client.waitForVisible(".ClustersMenu .ClusterIcon.active");
});
});
......@@ -170,7 +167,7 @@ describe("Lens integration tests", () => {
await app.client.waitUntilTextExists("span.link-text", "Cluster");
};
describeif(ready)("cluster tests", () => {
util.describeIf(ready)("cluster tests", () => {
let clusterAdded = false;
const addCluster = async () => {
......@@ -190,7 +187,7 @@ describe("Lens integration tests", () => {
}
});
it('allows to add a cluster', async () => {
it("allows to add a cluster", async () => {
await addCluster();
clusterAdded = true;
});
......@@ -515,7 +512,7 @@ describe("Lens integration tests", () => {
}
});
it('shows default namespace', async () => {
it("shows default namespace", async () => {
expect(clusterAdded).toBe(true);
await app.client.click('a[href="/namespaces"]');
await app.client.waitUntilTextExists("div.TableCell", "default");
......@@ -539,7 +536,7 @@ describe("Lens integration tests", () => {
await app.client.waitUntilTextExists('a[href^="/pods"]', "Pods");
await app.client.click('a[href^="/pods"]');
await app.client.waitUntilTextExists("div.TableCell", "kube-apiserver");
await app.client.click('.Icon.new-dock-tab');
await app.client.click(".Icon.new-dock-tab");
await app.client.waitUntilTextExists("li.MenuItem.create-resource-tab", "Create resource");
await app.client.click("li.MenuItem.create-resource-tab");
await app.client.waitForVisible(".CreateResource div.ace_content");
......
......@@ -6,6 +6,14 @@ const AppPaths: Partial<Record<NodeJS.Platform, string>> = {
"darwin": "./dist/mac/Lens.app/Contents/MacOS/Lens",
};
export function itIf(condition: boolean) {
return condition ? it : it.skip;
}
export function describeIf(condition: boolean) {
return condition ? describe : describe.skip;
}
export function setup(): Application {
return new Application({
path: AppPaths[process.platform], // path to electron app
......
......@@ -13,8 +13,8 @@ describe("empty config", () => {
beforeEach(() => {
ClusterStore.resetInstance();
const mockOpts = {
'tmp': {
'lens-cluster-store.json': JSON.stringify({})
"tmp": {
"lens-cluster-store.json": JSON.stringify({})
}
};
mockFs(mockOpts);
......@@ -144,8 +144,8 @@ describe("config with existing clusters", () => {
beforeEach(() => {
ClusterStore.resetInstance();
const mockOpts = {
'tmp': {
'lens-cluster-store.json': JSON.stringify({
"tmp": {
"lens-cluster-store.json": JSON.stringify({
__internal__: {
migrations: {
version: "99.99.99"
......@@ -153,24 +153,24 @@ describe("config with existing clusters", () => {
},
clusters: [
{
id: 'cluster1',
kubeConfig: 'foo',
contextName: 'foo',
preferences: { terminalCWD: '/foo' },
workspace: 'default'
id: "cluster1",
kubeConfig: "foo",
contextName: "foo",
preferences: { terminalCWD: "/foo" },
workspace: "default"
},
{
id: 'cluster2',
kubeConfig: 'foo2',
contextName: 'foo2',
preferences: { terminalCWD: '/foo2' }
id: "cluster2",
kubeConfig: "foo2",
contextName: "foo2",
preferences: { terminalCWD: "/foo2" }
},
{
id: 'cluster3',
kubeConfig: 'foo',
contextName: 'foo',
preferences: { terminalCWD: '/foo' },
workspace: 'foo'
id: "cluster3",
kubeConfig: "foo",
contextName: "foo",
preferences: { terminalCWD: "/foo" },
workspace: "foo"
},
]
})
......@@ -186,27 +186,27 @@ describe("config with existing clusters", () => {
});
it("allows to retrieve a cluster", () => {
const storedCluster = clusterStore.getById('cluster1');
expect(storedCluster.id).toBe('cluster1');
expect(storedCluster.preferences.terminalCWD).toBe('/foo');
const storedCluster = clusterStore.getById("cluster1");
expect(storedCluster.id).toBe("cluster1");
expect(storedCluster.preferences.terminalCWD).toBe("/foo");
});
it("allows to delete a cluster", () => {
clusterStore.removeById('cluster2');
const storedCluster = clusterStore.getById('cluster1');
clusterStore.removeById("cluster2");
const storedCluster = clusterStore.getById("cluster1");
expect(storedCluster).toBeTruthy();
const storedCluster2 = clusterStore.getById('cluster2');
const storedCluster2 = clusterStore.getById("cluster2");
expect(storedCluster2).toBeUndefined();
});
it("allows getting all of the clusters", async () => {
const storedClusters = clusterStore.clustersList;
expect(storedClusters.length).toBe(3);
expect(storedClusters[0].id).toBe('cluster1');
expect(storedClusters[0].preferences.terminalCWD).toBe('/foo');
expect(storedClusters[1].id).toBe('cluster2');
expect(storedClusters[1].preferences.terminalCWD).toBe('/foo2');
expect(storedClusters[2].id).toBe('cluster3');
expect(storedClusters[0].id).toBe("cluster1");
expect(storedClusters[0].preferences.terminalCWD).toBe("/foo");
expect(storedClusters[1].id).toBe("cluster2");
expect(storedClusters[1].preferences.terminalCWD).toBe("/foo2");
expect(storedClusters[2].id).toBe("cluster3");
});
});
......@@ -214,14 +214,14 @@ describe("pre 2.0 config with an existing cluster", () => {
beforeEach(() => {
ClusterStore.resetInstance();
const mockOpts = {
'tmp': {
'lens-cluster-store.json': JSON.stringify({
"tmp": {
"lens-cluster-store.json": JSON.stringify({
__internal__: {
migrations: {
version: "1.0.0"
}
},
cluster1: 'kubeconfig content'
cluster1: "kubeconfig content"
})
}
};
......@@ -244,8 +244,8 @@ describe("pre 2.6.0 config with a cluster that has arrays in auth config", () =>
beforeEach(() => {
ClusterStore.resetInstance();
const mockOpts = {
'tmp': {
'lens-cluster-store.json': JSON.stringify({
"tmp": {
"lens-cluster-store.json": JSON.stringify({
__internal__: {
migrations: {
version: "2.4.1"
......@@ -270,8 +270,8 @@ describe("pre 2.6.0 config with a cluster that has arrays in auth config", () =>
const file = clusterStore.clustersList[0].kubeConfigPath;
const config = fs.readFileSync(file, "utf8");
const kc = yaml.safeLoad(config);
expect(kc.users[0].user['auth-provider'].config['access-token']).toBe("should be string");
expect(kc.users[0].user['auth-provider'].config['expiry']).toBe("should be string");
expect(kc.users[0].user["auth-provider"].config["access-token"]).toBe("should be string");
expect(kc.users[0].user["auth-provider"].config["expiry"]).toBe("should be string");
});
});
......@@ -279,8 +279,8 @@ describe("pre 2.6.0 config with a cluster icon", () => {
beforeEach(() => {
ClusterStore.resetInstance();
const mockOpts = {
'tmp': {
'lens-cluster-store.json': JSON.stringify({
"tmp": {
"lens-cluster-store.json": JSON.stringify({
__internal__: {
migrations: {
version: "2.4.1"
......@@ -308,8 +308,8 @@ describe("pre 2.6.0 config with a cluster icon", () => {
it("moves the icon into preferences", async () => {
const storedClusterData = clusterStore.clustersList[0];
expect(storedClusterData.hasOwnProperty('icon')).toBe(false);
expect(storedClusterData.preferences.hasOwnProperty('icon')).toBe(true);
expect(storedClusterData.hasOwnProperty("icon")).toBe(false);
expect(storedClusterData.preferences.hasOwnProperty("icon")).toBe(true);
expect(storedClusterData.preferences.icon.startsWith("data:;base64,")).toBe(true);
});
});
......@@ -318,8 +318,8 @@ describe("for a pre 2.7.0-beta.0 config without a workspace", () => {
beforeEach(() => {
ClusterStore.resetInstance();
const mockOpts = {
'tmp': {
'lens-cluster-store.json': JSON.stringify({
"tmp": {
"lens-cluster-store.json": JSON.stringify({
__internal__: {
migrations: {
version: "2.6.6"
......@@ -345,7 +345,7 @@ describe("for a pre 2.7.0-beta.0 config without a workspace", () => {
it("adds cluster to default workspace", async () => {
const storedClusterData = clusterStore.clustersList[0];
expect(storedClusterData.workspace).toBe('default');
expect(storedClusterData.workspace).toBe("default");
});
});
......@@ -353,8 +353,8 @@ describe("pre 3.6.0-beta.1 config with an existing cluster", () => {
beforeEach(() => {
ClusterStore.resetInstance();
const mockOpts = {
'tmp': {
'lens-cluster-store.json': JSON.stringify({
"tmp": {
"lens-cluster-store.json": JSON.stringify({
__internal__: {
migrations: {
version: "3.5.0"
......@@ -362,9 +362,9 @@ describe("pre 3.6.0-beta.1 config with an existing cluster", () => {
},
clusters: [
{
id: 'cluster1',
kubeConfig: 'kubeconfig content',
contextName: 'cluster',
id: "cluster1",
kubeConfig: "kubeconfig content",
contextName: "cluster",
preferences: {
icon: "store://icon_path",
}
......
......@@ -3,9 +3,9 @@ import mockFs from "mock-fs";
jest.mock("electron", () => {
return {
app: {
getVersion: () => '99.99.99',
getPath: () => 'tmp',
getLocale: () => 'en'
getVersion: () => "99.99.99",
getPath: () => "tmp",
getLocale: () => "en"
}
};
});
......@@ -18,7 +18,7 @@ describe("user store tests", () => {
describe("for an empty config", () => {
beforeEach(() => {
UserStore.resetInstance();
mockFs({ tmp: { 'config.json': "{}" } });
mockFs({ tmp: { "config.json": "{}" } });
});
afterEach(() => {
......@@ -35,26 +35,26 @@ describe("user store tests", () => {
it("allows adding and listing seen contexts", () => {
const us = UserStore.getInstance<UserStore>();
us.seenContexts.add('foo');
us.seenContexts.add("foo");
expect(us.seenContexts.size).toBe(1);
us.seenContexts.add('foo');
us.seenContexts.add('bar');
us.seenContexts.add("foo");
us.seenContexts.add("bar");
expect(us.seenContexts.size).toBe(2); // check 'foo' isn't added twice
expect(us.seenContexts.has('foo')).toBe(true);
expect(us.seenContexts.has('bar')).toBe(true);
expect(us.seenContexts.has("foo")).toBe(true);
expect(us.seenContexts.has("bar")).toBe(true);
});
it("allows setting and getting preferences", () => {
const us = UserStore.getInstance<UserStore>();
us.preferences.httpsProxy = 'abcd://defg';
us.preferences.httpsProxy = "abcd://defg";
expect(us.preferences.httpsProxy).toBe('abcd://defg');
expect(us.preferences.httpsProxy).toBe("abcd://defg");
expect(us.preferences.colorTheme).toBe(UserStore.defaultTheme);
us.preferences.colorTheme = "light";
expect(us.preferences.colorTheme).toBe('light');
expect(us.preferences.colorTheme).toBe("light");
});
it("correctly resets theme to default value", async () => {
......@@ -80,11 +80,11 @@ describe("user store tests", () => {
beforeEach(() => {
UserStore.resetInstance();
mockFs({
'tmp': {
'config.json': JSON.stringify({
user: { username: 'foobar' },
preferences: { colorTheme: 'light' },
lastSeenAppVersion: '1.2.3'
"tmp": {
"config.json": JSON.stringify({
user: { username: "foobar" },
preferences: { colorTheme: "light" },
lastSeenAppVersion: "1.2.3"
})
}
});
......@@ -97,7 +97,7 @@ describe("user store tests", () => {
it("sets last seen app version to 0.0.0", () => {
const us = UserStore.getInstance<UserStore>();
expect(us.lastSeenAppVersion).toBe('0.0.0');
expect(us.lastSeenAppVersion).toBe("0.0.0");
});
});
});
\ No newline at end of file
......@@ -3,9 +3,9 @@ import mockFs from "mock-fs";
jest.mock("electron", () => {
return {
app: {
getVersion: () => '99.99.99',
getPath: () => 'tmp',
getLocale: () => 'en'
getVersion: () => "99.99.99",
getPath: () => "tmp",
getLocale: () => "en"
}
};
});
......@@ -16,7 +16,7 @@ describe("workspace store tests", () => {
describe("for an empty config", () => {
beforeEach(async () => {
WorkspaceStore.resetInstance();
mockFs({ tmp: { 'lens-workspace-store.json': "{}" } });
mockFs({ tmp: { "lens-workspace-store.json": "{}" } });
await WorkspaceStore.getInstance<WorkspaceStore>().load();
});
......@@ -146,7 +146,7 @@ describe("workspace store tests", () => {
WorkspaceStore.resetInstance();
mockFs({
tmp: {
'lens-workspace-store.json': JSON.stringify({
"lens-workspace-store.json": JSON.stringify({
currentWorkspace: "abc",
workspaces: [{
id: "abc",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment