Remove babel-plugin-rewire (#3522)

This commit is contained in:
Louis Lam 2023-08-04 01:10:15 +08:00 committed by GitHub
parent f4967615c0
commit d231a05526
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 21 deletions

View file

@ -4,8 +4,4 @@ if (process.env.TEST_FRONTEND) {
config.presets = [ "@babel/preset-env" ]; config.presets = [ "@babel/preset-env" ];
} }
if (process.env.TEST_BACKEND) {
config.plugins = [ "babel-plugin-rewire" ];
}
module.exports = config; module.exports = config;

7
package-lock.json generated
View file

@ -90,7 +90,6 @@
"@vue/compiler-sfc": "~3.3.4", "@vue/compiler-sfc": "~3.3.4",
"@vuepic/vue-datepicker": "~3.4.8", "@vuepic/vue-datepicker": "~3.4.8",
"aedes": "^0.46.3", "aedes": "^0.46.3",
"babel-plugin-rewire": "~1.2.0",
"bootstrap": "5.1.3", "bootstrap": "5.1.3",
"chart.js": "~4.2.1", "chart.js": "~4.2.1",
"chartjs-adapter-dayjs-4": "~1.0.4", "chartjs-adapter-dayjs-4": "~1.0.4",
@ -6623,12 +6622,6 @@
"@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0"
} }
}, },
"node_modules/babel-plugin-rewire": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/babel-plugin-rewire/-/babel-plugin-rewire-1.2.0.tgz",
"integrity": "sha512-JBZxczHw3tScS+djy6JPLMjblchGhLI89ep15H3SyjujIzlxo5nr6Yjo7AXotdeVczeBmWs0tF8PgJWDdgzAkQ==",
"dev": true
},
"node_modules/babel-preset-current-node-syntax": { "node_modules/babel-preset-current-node-syntax": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz", "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz",

View file

@ -153,7 +153,6 @@
"@vue/compiler-sfc": "~3.3.4", "@vue/compiler-sfc": "~3.3.4",
"@vuepic/vue-datepicker": "~3.4.8", "@vuepic/vue-datepicker": "~3.4.8",
"aedes": "^0.46.3", "aedes": "^0.46.3",
"babel-plugin-rewire": "~1.2.0",
"bootstrap": "5.1.3", "bootstrap": "5.1.3",
"chart.js": "~4.2.1", "chart.js": "~4.2.1",
"chartjs-adapter-dayjs-4": "~1.0.4", "chartjs-adapter-dayjs-4": "~1.0.4",

View file

@ -1047,3 +1047,13 @@ module.exports.grpcQuery = async (options) => {
}); });
}; };
// For unit test, export functions
if (process.env.TEST_BACKEND) {
module.exports.__test = {
parseCertificateInfo,
};
module.exports.__getPrivateFunction = (functionName) => {
return module.exports.__test[functionName];
};
}

View file

@ -1,5 +1,5 @@
const { genSecret, DOWN, log} = require("../src/util"); const { genSecret, DOWN, log} = require("../src/util");
const utilServerRewire = require("../server/util-server"); const utilServer = require("../server/util-server");
const Discord = require("../server/notification-providers/discord"); const Discord = require("../server/notification-providers/discord");
const axios = require("axios"); const axios = require("axios");
const { UptimeKumaServer } = require("../server/uptime-kuma-server"); const { UptimeKumaServer } = require("../server/uptime-kuma-server");
@ -14,13 +14,13 @@ jest.mock("axios");
describe("Test parseCertificateInfo", () => { describe("Test parseCertificateInfo", () => {
it("should handle undefined", async () => { it("should handle undefined", async () => {
const parseCertificateInfo = utilServerRewire.__get__("parseCertificateInfo"); const parseCertificateInfo = utilServer.__getPrivateFunction("parseCertificateInfo");
const info = parseCertificateInfo(undefined); const info = parseCertificateInfo(undefined);
expect(info).toEqual(undefined); expect(info).toEqual(undefined);
}, 5000); }, 5000);
it("should handle normal cert chain", async () => { it("should handle normal cert chain", async () => {
const parseCertificateInfo = utilServerRewire.__get__("parseCertificateInfo"); const parseCertificateInfo = utilServer.__getPrivateFunction("parseCertificateInfo");
const chain1 = { const chain1 = {
fingerprint: "CF:2C:F3:6A:FE:6B:10:EC:44:77:C8:95:BB:96:2E:06:1F:0E:15:DA", fingerprint: "CF:2C:F3:6A:FE:6B:10:EC:44:77:C8:95:BB:96:2E:06:1F:0E:15:DA",
@ -52,7 +52,7 @@ describe("Test parseCertificateInfo", () => {
}, 5000); }, 5000);
it("should handle cert chain with strange circle", async () => { it("should handle cert chain with strange circle", async () => {
const parseCertificateInfo = utilServerRewire.__get__("parseCertificateInfo"); const parseCertificateInfo = utilServer.__getPrivateFunction("parseCertificateInfo");
const chain1 = { const chain1 = {
fingerprint: "CF:2C:F3:6A:FE:6B:10:EC:44:77:C8:95:BB:96:2E:06:1F:0E:15:DA", fingerprint: "CF:2C:F3:6A:FE:6B:10:EC:44:77:C8:95:BB:96:2E:06:1F:0E:15:DA",
@ -92,7 +92,7 @@ describe("Test parseCertificateInfo", () => {
}, 5000); }, 5000);
it("should handle cert chain with last undefined (should be happen in real, but just in case)", async () => { it("should handle cert chain with last undefined (should be happen in real, but just in case)", async () => {
const parseCertificateInfo = utilServerRewire.__get__("parseCertificateInfo"); const parseCertificateInfo = utilServer.__getPrivateFunction("parseCertificateInfo");
const chain1 = { const chain1 = {
fingerprint: "CF:2C:F3:6A:FE:6B:10:EC:44:77:C8:95:BB:96:2E:06:1F:0E:15:DA", fingerprint: "CF:2C:F3:6A:FE:6B:10:EC:44:77:C8:95:BB:96:2E:06:1F:0E:15:DA",
@ -213,22 +213,22 @@ describe("Test Discord Notification Provider", () => {
describe("The function filterAndJoin", () => { describe("The function filterAndJoin", () => {
it("should join and array of strings to one string", () => { it("should join and array of strings to one string", () => {
const result = utilServerRewire.filterAndJoin([ "one", "two", "three" ]); const result = utilServer.filterAndJoin([ "one", "two", "three" ]);
expect(result).toBe("onetwothree"); expect(result).toBe("onetwothree");
}); });
it("should join strings using a given connector", () => { it("should join strings using a given connector", () => {
const result = utilServerRewire.filterAndJoin([ "one", "two", "three" ], "-"); const result = utilServer.filterAndJoin([ "one", "two", "three" ], "-");
expect(result).toBe("one-two-three"); expect(result).toBe("one-two-three");
}); });
it("should filter null, undefined and empty strings before joining", () => { it("should filter null, undefined and empty strings before joining", () => {
const result = utilServerRewire.filterAndJoin([ undefined, "", "three" ], "--"); const result = utilServer.filterAndJoin([ undefined, "", "three" ], "--");
expect(result).toBe("three"); expect(result).toBe("three");
}); });
it("should return an empty string if all parts are filtered out", () => { it("should return an empty string if all parts are filtered out", () => {
const result = utilServerRewire.filterAndJoin([ undefined, "", "" ], "--"); const result = utilServer.filterAndJoin([ undefined, "", "" ], "--");
expect(result).toBe(""); expect(result).toBe("");
}); });
}); });