Skip to content

Commit

Permalink
avoid overriding config.js when running tests (#3205)
Browse files Browse the repository at this point in the history
solves #3201
  • Loading branch information
khassel authored Sep 22, 2023
1 parent a67a0b6 commit 95ec309
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- 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 overriding `config.js` when running tests (#3201)

## [2.24.0] - 2023-07-01

Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/helpers/weather-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exports.getText = async (element, result) => {
};

exports.startApp = async (configFileName, additionalMockData) => {
injectMockData(configFileName, additionalMockData);
await helpers.startApplication("");
await helpers.startApplication(injectMockData(configFileName, additionalMockData));
await helpers.getDocument();
};
2 changes: 2 additions & 0 deletions tests/e2e/modules/weather_current_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const helpers = require("../helpers/global-setup");
const weatherFunc = require("../helpers/weather-functions");
const { cleanupMockData } = require("../../utils/weather_mocker");

describe("Weather module", () => {
afterAll(async () => {
await helpers.stopApplication();
await cleanupMockData();
});

describe("Current weather", () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/modules/weather_forecast_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const helpers = require("../helpers/global-setup");
const weatherFunc = require("../helpers/weather-functions");
const { cleanupMockData } = require("../../utils/weather_mocker");

describe("Weather module: Weather Forecast", () => {
afterAll(async () => {
await helpers.stopApplication();
await cleanupMockData();
});

describe("Default configuration", () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/modules/weather_hourly_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const helpers = require("../helpers/global-setup");
const weatherFunc = require("../helpers/weather-functions");
const { cleanupMockData } = require("../../utils/weather_mocker");

describe("Weather module: Weather Hourly Forecast", () => {
afterAll(async () => {
await helpers.stopApplication();
await cleanupMockData();
});

describe("Default configuration", () => {
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/template_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require("fs");
const helpers = require("./helpers/global-setup");

describe("templated config with port variable", () => {
Expand All @@ -6,6 +7,11 @@ describe("templated config with port variable", () => {
});
afterAll(async () => {
await helpers.stopApplication();
try {
fs.unlinkSync("tests/configs/port_variable.js");
} catch (err) {
// do nothing
}
});

it("should return 200", async () => {
Expand Down
5 changes: 2 additions & 3 deletions tests/electron/helpers/weather-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exports.getText = async (element, result) => {
).toBe(result);
};

exports.startApp = async (configFileNameName, systemDate) => {
injectMockData(configFileNameName);
await helpers.startApplication("", systemDate);
exports.startApp = async (configFileName, systemDate) => {
await helpers.startApplication(injectMockData(configFileName), systemDate);
};
2 changes: 2 additions & 0 deletions tests/electron/modules/weather_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const helpers = require("../helpers/global-setup");
const weatherHelper = require("../helpers/weather-setup");
const { cleanupMockData } = require("../../utils/weather_mocker");

describe("Weather module", () => {
afterEach(async () => {
await helpers.stopApplication();
await cleanupMockData();
});

describe("Current weather with sunrise", () => {
Expand Down
15 changes: 12 additions & 3 deletions tests/utils/weather_mocker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const fs = require("fs");
const path = require("path");
const util = require("util");
const exec = util.promisify(require("child_process").exec);
const _ = require("lodash");

/**
Expand Down Expand Up @@ -35,9 +37,16 @@ const injectMockData = (configFileName, extendedData = {}) => {
} else {
mockWeather = readMockData("current", extendedData);
}
let content = fs.readFileSync(path.resolve(`${__dirname}../../../${configFileName}`)).toString();
let content = fs.readFileSync(configFileName).toString();
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 };

0 comments on commit 95ec309

Please sign in to comment.