Reputation: 492
I'm working on test automation using testcafe and I have integrated typescript into the project. I have set up non-relative paths, see below, which work for the IDE but when compiled I'm sure they're not being reverted to their original paths.
I have tried setting the moduleResolution option to a node in tsconfig.json although this did not work.
Is there a way this can be achieved with testcafe's configuration, or another way?
// tsconfig.json
{
"compilerOptions": {
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
"@page-model/*": [
"page-model/*",
]
}
}
}
// test-file.ts
import { Home } from '@page-model/home'
The error I receive when running testcafe chrome test-file.ts
is that it cannot find the module I am referencing. Obviously due to the fact it's not being transformed.
Upvotes: 4
Views: 1345
Reputation: 6318
It looks like an issue with the TypeScript module resolution and NodeJS, not with TestCafe.
I created a sample that demonstrates the issue without TestCafe. Please see the following code:
index.ts
function log(t:any) {
console.log(t);
}
log(require('@page-model/model').HEADER);
tsconfig.json
{
"compilerOptions": {
"baseUrl": "models",
"paths": {
"@page-model/*": [ "main/*" ]
},
"noImplicitAny": true
}
}
I compiled the index.ts
file with the tsc
util and got the following js code:
index.js
function log(t) {
console.log(t);
}
log(require('@page-model/model').HEADER);
The path was not resolved by the TS compiler. I searched for possible solutions on the StackOverflow and they recommend trying the https://www.npmjs.com/package/tsconfig-paths module.
Upvotes: 1