How to make testcafe work with absolute imports?

Viewed 505

I have a create react app 3 project,

so I have in my src folders some js scripts using like:

import { Foo } from 'components/layout/Foo

Unfortunately, the testcafe compiler complains about it by default. I read that maybe the solution was to create specify a custom tsconfig.json in which I declare

{
  "compilerOptions": {
    "baseUrl: "src"
  }
}

But it does not work, apparently. Thanks.

1 Answers

Sorry, indeed it is not a component file, but a utils one in the src directory.

in my foo_test.js I have

import { ROOT_PATH } from '../src/utils/config'

fixture("00 Home | Arriving to the Home").page(ROOT_PATH)

test('Default | leads to the home page', async t => {
    const location = await t.eval(() => window.location)
    await t.expect(location.pathname).eql('/home')
})

where utils/config is

import { getMobileOperatingSystem } from 'utils/mobile'

export const MOBILE_OS = getMobileOperatingSystem()

let CALC_ROOT_PATH
if (MOBILE_OS === 'ios') {
   document.body.className += ' cordova-ios'
   CALC_ROOT_PATH = window.location.href.match(/file:\/\/(.*)\/www/)[0]
}

export const ROOT_PATH = CALC_ROOT_PATH || 'http://localhost:3000/'
Related