Skip to content

Commit

Permalink
Initial core documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jkriegshauser committed Dec 31, 2023
1 parent 344f4cb commit 8001704
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ module.exports = {
"module-development/documentation.md",
],
},
{
title: "Core Development",
collapsable: true,
children: [
"core-development/introduction.md",
"core-development/testing.md",
"core-development/debugging.md",
],
},
{
title: "About",
collapsable: true,
Expand Down
47 changes: 47 additions & 0 deletions core-development/debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: Debugging
---

# Core Development Documentation: Debugging

Tips and tricks for debugging MagicMirror²,

## Breakpoints

Node.js has support for [built-in breakpoints](https://nodejs.org/api/debugger.html), or [VSCode](https://code.visualstudio.com/) allows for
visual breakpoints and inspecting of objects.

## Date

It can be very useful to set the current date to debug calendar issues. In order to do this, override `Date.now` with a lambda in *config/config.js*:

```js
Date.now = () => new Date('2023-12-31T14:05:32');
```

This will cause every request for the current time to return the specified time, at least for the core and built-in modules.

**NOTE:** Some modules may use `new Date()` to get the current date/time, though this is not recommended. If this is the case,
the external module will not work correctly for date debugging.

## Timezone

The `TZ` environment variable can be used to specify a valid [canonical timezone name](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
from the [tz database](https://en.wikipedia.org/wiki/Tz_database).

Several tests do this, such as this example in *tests/electron/helpers/global-setup.js*:

```js
process.env.TZ = "GMT";
```

The *package.json* could also be modified to force a timezone for a given script, such as `start:dev`:

```json
"start:dev": "TZ=Europe/Madrid ./node_modules/.bin/electron js/electron.js dev"
```

Or when running from the command line (Linux example):
```sh
TZ=Europe/Madrid npm run start:dev
```
39 changes: 39 additions & 0 deletions core-development/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Introduction
---

# Core Development Documentation

This documentation describes core MagicMirror² development.

## General

MagicMirror² is a community-driven development effort, and [contributions](../about/contributing.md) are
welcome!

In general, new features and bug fixes should be tracked against an [issue in the MagicMirror repo](https://github.com/MichMich/MagicMirror/issues).
It is always a good idea to search existing issues to see if a problem you're experiencing has already been reported,
or if someone has already suggested a feature you'd like to propose. Creating or finding an issue also starts the
discussion and helps build consensus around your proposed fix or feature.

The MagicMirror² core is [developed on GitHub](https://github.com/MichMich/MagicMirror/) out of the
*develop* branch. To begin developing MagicMirror² core, please fork the GitHub project and
create a new branch based off of the *develop* branch.

When your development is ready for review and testing, create a new *Pull Request* targeting the *develop* branch.
The development team and other contributors will be able to review your changes and provide feedback, and
the test system will run automated tests against your changes. Make sure to mention the issue(s) that your Pull
Request solves.

## Development Environment

Although Node.js applications are typically platform-independent, many of the scripts created for MagicMirror² are
Linux-based. While Windows/Mac development is possible, you may run into issues. (Improvements here are welcome!)

You will need to have [Node.js installed](https://nodejs.org/en/download). When doing Linux development, on newer
distributions Node.js is available from package managers.

Many Node.js or experienced Javascript developers have an environment that works for them. New developers
to Node.js / Electron can download [VSCode for free](https://code.visualstudio.com/download) and use many extensions available for debugging and developing Javascript.

Also checkout [Building Node.js Apps with VSCode](https://code.visualstudio.com/docs/nodejs/nodejs-tutorial).
30 changes: 30 additions & 0 deletions core-development/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Testing
---

# Core Development Documentation: Testing

Unit tests are important to ensure the quality of the project as changes occur.

All tests are located in the [*tests* top-level directory](https://github.com/MichMich/MagicMirror/tree/master/tests).

## Hierarchy of Tests

Below the *tests* directory are other directories that organize the tests:

* *configs* - Configuration files for tests.
* *e2e* - End-to-end tests that start and run MagicMirror² in various configurations.
* *electron* - Electron application tests.
* *mocks* - Mock-up data for tests.
* *unit* - Unit tests for utilities and smaller portions of MagicMirror².
* *utils* - Testing utilities.

## Writing a Test

Almost all pull requests must have test coverage of changes. Usually, it is easier to find an existing test and
extend it to test your new functionality.

For example, if you were writing a test for a fix in the Calendar module, you might locate *tests/e2e/modules/calendar_spec.js*
and add an additional test there.

If you have questions about how to write a test, you can also ask in the [MagicMirror forums](https://forum.magicmirror.builders/).
2 changes: 2 additions & 0 deletions module-development/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ information in your README file.**
- What external API's it depends upon, including web links to those
- Whether the API/request require a key and the user limitations of those. (Is
it free?)
- **Do not use `new Date()` for the current timestamp, instead prefer `Date.now()`
as it can be more [easily overridden for debugging](..\core-development\debugging.md#Date)**.

Surely this also help you get better recognition and feedback for your work.

Expand Down

0 comments on commit 8001704

Please sign in to comment.