From 4352cb923d70ddb7ff31463994a3e1d0e74eb3ef Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Mon, 23 May 2022 14:40:37 +1000 Subject: [PATCH] Replace karma-env-preproc with webpack --- karma.conf.cjs | 10 ++++++++-- package-lock.json | 13 ------------- package.json | 1 - src/lib/discovery/dns.spec.ts | 9 +-------- src/lib/discovery/index.spec.ts | 9 +-------- src/lib/waku.spec.ts | 9 +-------- 6 files changed, 11 insertions(+), 40 deletions(-) diff --git a/karma.conf.cjs b/karma.conf.cjs index 16ff72e5a1..2852c6faca 100644 --- a/karma.conf.cjs +++ b/karma.conf.cjs @@ -1,12 +1,13 @@ process.env.CHROME_BIN = require("puppeteer").executablePath(); const webpackConfig = require("./webpack.config.cjs"); +const webpack = require("webpack"); module.exports = function (config) { config.set({ frameworks: ["webpack", "mocha"], files: ["src/lib/**/!(node).spec.ts"], preprocessors: { - "src/lib/**/!(node).spec.ts": ["env", "webpack"], + "src/lib/**/!(node).spec.ts": ["webpack"], }, envPreprocessor: ["CI"], reporters: ["progress"], @@ -20,7 +21,12 @@ module.exports = function (config) { webpack: { mode: "production", module: webpackConfig.module, - plugins: webpackConfig.plugins, + plugins: [ + new webpack.DefinePlugin({ + "process.env.CI": process.env.CI || false, + }), + ...webpackConfig.plugins, + ], resolve: webpackConfig.resolve, stats: { warnings: false }, }, diff --git a/package-lock.json b/package-lock.json index a18bf3706d..a141a03f2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -67,7 +67,6 @@ "jsdom-global": "^3.0.2", "karma": "^6.3.12", "karma-chrome-launcher": "^3.1.0", - "karma-env-preprocessor": "^0.1.1", "karma-mocha": "^2.0.1", "karma-webpack": "^5.0.0", "lint-staged": "^12.3.4", @@ -6883,12 +6882,6 @@ "which": "bin/which" } }, - "node_modules/karma-env-preprocessor": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/karma-env-preprocessor/-/karma-env-preprocessor-0.1.1.tgz", - "integrity": "sha1-u+jIfVnADtt2BwvTwxtLOdXcfhU=", - "dev": true - }, "node_modules/karma-mocha": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/karma-mocha/-/karma-mocha-2.0.1.tgz", @@ -17155,12 +17148,6 @@ } } }, - "karma-env-preprocessor": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/karma-env-preprocessor/-/karma-env-preprocessor-0.1.1.tgz", - "integrity": "sha1-u+jIfVnADtt2BwvTwxtLOdXcfhU=", - "dev": true - }, "karma-mocha": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/karma-mocha/-/karma-mocha-2.0.1.tgz", diff --git a/package.json b/package.json index 5a03ffe4c1..2024e7446f 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,6 @@ "jsdom-global": "^3.0.2", "karma": "^6.3.12", "karma-chrome-launcher": "^3.1.0", - "karma-env-preprocessor": "^0.1.1", "karma-mocha": "^2.0.1", "karma-webpack": "^5.0.0", "lint-staged": "^12.3.4", diff --git a/src/lib/discovery/dns.spec.ts b/src/lib/discovery/dns.spec.ts index a6d2de5aee..2db676f514 100644 --- a/src/lib/discovery/dns.spec.ts +++ b/src/lib/discovery/dns.spec.ts @@ -3,13 +3,6 @@ import { expect } from "chai"; import { DnsClient, DnsNodeDiscovery } from "./dns"; import testData from "./testdata.json"; -declare global { - interface Window { - __env__?: any; - } -} -declare let window: Window | undefined; - const mockData = testData.dns; const host = "nodes.example.org"; @@ -273,7 +266,7 @@ describe("DNS Node Discovery [live data]", function () { const maxQuantity = 3; before(function () { - if (process.env.CI || window?.__env__?.CI) { + if (process.env.CI) { this.skip(); } }); diff --git a/src/lib/discovery/index.spec.ts b/src/lib/discovery/index.spec.ts index a0ee745f2b..f68126a033 100644 --- a/src/lib/discovery/index.spec.ts +++ b/src/lib/discovery/index.spec.ts @@ -3,13 +3,6 @@ import { expect } from "chai"; import { fleets } from "./predefined"; import { getPseudoRandomSubset } from "./random_subset"; -declare global { - interface Window { - __env__?: any; - } -} -declare let window: Window | undefined; - describe("Discovery", () => { it("returns all values when wanted number matches available values", function () { const values = ["a", "b", "c"]; @@ -44,7 +37,7 @@ describe("Discovery", () => { describe("Discovery [live data]", function () { before(function () { - if (process.env.CI || window?.__env__?.CI) { + if (process.env.CI) { this.skip(); } }); diff --git a/src/lib/waku.spec.ts b/src/lib/waku.spec.ts index 77e9c21915..e72bb9db66 100644 --- a/src/lib/waku.spec.ts +++ b/src/lib/waku.spec.ts @@ -3,13 +3,6 @@ import PeerId from "peer-id"; import { Waku } from "./waku"; -declare global { - interface Window { - __env__?: any; - } -} -declare let window: Window | undefined; - describe("Waku Dial", function () { describe("Bootstrap [live data]", function () { let waku: Waku; @@ -19,7 +12,7 @@ describe("Waku Dial", function () { }); before(function () { - if (process.env.CI || window?.__env__?.CI) { + if (process.env.CI) { this.skip(); } });