avoid overriding config.js when running tests (#3205)

solves #3201
This commit is contained in:
Karsten Hassel 2023-09-22 14:45:46 +02:00 committed by GitHub
parent a67a0b677c
commit 95ec3096e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 30 additions and 8 deletions

View File

@ -50,6 +50,7 @@ _This release is scheduled to be released on 2023-10-01._
- Respect width/height (no fullscreen) if set in electronOptions (together with `fullscreen: false`) in `config.js` (#3174) - Respect width/height (no fullscreen) if set in electronOptions (together with `fullscreen: false`) in `config.js` (#3174)
- Fix: AnimateCSS merge hide() and show() animated css class when we do multiple call - Fix: AnimateCSS merge hide() and show() animated css class when we do multiple call
- Fix `Uncaught SyntaxError: Identifier 'getCorsUrl' has already been declared (at utils.js:1:1)` when using `clock` and `weather` module (#3204) - Fix `Uncaught SyntaxError: Identifier 'getCorsUrl' has already been declared (at utils.js:1:1)` when using `clock` and `weather` module (#3204)
- Fix overriding `config.js` when running tests (#3201)
## [2.24.0] - 2023-07-01 ## [2.24.0] - 2023-07-01

View File

@ -13,7 +13,6 @@ exports.getText = async (element, result) => {
}; };
exports.startApp = async (configFileName, additionalMockData) => { exports.startApp = async (configFileName, additionalMockData) => {
injectMockData(configFileName, additionalMockData); await helpers.startApplication(injectMockData(configFileName, additionalMockData));
await helpers.startApplication("");
await helpers.getDocument(); await helpers.getDocument();
}; };

View File

@ -1,9 +1,11 @@
const helpers = require("../helpers/global-setup"); const helpers = require("../helpers/global-setup");
const weatherFunc = require("../helpers/weather-functions"); const weatherFunc = require("../helpers/weather-functions");
const { cleanupMockData } = require("../../utils/weather_mocker");
describe("Weather module", () => { describe("Weather module", () => {
afterAll(async () => { afterAll(async () => {
await helpers.stopApplication(); await helpers.stopApplication();
await cleanupMockData();
}); });
describe("Current weather", () => { describe("Current weather", () => {

View File

@ -1,9 +1,11 @@
const helpers = require("../helpers/global-setup"); const helpers = require("../helpers/global-setup");
const weatherFunc = require("../helpers/weather-functions"); const weatherFunc = require("../helpers/weather-functions");
const { cleanupMockData } = require("../../utils/weather_mocker");
describe("Weather module: Weather Forecast", () => { describe("Weather module: Weather Forecast", () => {
afterAll(async () => { afterAll(async () => {
await helpers.stopApplication(); await helpers.stopApplication();
await cleanupMockData();
}); });
describe("Default configuration", () => { describe("Default configuration", () => {

View File

@ -1,9 +1,11 @@
const helpers = require("../helpers/global-setup"); const helpers = require("../helpers/global-setup");
const weatherFunc = require("../helpers/weather-functions"); const weatherFunc = require("../helpers/weather-functions");
const { cleanupMockData } = require("../../utils/weather_mocker");
describe("Weather module: Weather Hourly Forecast", () => { describe("Weather module: Weather Hourly Forecast", () => {
afterAll(async () => { afterAll(async () => {
await helpers.stopApplication(); await helpers.stopApplication();
await cleanupMockData();
}); });
describe("Default configuration", () => { describe("Default configuration", () => {

View File

@ -1,3 +1,4 @@
const fs = require("fs");
const helpers = require("./helpers/global-setup"); const helpers = require("./helpers/global-setup");
describe("templated config with port variable", () => { describe("templated config with port variable", () => {
@ -6,6 +7,11 @@ describe("templated config with port variable", () => {
}); });
afterAll(async () => { afterAll(async () => {
await helpers.stopApplication(); await helpers.stopApplication();
try {
fs.unlinkSync("tests/configs/port_variable.js");
} catch (err) {
// do nothing
}
}); });
it("should return 200", async () => { it("should return 200", async () => {

View File

@ -13,7 +13,6 @@ exports.getText = async (element, result) => {
).toBe(result); ).toBe(result);
}; };
exports.startApp = async (configFileNameName, systemDate) => { exports.startApp = async (configFileName, systemDate) => {
injectMockData(configFileNameName); await helpers.startApplication(injectMockData(configFileName), systemDate);
await helpers.startApplication("", systemDate);
}; };

View File

@ -1,9 +1,11 @@
const helpers = require("../helpers/global-setup"); const helpers = require("../helpers/global-setup");
const weatherHelper = require("../helpers/weather-setup"); const weatherHelper = require("../helpers/weather-setup");
const { cleanupMockData } = require("../../utils/weather_mocker");
describe("Weather module", () => { describe("Weather module", () => {
afterEach(async () => { afterEach(async () => {
await helpers.stopApplication(); await helpers.stopApplication();
await cleanupMockData();
}); });
describe("Current weather with sunrise", () => { describe("Current weather with sunrise", () => {

View File

@ -1,5 +1,7 @@
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const util = require("util");
const exec = util.promisify(require("child_process").exec);
const _ = require("lodash"); const _ = require("lodash");
/** /**
@ -35,9 +37,16 @@ const injectMockData = (configFileName, extendedData = {}) => {
} else { } else {
mockWeather = readMockData("current", extendedData); mockWeather = readMockData("current", extendedData);
} }
let content = fs.readFileSync(path.resolve(`${__dirname}../../../${configFileName}`)).toString(); let content = fs.readFileSync(configFileName).toString();
content = content.replace("#####WEATHERDATA#####", mockWeather); content = content.replace("#####WEATHERDATA#####", mockWeather);
fs.writeFileSync(path.resolve(`${__dirname}../../../config/config.js`), content); const tempFile = configFileName.replace(".js", "_temp.js");
fs.writeFileSync(tempFile, content);
return tempFile;
}; };
module.exports = { injectMockData }; const cleanupMockData = async () => {
const tempDir = path.resolve(`${__dirname}/../configs`).toString();
await exec(`find ${tempDir} -type f -name *_temp.js -delete`);
};
module.exports = { injectMockData, cleanupMockData };