[英]How to make testcafe work with absolute imports?
I have a create react app 3 project,我有一个 create react app 3 项目,
so I have in my src folders some js scripts using like:所以我在我的 src 文件夹中有一些 js 脚本,使用如下:
import { Foo } from 'components/layout/Foo
Unfortunately, the testcafe compiler complains about it by default.不幸的是,testcafe 编译器默认会抱怨它。 I read that maybe the solution was to create specify a custom tsconfig.json in which I declare
我读到也许解决方案是创建一个自定义的 tsconfig.json 我在其中声明
{
"compilerOptions": {
"baseUrl: "src"
}
}
But it does not work, apparently.但它显然不起作用。 Thanks.
谢谢。
Sorry, indeed it is not a component file, but a utils one in the src directory.抱歉,确实不是组件文件,而是 src 目录中的 utils 文件。
in my foo_test.js I have在我的 foo_test.js 我有
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 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/'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.