How do I specify the base file path to import files in Cypress.io?

Viewed 1596

I want to import my locale file locale/pages.js into a test so that I don't hardcode locale strings, but the locale file imports other things like constants using statements like:

import { PRODUCT_NAME } from 'config/general';

The config and locale directories are inside src directory, but cypress directory is at the project root. So to refer to the locale file, I have to specify from 'cypress/integration/test.spec.js' the relative path '../../src/locale/pages.js'. I would rather be able to use locale/pages.js, but at least this gets me access to the file. But at this point, the import of the config file fails.

How can I specify the base path for imports so that I don't have to worry about where the current file is relative to the file to be imported?

2 Answers

We may load js file by appending 'script' tag in DOM. Try the below code:

var script = document.createElement('script');          
script.src = PATH;
script.onload =  function(){
    FILE LOADED           
};
document.head.appendChild(script);
Related