We have adopted the page object pattern in our testing and recently made the decision to move them into a separate npm-published library for reusability.
Considering the heavy nature of Cypress and potential version conflicts, we believe it's best not to install Cypress directly in the library. Instead, we list it among peerDependencies. To address typing issues (we use TS), I created some types for Cypress commands as shown below:
Options.ts
export interface Options {
log: boolean;
timeout: number;
withinSubject: null | HTMLElement;
includeShadowDom: boolean;
}
global.ts
import { Options } from './Options';
export declare namespace cy {
function get(selector: string, options?: Partial<Options>): Cypress.Chainable<JQuery<HTMLElement>>;
function find(selector: string, options?: Partial<Options>): Cypress.Chainable<JQuery<HTMLElement>>;
}
export declare namespace Cypress {
interface Chainable<Subject> {
find(selector: string, options?: Partial<Options>): Chainable<JQuery<HTMLElement>>;
eq(index: number, options?: Partial<Options>): Chainable<JQuery<HTMLElement>>;
next(selector?: string, options?: Partial<Options>): Chainable<JQuery<HTMLElement>>;
}
}
export declare interface JQuery<Subject> {
}
However, when utilizing the library in our tests, nothing seems to be functioning correctly and an error keeps popping up:
Error: Webpack Compilation Error '../path/file.js' Module not found: Error: Can't resolve 'core-js/modules/es6.array.find' in 'path/dist/fileHoldingFolder' Parsed request is a module using description in file 'path/package.json' (relative path: 'dist/fileHoldingFolder') Field 'browser' doesn't contain a valid alias configuration *Here goes a long list of paths in node_modules*
(The library was included via npm link libname)
To create the library in TypeScript, I followed this guide. The only alteration I made was setting the target to 'ES2015' and adding stricter settings.
At this point, I'm running out of solutions and hoping that someone out there who has experience implementing similar setups can provide assistance. Any help would be greatly appreciated.