I'm writing a UI page object model testing project in TypeScript and I'm trying my best to avoid hideous nested imports.
I found the paths object for the .tsconfig file that fixes the issue in .ts files, but, because I compile into an outDir, my compiled .js files cannot resolve the module path.
I develop in a model directory and compile into a src directory.
I've set up my .tsconfig file as follows
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"noImplicitAny": false,
"outDir": "src/",
"baseUrl": "./model/",
"paths": {
"general.utils": [ "lib/general/general.utils" ],
"pretest.setup": [ "lib/pretest.setup/pretest.setup" ],
"tpapi": [ "lib/tpapi/tpapi" ],
"*": [ "*" ]
}
},
"exclude": [
"node_modules"
],
"compileOnSave": false
}
That paths allows me to
import { chooseRandomValueFrom } from 'general.utils';
from a .ts file that is in model, but won't resolve in a .js file in src.
This is an npm type project that is run with npm test. That command executes a script that compiles, runs tests from, and deletes the src directory.
#!/bin/bash
npm run compile:ts
node_modules/webdriverio/bin/wdio
npm run clean:ts