Compare commits

...

2 Commits

Author SHA1 Message Date
Karsten Hassel
aac85bbb54 improve config check tests (#3889)
see
https://github.com/MagicMirrorOrg/MagicMirror/pull/3886#issuecomment-3280414877
2025-09-11 21:50:11 +02:00
Kristjan ESPERANTO
d81386f3d9 chore: use prettier --write --ignore-unknown in lint-staged to avoid errors on unsupported files (#3888)
This prevents `prettier` from failing when `lint-staged` passes
unknown/binary files, making the pre-commit hook more robust.

In concrete terms this could happen, when we, for example, add a new PNG
file. Since we rarely do this, it has not been noticed so far.

This is recommended when using asterisk:
https://github.com/lint-staged/lint-staged#automatically-fix-code-style-with-prettier-for-any-format-prettier-supports

## before

```bash
$ npx lint-staged <-- after staging a new PNG file
✔ Backed up original state in git stash (c3247d4b)
✔ Hiding unstaged changes to partially staged files...
⚠ Running tasks for staged files...
  ❯ package.json — 2 files
    ❯ * — 2 files
      ✖ prettier --write [FAILED]
    ↓ *.js — no files
    ↓ *.css — no files
↓ Skipped because of errors from tasks.
↓ Skipped because of errors from tasks.
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ prettier --write:
[error] No parser could be inferred for file "~/MagicMirror/test.png".
...
```

## after

```bash
$ npx lint-staged <-- after staging a new PNG file
✔ Backed up original state in git stash (0c3fe285)
✔ Running tasks for staged files...
✔ Applying modifications from tasks...
✔ Cleaning up temporary files...
```
2025-09-11 18:34:08 +02:00
3 changed files with 15 additions and 4 deletions

View File

@@ -25,7 +25,7 @@ Thanks to: @dathbe.
- [clock] Add CSS to prevent line breaking of sunset/sunrise time display (#3816)
- [core] Enhance system information logging format and include additional env and RAM details (#3839, #3843)
- [refactor] Add new file `js/module_functions.js` to move code used in several modules to one place (#3837)
- [refactor] Use global.root_path where possible and add test for config:check (#3883, #3885, #3886)
- [refactor] Use global.root_path where possible and add tests for config:check (#3883, #3885, #3886, #3889)
- [tests] refactor: simplify jest config file (#3844)
- [tests] refactor: extract constants for weather electron tests (#3845)
- [tests] refactor: add `setupDOMEnvironment` helper function to eliminate repetitive JSDOM setup code (#3860)
@@ -39,6 +39,7 @@ Thanks to: @dathbe.
- Avoid potential port conflicts by using port 3001 for translator unit tests
- Improve test reliability and maintainability
- [tests] add alert module tests for different welcome_message configurations (#3867)
- [lint-staged] use `prettier --write --ignore-unknown` in `lint-staged` to avoid errors on unsupported files (#3888)
### Updated

View File

@@ -64,7 +64,7 @@
"test:unit": "NODE_ENV=test jest --selectProjects unit"
},
"lint-staged": {
"*": "prettier --write",
"*": "prettier --ignore-unknown --write",
"*.js": "eslint --fix",
"*.css": "stylelint --fix"
},

View File

@@ -2,6 +2,12 @@ const delay = (time) => {
return new Promise((resolve) => setTimeout(resolve, time));
};
const runConfigCheck = async () => {
const serverProcess = await require("node:child_process").spawnSync("node", ["--run", "config:check"], { env: process.env });
expect(serverProcess.stderr.toString()).toBe("");
return await serverProcess.status;
};
describe("App environment", () => {
let serverProcess;
beforeAll(async () => {
@@ -28,7 +34,11 @@ describe("App environment", () => {
describe("Check config", () => {
it("config check should return without errors", async () => {
process.env.MM_CONFIG_FILE = "tests/configs/default.js";
const serverProcess = await require("node:child_process").spawnSync("node", ["--run", "config:check"], { env: process.env });
expect(serverProcess.stderr.toString()).toBe("");
await expect(runConfigCheck()).resolves.toBe(0);
});
it("config check should fail with non existent config file", async () => {
process.env.MM_CONFIG_FILE = "tests/configs/not_exists.js";
await expect(runConfigCheck()).resolves.toBe(1);
});
});