Skip to content

Commit

Permalink
Merge pull request #84 from KCarlile/73-add-a-test-suite
Browse files Browse the repository at this point in the history
Issue #73: Add Jest test suite for unit/regression testing. One examp…
  • Loading branch information
KCarlile authored Jun 2, 2022
2 parents 3a80a9f + 760b45e commit 3ed8e58
Show file tree
Hide file tree
Showing 9 changed files with 6,091 additions and 3 deletions.
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

0 comments on commit 3ed8e58

Please sign in to comment.