Skip to content
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

Issue #73: Add Jest test suite for unit/regression testing. One examp… #84

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Commit: <>
- Issue [#60](https://github.com/KCarlile/flashchord/issues/60): Add changelog to About page.
- About page updates: adding new tech and adding donors.
- Issue [#80](https://github.com/KCarlile/flashchord/issues/80): Updated to Twitter Bootstrap 5.2-beta.
- Issue [#73](https://github.com/KCarlile/flashchord/issues/73): Add Jest test suite for unit/regression testing.

## Release 1.7

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ For logging functionality, see the `js/utils.js` file and look at the following
- PHP
- [Parsedown for Markdown parsing](https://parsedown.org/)
- Composer for dependency management
- Jest for unit testing of JavaScript
- Run Jest using `./test` from the command line

## Creator

Expand Down
1 change: 1 addition & 0 deletions about.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<li><a href="https://www.w3.org/Style/CSS/">CSS</a></li>
<li><a href="https://getbootstrap.com/">Bootstrap</a></li>
<li><a href="https://parsedown.org/">Parsedown</a></li>
<li><a href="https://jestjs.io/">Jest JS</a></li>
<li><a href="https://getcomposer.org/">Composer</a></li>
<li><a href="https://git-scm.com/">Git</a></li>
<li><a href="https://github.com/">GitHub</a></li>
Expand Down
5 changes: 5 additions & 0 deletions js2/Controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Controller {
constructor() {

}
}
91 changes: 91 additions & 0 deletions js2/Logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Logger class provides an easy way to log to Chrome's console and includes section dividers.
*
* Tested via /tests/Logger.test.js.
*/
module.exports = class Logger {
enabled = false;

/**
* Default constructor assumes debugging to be disabled.
*
* @param {boolean} enabled
*/
constructor(enabled) {
this.enabled = enabled;
}

/**
* Response with true if logging is enabled, false if logging is disabled.
*
* @returns {boolean} Status of logging enablement.
*/
isEnabled() {
return this.enabled;
}

/**
* Enables logging even if Logger was instantiated with logging disabled.
*/
enableLogging() {
this.enabled = true;
}

/**
* Disables logging even if Logger was instantiated with logging enabled.
*/
disableLogging() {
this.enabled = false;
}

/**
* Logs a message to the console if debugging is enabled.
*
* @param {string} message The message to be written to console.log().
* @param {boolean} override Overrides the instance-level setting for logging enabled.
* @returns {boolean} True if the console.log() command succeeded; false if not.
*/
logger(message, override = false) {
let success = false;

if (this.enabled || override) {
try {
console.log(message);

success = true;
}
catch (exception) {
throw "Console.log not available."
}
}

return success;
}

/**
* Prints a new section divider to the console if logging is enabled.
*
* @param {boolean} override
* @param {boolean} override Overrides the instance-level setting for logging enabled.
* @returns {boolean} True if the console.log() command succeeded; false if not.
*/
loggerNewSection(override = false) {
return this.logger("==========", override);
}

// start a new sub-block of logging with a light line if logging is enabled

/**
* Prints a sub-block divider line to the console if logging is enabled.
* @param {boolean} override Overrides the instance-level setting for logging enabled.
* @returns {boolean} True if the console.log() command succeeded; false if not.
*/
/**
*
* @param {*} override
* @returns
*/
loggerNewBlock(override = false) {
return this.logger("----------", override);
}
}
Loading