• Resolved zethodderskov

    (@zethodderskov)


    Description of the error:

    We’ve written an automated test, that opens the search-field via the UI and performs a search for the string: test.
    It fails upon every single run, with below details.
    If I run it directly in my browser, then I can’t reproduce it, but the error seems legit enough.

    The error in the console:

    I happens in: index-67d905f1.js or VM4812:1 (resource name changes from one test to the next).

    Error:      SyntaxError: Unexpected token '<', "<head> <sc"... is not valid JSON
        at JSON.parse (<anonymous>)
        at Object.e [as transformResult] (search.min.js?r=e7699c8a4f2ec1f8c9f818d804a3e186:1:5812)
        at Object.<anonymous> (search.min.js?r=e7699c8a4f2ec1f8c9f818d804a3e186:1:26703)
        at c (jquery.min.js?r=e7699c8a4f2ec1f8c9f818d804a3e186:2:28327)
        at Object.fireWith [as resolveWith] (jquery.min.js?r=e7699c8a4f2ec1f8c9f818d804a3e186:2:29072)
        at l (jquery.min.js?r=e7699c8a4f2ec1f8c9f818d804a3e186:2:79901)
        at XMLHttpRequest.<anonymous> (jquery.min.js?r=e7699c8a4f2ec1f8c9f818d804a3e186:2:82355)

    It happens after I try and access the search via a Cypress-search.

    If I click the link to the file, I see the file in my debugger:

    <head> <script type='text/javascript'> document.domain = 'MY_LOCAL_TEST_DOMAIN.test'; !function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call
    
    ...
    ...
    ...
    
    r.on("app:timers:reset",o.reset),r.on("app:timers:pause",o.pause),o.wrap(),r.action("app:window:before:load",window)},0:function(e,t,n){e.exports=n("./injection/main.js")}}); </script> </head>{"suggestions":[{"value":"","type":"no-results"}],"total":0,"time":"0.01 sec","engine":"free","v":"1.26.1"}

    First stack trace step:

    n.utils = s,
        e.DgwtWcasAutocompleteSearch = n,
        n.defaults = {
            ajaxSettings: {},
            autoSelectFirst: !1,
            appendTo: "body",
            serviceUrl: null,
            lookup: null,
            onSelect: null,
            containerDetailsWidth: "auto",
            showDetailsPanel: !1,
            showImage: !1,
            showPrice: !1,
            showSKU: !1,
            showDescription: !1,
            showSaleBadge: !1,
            showFeaturedBadge: !1,
            dynamicPrices: !1,
            saleBadgeText: "sale",
            featuredBadgeText: "featured",
            minChars: 3,
            maxHeight: 600,
            dpusbBreakpoint: 550,
            deferRequestBy: 0,
            params: {},
            formatResult: function e(t, a, o) {
                return a.length > 0 && o && (t = s.highlight(t, a)),
                s.formatHtml(t)
            },
            delimiter: null,
            zIndex: 999999999,
            type: "GET",
            noCache: !1,
            isRtl: !1,
            onSearchStart: i,
            onSearchComplete: i,
            onSearchError: i,
            preserveInput: !1,
            searchFormClass: "dgwt-wcas-search-wrapp",
            containerClass: "dgwt-wcas-suggestions-wrapp",
            containerDetailsClass: "dgwt-wcas-details-wrapp",
            preSuggestionsWrappClass: "dgwt-wcas-pre-suggestions-wrapp",
            darkenedOverlayClass: "dgwt-wcas-darkened-overlay",
            searchInputClass: "dgwt-wcas-search-input",
            preloaderClass: "dgwt-wcas-preloader",
            closeTrigger: "dgwt-wcas-close",
            formClass: "dgwt-wcas-search-form",
            voiceSearchClass: "dgwt-wcas-voice-search",
            voiceSearchSupportedClass: "dgwt-wcas-voice-search-supported",
            voiceSearchActiveClass: "dgwt-wcas-voice-search-active",
            voiceSearchDisabledClass: "dgwt-wcas-voice-search-disabled",
            tabDisabled: !1,
            dataType: "text",
            currentRequest: null,
            triggerSelectOnValidInput: !0,
            isPremium: !1,
            overlayMobile: !1,
            preventBadQueries: !0,
            lookupFilter: function e(t, s, a) {
                return -1 !== t.value.toLowerCase().indexOf(a)
            },
            paramName: "query",
            transformResult: function e(t) {
                return "string" == typeof t ? JSON.parse(t) : t          //  <---- HERE IS WHERE THE ERROR OCCURS
            },
            noSuggestionNotice: "No results",
            forceFixPosition: !1,
            positionFixed: !1,
            debounceWaitMs: 400,
            sendGAEvents: !0,
            enableGASiteSearchModule: !1,
            showProductVendor: !1,
            disableHits: !1,
            disableSubmit: !1,
            voiceSearchEnabled: !1,
            voiceSearchLang: "",
            showRecentlySearchedProducts: !1,
            showRecentlySearchedPhrases: !1
        },

    In Firefox it also adds this error:

    (uncaught exception)Error: There is no route for the given namespace (/wc/store/v1) in the store

    How it looks:

    It looks like this:

    Solution attempts:

    • Ensure I’m on the latest version (I am: 1.26.1 )
    • Try both to press ‘Enter’, but also click the ‘Search’-button. Both things makes the Cypress-test show above error.
    • Try in different browsers (manually): Neither in Chrome nor Safari, I get the error when I do it myself. But using Cypress, then both Chrome, Electron and Firefox, it makes this fail.
Viewing 1 replies (of 1 total)
  • Hi @zethodderskov

    The error you’re encountering seems related to Cypress and its interaction with the FiboSearch endpoint. When Cypress interacts with the FiboSearch UI by opening the search field and performing a search for the string “test,” it encounters an issue that consistently causes the test to fail. However, when you manually run the test in your browser, you don’t encounter the same problem, which suggests there might be an issue specific to how Cypress interacts with the page.

    The error message in the console indicates a SyntaxError: Unexpected token '<', which typically suggests that the response received from the server is not valid JSON. This error appears to be originating from a JavaScript file named “index-67d905f1.js” or similar (the resource name may change from one test to the next).

    Upon further investigation, I’ve found that Cypress may be injecting additional markup into the FiboSearch endpoint response, causing it to become an invalid JSON. This unexpected markup, which starts with <head> <script type='text/javascript'> document.domain = 'MY_LOCAL_TEST_DOMAIN.test'; ... and appears to contain JavaScript code, which is likely the cause of the SyntaxError.

    To address this issue, you may need to adjust how Cypress interacts with the FiboSearch endpoint or investigate any Cypress plugins or configurations that might be affecting the response.

    You can also check out this thread on Stackoverflow for more information.

    Regards,
    Kris

Viewing 1 replies (of 1 total)
  • The topic ‘Getting error: SyntaxError: Unexpected token… not valid JSON’ is closed to new replies.