fix: skip redefining global __static in tests

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2020-08-14 12:42:50 +03:00
1 parent 165788da2d
commit da96776b73
2 files changed
+15 -3

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
// Setup variable in global scope (top-level object)
// Global type definition must be added separately to `mocks.d.ts` in form:
// declare const __globalName: any;
export function defineGlobal(propName: string, descriptor: PropertyDescriptor) {
const scope = typeof global !== "undefined" ? global : window;
if (scope.hasOwnProperty(propName)) {
console.info(`Global variable "${propName}" already exists. Skipping.`)
return;
}
Object.defineProperty(scope, propName, descriptor);
}
+3 -3
View File
@@ -1,6 +1,7 @@
// App's common configuration for any process (main, renderer, build pipeline, etc.) // App's common configuration for any process (main, renderer, build pipeline, etc.)
import packageInfo from "../../package.json"
import path from "path"; import path from "path";
import packageInfo from "../../package.json"
import { defineGlobal } from "./utils/defineGlobal";
export const isMac = process.platform === "darwin" export const isMac = process.platform === "darwin"
export const isWindows = process.platform === "win32" export const isWindows = process.platform === "win32"
@@ -21,8 +22,7 @@ export const htmlTemplate = path.resolve(rendererDir, "template.html");
export const sassCommonVars = path.resolve(rendererDir, "components/vars.scss"); export const sassCommonVars = path.resolve(rendererDir, "components/vars.scss");
// Special runtime paths // Special runtime paths
const globScope = typeof global !== "undefined" ? global : window; defineGlobal("__static", {
Object.defineProperty(globScope, "__static", {
get() { get() {
if (isDevelopment) { if (isDevelopment) {
return path.resolve(contextDir, "static"); return path.resolve(contextDir, "static");