Calling the same imports onto a single cypress file

Viewed 68

We are using Cypress v10 and our .cy.js files always use these same imports:

import Customers from "../imports/Customer"
import Search from "../imports/Search"
import PostComment from "../imports/PostComment"
import Feedback from "../imports/Feedback"
import Login from "../imports/Login"

Is there a better way that I can include all these imports in a single or two lines and not call them manually like this? I tried creating a complete.js file that contains copy pasted code as above then try to import that complete.js but it does not seem to work. I'm not sure if I'm missing anything.

2 Answers

You can use an index file to re-export and simplify the import.

// imports/index.js
export { Customers } from 'Customer'
export { Search } from 'Search'
export { PostComment } from 'PostComment'
export { Feedback } from 'Feedback'
export { Login } from 'Login'

// test.cy.js
import { Customers, Search, PostComment, Feedback, Login } from '../imports'

To convert default exports in the individual files to named exports in the barrel index

export { * as Customers } from 'Customer'
export { * as Search } from 'Search'
export { * as PostComment } from 'PostComment'
export { * as Feedback } from 'Feedback'
export { * as Login } from 'Login'
Related