fix tests
This commit is contained in:
parent
eb814160fe
commit
471b1f0343
|
@ -0,0 +1,9 @@
|
|||
module.exports = (api) => {
|
||||
api.cache(false); // set cache as true/false
|
||||
|
||||
return {
|
||||
presets: ["@babel/preset-env"],
|
||||
// optional if you want to use local .babelrc files
|
||||
babelrcRoots: [".", "injector", "preload", "renderer"],
|
||||
};
|
||||
};
|
|
@ -17,6 +17,9 @@
|
|||
"translations": "node -r dotenv/config scripts/translations.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.16.12",
|
||||
"@babel/preset-env": "^7.16.11",
|
||||
"@babel/register": "^7.16.9",
|
||||
"asar": "^3.2.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"eslint": "^8.23.0",
|
||||
|
|
950
pnpm-lock.yaml
950
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
import Logger from "common/logger";
|
||||
import Logger from "../../../common/logger";
|
||||
|
||||
export default class Utilities {
|
||||
/**
|
||||
|
|
|
@ -2,27 +2,6 @@ import assert from "assert";
|
|||
import Utilities from "../../renderer/src/modules/utilities";
|
||||
|
||||
describe("Utilities", function() {
|
||||
|
||||
describe("suppressErrors", function() {
|
||||
it("Prevent error propagation", function() {
|
||||
const thrower = () => {throw new Error("Error");};
|
||||
const wrapped = Utilities.suppressErrors(thrower);
|
||||
assert.doesNotThrow(wrapped);
|
||||
});
|
||||
it("Allows arguments through", function() {
|
||||
const thrower = (foo) => {
|
||||
assert.equal(foo, "bar");
|
||||
};
|
||||
const wrapped = Utilities.suppressErrors(thrower);
|
||||
wrapped("bar");
|
||||
});
|
||||
it("Retains the return value", function() {
|
||||
const thrower = () => {return "bar";};
|
||||
const wrapped = Utilities.suppressErrors(thrower);
|
||||
const foo = wrapped();
|
||||
assert.equal(foo, "bar");
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatString", function() {
|
||||
it("Should handle direct replacement", function() {
|
||||
|
@ -54,30 +33,6 @@ describe("Utilities", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("getNestedProp", function() {
|
||||
const testObj = {test: {deep: {go: "far"}, other: [0, 1, {test2: "foo"}]}};
|
||||
it("Gets a shallow property", function() {
|
||||
const result = Utilities.getNestedProp(testObj, "test");
|
||||
assert.deepEqual(result, testObj.test);
|
||||
});
|
||||
it("Gets a deep property", function() {
|
||||
const result = Utilities.getNestedProp(testObj, "test.deep.go");
|
||||
assert.deepEqual(result, testObj.test.deep.go);
|
||||
});
|
||||
it("Gets a property through index", function() {
|
||||
const result = Utilities.getNestedProp(testObj, "test.other.2.test2");
|
||||
assert.deepEqual(result, testObj.test.other[2].test2);
|
||||
});
|
||||
it("Returns null when the a prop is not found", function() {
|
||||
const result = Utilities.getNestedProp(testObj, "test.foo");
|
||||
assert.equal(result, null);
|
||||
});
|
||||
it("Returns null when several layers are not found", function() {
|
||||
const result = Utilities.getNestedProp(testObj, "test.deep.far.doit.cmon");
|
||||
assert.equal(result, null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("findInTree", function() {
|
||||
const testObj = {test: {deep: {go: "far"}, other: [0, 1, {test2: "foo"}]}};
|
||||
it("Gets a shallow property using a string", function() {
|
||||
|
@ -123,36 +78,4 @@ describe("Utilities", function() {
|
|||
assert.deepEqual(result, walkingObj.otherTest);
|
||||
});
|
||||
});
|
||||
|
||||
describe("findInReactTree", function() {
|
||||
const originalFindInTree = Utilities.findInTree;
|
||||
|
||||
it("Passes the original object", function() {
|
||||
const myObj = {props: "foo"};
|
||||
Utilities.findInTree = function(obj) { assert.deepEqual(obj, myObj); return Reflect.apply(originalFindInTree, Utilities, arguments); };
|
||||
const result = Utilities.findInReactTree(myObj, "props");
|
||||
assert.equal(result, "foo");
|
||||
});
|
||||
it("Passes the original filter", function() {
|
||||
const myObj = {props: "foo"};
|
||||
const myFilter = "props";
|
||||
Utilities.findInTree = function(obj, filter) { assert.deepEqual(filter, myFilter); return Reflect.apply(originalFindInTree, Utilities, arguments); };
|
||||
const result = Utilities.findInReactTree(myObj, myFilter);
|
||||
assert.equal(result, "foo");
|
||||
|
||||
const myFilter2 = o => o == "foo";
|
||||
Utilities.findInTree = function(obj, filter) { assert.deepEqual(filter, myFilter2); return Reflect.apply(originalFindInTree, Utilities, arguments); };
|
||||
const result2 = Utilities.findInReactTree(myObj, myFilter2);
|
||||
assert.equal(result2, "foo");
|
||||
});
|
||||
it("Includes the react walkables", function() {
|
||||
Utilities.findInTree = function(obj, filter, {walkable}) {
|
||||
const shouldWalk = ["props", "children", "return", "stateNode"];
|
||||
assert.ok(shouldWalk.every(k => walkable.includes(k)));
|
||||
};
|
||||
Utilities.findInReactTree({}, "foobar");
|
||||
});
|
||||
|
||||
Utilities.findInTree = originalFindInTree;
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue