I am trying to externalize functionalities from Cypress tests written in TypeScript/cucumber, aiming for reuse across multiple repositories. In my commands.ts file, various functionalities are encapsulated within the Cypress.Commands namespace. These commands are then added to the global cy object in the e2e.ts file. Despite successfully compiling TypeScript files using npx tsc, I encountered a 404 error during the npm publish process.
How can I compile these code in js and create a npm package?
// commands.ts
import { whateverClass1 } from "..";
import { whateverClass2 } from "..";
declare global {
namespace Cypress {
interface Chainable {
createLabel: typeof createLabel;
save : typeof save ;
}
}
}
const createLabel = (param: string) => {
whateverClass1.createLabel(param);
};
const save = () => {
whateverClass2.save();
};
const Commands = {
save,
createLabel,
};
export default Commands;
// e2e.ts
import Commands from './commands';
Cypress.Commands.add('save', Commands.save);
Cypress.Commands.add('createLabel', Commands.createLabel);
// tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": ["dom", "es6"],
"types": ["cypress", "node", "cypress-xpath"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true
},
"exclude": ["node_modules"]
}