javascript - ¿Cómo hacer que testcafe funcione con importaciones absolutas?
Tengo un proyecto de create react app 3,
así que tengo en mis carpetas src algunos scripts js usando como:
import { Foo } from 'components/layout/Foo
Desafortunadamente, el compilador de testcafe se queja de ello por defecto. Leí que tal vez la solución era crear y especificar un tsconfig.json personalizado en el que declarara
{
"compilerOptions": {
"baseUrl: "src"
}
}
Pero aparentemente no funciona. Gracias.
Respuesta #1
Lo siento, en efecto no es un archivo de componente, sino uno de utilidades en el directorio src.
en mi foo_test.js tengo
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')
})
dónde está utils/config
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/'
