I'm running to this error:
Could not locate module @@/umiExports mapped as:'[Myrootdirectory]\node_modules\umiExports.,
I'm using 'Umi.js' library with 'Jest' unit tests, all my unit tests are working fine both but yesterday I created this test which wouldn't run correctly it shows the error shared above
this is my new unit test file inside folder structure: src/pages/Admin/components which already contains some other tests that are working fine:
import '@testing-library/jest-dom';
import { shallow } from 'enzyme';
import Customers from '../Customers';
jest.mock('umi-plugin-react/locale');
const mockedDispatch = jest.fn(() => {});
const Customer = {
list: [],
currentCustomer: {
id: 'f6cf775f-0770-45af-0869-08d842b30965',
createDate: '0001-01-01T00:00:00',
createdByUser: null,
updatedDate: '0001-01-01T00:00:00',
updatedByUser: null,
useDefaultFrontEndSettings: true,
useDefaultEmailTemplates: false,
useDefaultGeneralSettings: true,
name: 'SalesLabNordic',
displayName: null,
address1: null,
address2: null,
postalCodeID: 0,
phone: null,
contactEmail: null,
contactPerson: 'Søren Lundsgaard Jensen',
webSite: null,
cvr: 0,
bankName: null,
regNo: 0,
accountNo: 0,
swiftCode: 0,
ibanNo: null,
signature: null,
companyLogoImageUploadFileId: '00000000-0000-0000-0000-000000000000',
},
};
describe('test customers component', () => {
const renderElement = (
<Customers.WrappedComponent dispatch={mockedDispatch} customer={Customer} loading submitting />
);
it('should render properly', () => {
shallow(renderElement);
});
});
my config files:
jest.config.js:
roots: ['<rootDir>'],
testMatch: ['**/src/**/*.test.(js|jsx|ts|tsx)'],
collectCoverageFrom: ['**/src/**/*', '!**/src/**/*.test.(js|jsx|ts|tsx)'],
globals: {
__UMI_HTML_SUFFIX: false,
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'^@@/(.*)$': '<rootDir>/node_modules/$1',
},
moduleDirectories: ['node_modules', './'],
moduleFileExtensions: ['js', 'jsx'],
};
tsconfig.json
{
"compilerOptions": {
"outDir": "build/dist",
"module": "esnext",
"target": "es2016",
"lib": ["es6", "dom"],
"sourceMap": true,
"baseUrl": ".",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"rootDirs": ["/src", "/test", "/mock", "./typings"],
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowJs": true,
"experimentalDecorators": true,
"paths": {
"@/*": ["./src/*"]
},
"checkJs": true
},
"include": ["./src"],
"exclude": [
"node_modules",
"build",
"scripts",
"acceptance-tests",
"webpack",
"jest",
"src/setupTests.ts",
"tslint:latest",
"tslint-config-prettier"
]
}
jsconfig.json
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"baseUrl": ".",
"checkJs": true,
"paths": {
"@/*": ["./src/*"]
}
}
}
I tried the bunch of answers found on the internet, such as :
changing the moduleNameMapper part of my 'jest.config' by adding the path in my tsconfig
as follows:
moduleNameMapper: {
'@/*': '<rootDir>/src/$1',
'^@/(.*)$': '<rootDir>/src/$1',
'^@@/(.*)$': '<rootDir>/node_modules/$1',
},
still didn't work for me at all.