Skip to content

Commit

Permalink
Htmx 1.9.19
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jan 12, 2024
1 parent a959233 commit d3df916
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2002-2024 Gargoyle Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.htmlunit.javascript.preprocessor;

import org.apache.commons.lang3.StringUtils;
import org.htmlunit.ScriptPreProcessor;
import org.htmlunit.html.HtmlElement;
import org.htmlunit.html.HtmlPage;

/**
* Preprozessor to fix one default parameter method.
*
* @author Ronald Brill
*/
public class HtmxOneNineTenScriptPreprozessor implements ScriptPreProcessor {

private final ScriptPreProcessor nextScriptPreProcessor_;

public HtmxOneNineTenScriptPreprozessor() {
nextScriptPreProcessor_ = null;
}

public HtmxOneNineTenScriptPreprozessor(final ScriptPreProcessor nextScriptPreProcessor) {
nextScriptPreProcessor_ = nextScriptPreProcessor;
}

@Override
public String preProcess(final HtmlPage htmlPage, final String sourceCode, final String sourceName,
final int lineNumber, final HtmlElement htmlElement) {

String patchedSourceCode = sourceCode;

if (sourceName.contains("/htmx.js")) {
patchedSourceCode = StringUtils.replace(
sourceCode,
"function makeTagRegEx(tag, global = false) {",
"function makeTagRegEx(tag) {\n"
+ " "
+ "var global = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n");
}
else if (sourceName.contains("/htmx.min.js")) {
patchedSourceCode = StringUtils.replace(
sourceCode,
"function e(e,t=false){",
"function e(e){"
+ "var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; ");
}

if (nextScriptPreProcessor_ != null) {
return nextScriptPreProcessor_.preProcess(htmlPage, patchedSourceCode, sourceName, lineNumber, htmlElement);
}

return patchedSourceCode;
}
}
7 changes: 5 additions & 2 deletions src/test/java/org/htmlunit/libraries/HtmxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ protected void htmx(final String subDir) throws Exception {
final String url = URL_FIRST + "test/index.html";
final WebDriver webDriver = getWebDriver();

if (getWebDriver() instanceof HtmlUnitDriver) {
getWebClient().getOptions().setThrowExceptionOnScriptError(false);
if (webDriver instanceof HtmlUnitDriver) {
setupWebClient(((HtmlUnitDriver) webDriver).getWebClient());
}

int tries = 0;
Expand Down Expand Up @@ -102,6 +102,9 @@ protected void htmx(final String subDir) throws Exception {
}
}

protected void setupWebClient(final WebClient webClient) {
}

private static String getResultElementText(final WebDriver webdriver) {
// if the elem is not available or stale we return an empty string
// this will force a second try
Expand Down
59 changes: 59 additions & 0 deletions src/test/java/org/htmlunit/libraries/HtmxTest1x9x10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2002-2024 Gargoyle Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.htmlunit.libraries;

import org.htmlunit.WebClient;
import org.htmlunit.javascript.preprocessor.HtmxOneNineTenScriptPreprozessor;
import org.htmlunit.junit.BrowserRunner;
import org.htmlunit.junit.BrowserRunner.Alerts;
import org.htmlunit.junit.BrowserRunner.HtmlUnitNYI;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Tests for <a href="https://htmx.org/">htmx</a>.
*
* @author Ronald Brill
*/
@RunWith(BrowserRunner.class)
public class HtmxTest1x9x10 extends HtmxTest {

/**
* @throws Exception if an error occurs
*/
@Test
@Alerts(DEFAULT = "passes:679failures:1",
FF = "passes:679failures:0",
FF_ESR = "passes:679failures:0",
IE = "not testable")
@HtmlUnitNYI(
CHROME = "passes:679failures:0",
EDGE = "passes:679failures:0")
public void htmx() throws Exception {
// the test page runs in an endless loop in ie
if (getBrowserVersion().isIE()) {
return;
}
htmx("htmx-1.9.10");
}

@Override
protected void setupWebClient(final WebClient webClient) {
super.setupWebClient(webClient);

webClient.setScriptPreProcessor(new HtmxOneNineTenScriptPreprozessor());
webClient.getOptions().setThrowExceptionOnScriptError(false);
}
}

0 comments on commit d3df916

Please sign in to comment.