From 23d4eb77b2217aa9325a29a09518cc40fb95e313 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Wed, 20 Feb 2019 20:13:27 +0200 Subject: [PATCH] Fix test mode --- client/webpack.config.js | 2 +- core/src/main.js | 23 +++++++++++++++++++++-- package-lock.json | 3 +++ package.json | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/client/webpack.config.js b/client/webpack.config.js index 22a09c73..8f856b63 100644 --- a/client/webpack.config.js +++ b/client/webpack.config.js @@ -39,7 +39,7 @@ module.exports = { process: 'require("process")', net: 'require("net")', request: 'require(require("path").join(require("electron").remote.app.getAppPath(), "node_modules", "request"))', - sparkplug: 'require("../core/sparkplug")', + sparkplug: 'require("../../core/dist/sparkplug")', 'node-crypto': 'require("crypto")' }, resolve: { diff --git a/core/src/main.js b/core/src/main.js index 853cbecb..29494434 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -8,7 +8,23 @@ * LICENSE file in the root directory of this source tree. */ -const tests = typeof PRODUCTION === 'undefined'; +const TESTS = typeof PRODUCTION === 'undefined'; +const TEST_ARGS = () => { + const _basePath = path.resolve(__dirname, '..', '..'); + const _baseDataPath = path.resolve(_basePath, 'tests'); + return { + 'options': { + 'autoInject': true, + 'commonCore': true, + 'commonData': true + }, + 'paths': { + 'client': path.resolve(_basePath, 'client', 'dist'), + 'core': path.resolve(_basePath, 'core', 'dist'), + 'data': path.resolve(_baseDataPath, 'data') + } + } +} import path from 'path'; import sass from 'node-sass'; @@ -135,6 +151,7 @@ export class BetterDiscord { get window() { return this.windowUtils ? this.windowUtils.window : undefined; } constructor(args) { + if (TESTS) args = TEST_ARGS(); console.log('[BetterDiscord|args] ', JSON.stringify(args, null, 4)); if (BetterDiscord.loaded) { console.log('[BetterDiscord] Creating two BetterDiscord objects???'); @@ -216,7 +233,9 @@ export class BetterDiscord { */ parseClientPackage() { const clientPath = this.config.getPath('client'); - const { version, main } = require(`${clientPath}/package.json`); + const clientPkg = TESTS ? require(`${path.resolve(clientPath, '..')}/package.json`) :require(`${clientPath}/package.json`); + const { version } = clientPkg; + const main = TESTS ? 'betterdiscord.client.js' : clientPkg.main; this.config.addPath('client_script', `${clientPath}/${main}`); this.config.setClientVersion(version); console.log(`[BetterDiscord] Client v${this.config.clientVersion} - ${this.config.getPath('client_script')}`); diff --git a/package-lock.json b/package-lock.json index 55e4a8dd..1a770741 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2828,6 +2828,9 @@ "randomfill": "1.0.4" } }, + "csp-parse": { + "version": "github:macropodhq/csp-parse#db7d5f954b420b527d7fb452a93bb6e2fa302c5a" + }, "css-color-names": { "version": "0.0.4", "resolved": "https://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz", diff --git a/package.json b/package.json index abfa9633..e51201f7 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,6 @@ "release": "npm run lint && npm run build_release && gulp release && npm run package_release", "update_release": "npm run build_release && gulp build-release", "inject": "node scripts/inject.js", - "tt": "npm run release --prefix client" + "tt": "npm run build --prefix core" } }