I have a typescript file with imports eg:
util.ts file
import { protractor } from 'protractor'
export const waitForFile = async () => {
protractor.promise....
return await ''
}
Now helper.js file
const getUtilFunction = (func) => {
const { register } = require('ts-node');
const { compilerOptions } = require('./tsconfig.json');
register({ compilerOptions });
const result = require('./utils.ts');
return result[func];
};
const waitTillReportGenerated = async () => {
const waitForFileToDownload = getUtilFunction('waitForFileToDownload');
const file = await waitForFileToDownload('./result/result.js', 60000);
console.log(file);
}
However when we call the helper.js function it throws error that protractor is undefined. Can someone please help me with this?
You need to convert .ts file to .js.