How to play the specific property of the browser `window.location.origin` with AVA

Context

I have a Frontend React + Webpack application using front-end APIs. My setup of Webpack depends on the window.location.origin property, for configuration and deployment. I am currently using Karma testrunner and am trying to replace it with an AVA test test.

I am trying to apply AVA with this setting up a single entry for the webpack recipe. I also use JSDOM as a dom emulator for node.

Problem

Some of the tests included in the kit use the location.origin property. What causes an error when running webpack && ava script:

 var apiUrl = process.env.API_URL && process.env.NODE_ENV !== 'production' ? process.env.API_URL : location.origin; ReferenceError: location is not defined 

Karma works in a browser and dynamically reproduces the value of window.location.origin . With AVA is different. When you run the test, it does not start the browser. I can (as far as I know) emulate the browser environment using jsdom , and this is what I am trying to do. However, the specific property location.origin not supported by jsdom Reference

Question

Can someone track me in the solution for playing window.location.origin dynamically (from an environmental point of view) for AVA? I know that I can put it in a constant and save it in .env for each environment. But this is another maintenance task that I would like to mitigate.

+5
source share

Source: https://habr.com/ru/post/1272836/


All Articles