-
-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development documentation (MM issue #3252) #218
Open
jkriegshauser
wants to merge
7
commits into
MagicMirrorOrg:develop
Choose a base branch
from
jkriegshauser:development-documentation
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+238
−16
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f1b1997
Rename development -> module-development
jkriegshauser e093521
Initial core documentation
jkriegshauser 2aaec0f
Corrections
jkriegshauser 0ffe867
Fix links
jkriegshauser 0f6e296
Additional debugging info
jkriegshauser ddad6b5
Added redirects
rejas 7044b63
Lint new pages
rejas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default ({ router }) => { | ||
router.addRoutes([ | ||
{ path: '/development/introduction.html', redirect: '/module-development/introduction.html' }, | ||
{ path: '/development/core-module-file.html', redirect: '/module-development/core-module-file.html' }, | ||
{ path: '/development/node-helper.html', redirect: '/module-development/node-helper.html' }, | ||
{ path: '/development/helper-methods.html', redirect: '/module-development/helper-methods.html' }, | ||
{ path: '/development/logger.html', redirect: '/module-development/logger.html' }, | ||
{ path: '/development/notifications.html', redirect: '/module-development/notifications.html' }, | ||
{ path: '/development/weather-provider.html', redirect: '/module-development/weather-provider.html' }, | ||
{ path: '/development/documentation.html', redirect: '/module-development/documentation.html' } | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
title: Debugging | ||
--- | ||
|
||
# Core Development Documentation: Debugging | ||
|
||
Tips and tricks for debugging MagicMirror², | ||
|
||
## Make sure dependencies are up-to-date | ||
|
||
When you pull a branch, exceptions can be thrown when running MagicMirror²: | ||
``` | ||
App threw an error during load | ||
Error: Cannot find module 'ansis' | ||
Require stack: | ||
``` | ||
|
||
If this happens, make sure that dependencies have been updated to latest by executing `npm install`. | ||
|
||
## 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. | ||
|
||
Developer consoles in browsers and the Electron app (typically CTRL+SHIFT+I to toggle open/close) can be used to set client-side breakpoints, step through scripts and inspect variables. | ||
|
||
## Logging | ||
|
||
While there are no log files produced by the server, info is reported in two different places: | ||
* The console when running from `npm run start` or `npm run server`. | ||
* This is separated into two streams, `console.log()` is output as the `stdout` stream, and | ||
* `console.error()` is output as the `stderr` stream. | ||
* These can be redirected to files when starting the server. `>` will redirect `stdout`, and `2>` will redirect `stderr`. `2>&1` will combine both streams: `npm run start > out.log 2>&1` | ||
* The browser's developer console (typically CTRL+SHIFT+I to toggle open/close) will have output from scripts that run on the browser. | ||
|
||
The [MMM-Logging](https://github.com/shbatm/MMM-Logging) module can help to gather logs and output to a file, but at a performance cost. | ||
|
||
Debug logging is disabled by default, and can be very verbose. It can be enabled in the *config/config.js* file by adding `"DEBUG"` to the `logLevel` key: | ||
```js | ||
let config = { | ||
// ... | ||
logLevel: ["INFO", "LOG", "WARN", "ERROR", "DEBUG"], // Add "DEBUG" for even more logging | ||
// ... | ||
}; | ||
``` | ||
|
||
If you are using `pm2` to launch MagicMirror², you can use the `logs` command to display lines from each of the `stderr` and `stdout` streams, but not interlaced by time: | ||
```sh | ||
pm2 logs --lines=15 # will show 15 lines each from stdout and stderr | ||
``` | ||
|
||
There is no capability to identify the module that is producing console output. However, most browsers have the ability to filter logs by a string. | ||
|
||
## 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').valueOf(); | ||
``` | ||
|
||
This will cause every request for the current time to return the specified time, at least for the core and built-in modules. | ||
|
||
Several tests use this to override the current time for the test. See `startApplication()` in *tests/electron/helpers/global-setup.js* as it has a `systemDate` argument to override the system date for tests. | ||
|
||
**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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/MagicMirrorOrg/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/MagicMirrorOrg/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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/MagicMirrorOrg/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/). |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0
development/weather-provider.md → module-development/weather-provider.md
100755 → 100644
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this makes a lot more sense now 👍