summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexander Petros <apetros15@gmail.com>2023-06-24 16:21:55 -0400
committerGitHub <noreply@github.com>2023-06-24 14:21:55 -0600
commitfe4a803e2e91ffb5e81b90e246fcf5ff490f0d3f (patch)
tree74f7b5b7e9311962d33220e2e7ef91f216d3ab64
parent081aaf3cca4ea1bd94b74471ab4c7fd7e2e16d0b (diff)
downloadhtmx-fe4a803e2e91ffb5e81b90e246fcf5ff490f0d3f.tar.gz
htmx-fe4a803e2e91ffb5e81b90e246fcf5ff490f0d3f.zip
Add logNone function and apply it to tests (#1504)
New function to turn off the logger after using `logAll()`. I applied to this to the tests as well so that `logAll()` is only used in the specfic places where debug output is required. This makes the console output of the tests dramatically more useful when run from the command line.
-rw-r--r--src/htmx.js5
-rw-r--r--test/attributes/hx-boost.js1
-rw-r--r--test/core/api.js14
-rw-r--r--test/core/regressions.js2
-rw-r--r--www/content/api.md10
5 files changed, 22 insertions, 10 deletions
diff --git a/src/htmx.js b/src/htmx.js
index 70a93ab4..8782d837 100644
--- a/src/htmx.js
+++ b/src/htmx.js
@@ -44,6 +44,7 @@ return (function () {
defineExtension : defineExtension,
removeExtension : removeExtension,
logAll : logAll,
+ logNone : logNone,
logger : null,
config : {
historyEnabled:true,
@@ -475,6 +476,10 @@ return (function () {
}
}
+ function logNone() {
+ htmx.logger = null
+ }
+
function find(eltOrSelector, selector) {
if (selector) {
return eltOrSelector.querySelector(selector);
diff --git a/test/attributes/hx-boost.js b/test/attributes/hx-boost.js
index 96000f28..330b9cb8 100644
--- a/test/attributes/hx-boost.js
+++ b/test/attributes/hx-boost.js
@@ -1,6 +1,5 @@
describe("hx-boost attribute", function() {
- htmx.logAll();
beforeEach(function () {
this.server = makeServer();
clearWorkArea();
diff --git a/test/core/api.js b/test/core/api.js
index aea3fa24..28f21a41 100644
--- a/test/core/api.js
+++ b/test/core/api.js
@@ -241,13 +241,13 @@ describe("Core htmx API test", function(){
div3.classList.contains("foo").should.equal(true);
});
- it('logAll works', function () {
- var initialLogger = htmx.config.logger
- try {
- htmx.logAll();
- } finally {
- htmx.config.logger = initialLogger;
- }
+ it('logAll and logNone works', function () {
+ var initialLogger = htmx.logger
+ htmx.logAll();
+ htmx.logger.should.not.equal(null);
+ htmx.logNone();
+ should.equal(htmx.logger, null);
+ htmx.logger = initialLogger;
});
it('eval can be suppressed', function () {
diff --git a/test/core/regressions.js b/test/core/regressions.js
index 5a478557..585ab3dc 100644
--- a/test/core/regressions.js
+++ b/test/core/regressions.js
@@ -130,7 +130,6 @@ describe("Core htmx Regression Tests", function(){
it('a form can reset based on the htmx:afterRequest event', function() {
this.server.respondWith("POST", "/test", "posted");
- //htmx.logAll();
var form = make('<div id="d1"></div><form _="on htmx:afterRequest reset() me" hx-post="/test" hx-target="#d1">' +
' <input type="text" name="input" id="i1"/>' +
@@ -174,7 +173,6 @@ describe("Core htmx Regression Tests", function(){
it("supports unset on hx-select", function(){
this.server.respondWith("GET", "/test", "Foo<span id='example'>Bar</span>");
- htmx.logAll();
make('<form hx-select="#example">\n' +
' <button id="b1" hx-select="unset" hx-get="/test">Initial</button>\n' +
'</form>')
diff --git a/www/content/api.md b/www/content/api.md
index ca376723..331cc430 100644
--- a/www/content/api.md
+++ b/www/content/api.md
@@ -240,6 +240,16 @@ Log all htmx events, useful for debugging.
htmx.logAll();
```
+### Method - `htmx.logNone()` {#logNone}
+
+Log no htmx events, call this to turn off the debugger if you previously enabled it.
+
+##### Example
+
+```js
+ htmx.logNone();
+```
+
### Property - `htmx.logger` {#logger}
The logger htmx uses to log with