Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Uncaught SyntaxError: Unexpected token ( #8

Closed
cdeutsch opened this issue Oct 16, 2018 · 1 comment
Closed

Uncaught SyntaxError: Unexpected token ( #8

cdeutsch opened this issue Oct 16, 2018 · 1 comment

Comments

@cdeutsch
Copy link

cdeutsch commented Oct 16, 2018

I'm getting the error...

Uncaught SyntaxError: Unexpected token (

...when trying to run a test via the Cypress GUI.

I'm using Typescript with Cypress which might be (part of) the problem, but I tracked down the issue to here:
https://github.com/applitools/visual-grid-client/blob/af0121538dd78872a32f505c29f8f84fced3aef9/src/browser-util/processResources.js#L113

Is there a reason you can't declare a normal function there?
(I probably don't want to know 😆)

It works if I move the code from absolutizeUrl and domNodesToCdt into processResources.js, it will compile, but it still doesn't work because something seems to be minimizing it and turning it into:

function a(t,e){const{origin:r}="data:"===t.protocol?t.origin:new n(e,t.href);return r===t.origin||/^blob:/.test(e)}
function o(t,e){return new n(t,e).href}
  function h(t){return Array.from(new Set(t)).filter(t=>!!t)}
  function i(t,e){return e.reduce((e,r)=>(a(t,r)?e.internalUrls.push(r):e.externalUrls.push(r),e),{externalUrls:[],internalUrls:[]})}
  function c(t){const e=t.defaultView,r=[...t.querySelectorAll("img[src],source[src]")].map(t=>t.getAttribute("src")),n=[...t.querySelectorAll('link[rel="stylesheet"]')].map(t=>t.getAttribute("href")),s=[...t.querySelectorAll("video[poster]")].map(t=>t.getAttribute("poster")),a=i(e.location,[...r,...n,...s]);return{requiresMoreParsing:h([...t.querySelectorAll("iframe[src]")].map(t=>{try{return t.contentDocument}catch(t){return}}).filter(t=>!!t)),externalUrls:h(a.externalUrls).map(t=>{try{return o(t,e.location)}catch(e){return t}}),urlsToFetch:h(a.internalUrls).map(t=>o(t,e.location))}}
  function u(t,e,r=window.fetch){return Promise.all(e.map(e=>r(e,{cache:"force-cache",credentials:"same-origin"}).then(r=>r.arrayBuffer().then(o=>({url:new n(e.replace(/^blob:http:\/\/localhost:\d+\/(.+)/,"$1"),t).href,type:r.headers.get("Content-Type"),value:o})))))}
  function l(t){const e=t.defaultView.frameElement?t.defaultView.frameElement.src:t.defaultView.location.href;let{urlsToFetch:r,externalUrls:n,requiresMoreParsing:o}=c(t);return u(e,r,t.defaultView.fetch).then(r=>Promise.all(o.map(t=>l(t))).then(o=>({cdt:s(t),url:e,resourceUrls:n,blobs:r,frames:o,allBlobs:o.reduce((t,e)=>h([...t,...e.allBlobs]),r)})))}

  return processPage(doc);

...ahhhh Compiled Javascript. What a wonderful time to be alive 🤦‍♂️

@cdeutsch
Copy link
Author

cdeutsch commented Oct 16, 2018

Never mind.

Fixed the whole thing by turning off Webpack minification.

webpack.config.js

module.exports = {
  optimization: {
    // minimize the code will cause applitools/eyes.cypress to fail
    // https://github.com/applitools/eyes.cypress/issues/8
    minimize: false
  },
  resolve: {
    extensions: ['.ts', '.js'],
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        exclude: [/node_modules/],
        use: [{
          loader: 'ts-loader',
          options: {
            configFile: 'tsconfig.cypress.json'
          }
        }],
      },
    ],
  },
}

...I need a drink

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant