Open moehrenzahn opened 4 years ago
I can get it to work when adding the ADMIN_PATH
env variable myself to the environment:
(cd src/Resources/app/administration/ && npm install && ADMIN_PATH='/myProject/vendor/shopware/platform/src/Administration/Resources/app/administration' npm test)
This works. Using a relative ADMIN_PATH
does not work. Putting the full path into jest.config.js
also does not work.
Thanks for the information, I'm taking care of it 👍
I can get it to work when adding the
ADMIN_PATH
env variable myself to the environment:(cd src/Resources/app/administration/ && npm install && ADMIN_PATH='/myProject/vendor/shopware/platform/src/Administration/Resources/app/administration' npm test)
This works. Using a relative
ADMIN_PATH
does not work. Putting the full path intojest.config.js
also does not work.
Can you provide the full working configuration?
I try to execute the test from the cli, but it does retrun the same error
rammi@rammi-Akoya-P5105-D-MD8856-2414:~/My/Local/Path/custom/plugins/MyPlugin/src/Resources/app/administration$ (npm install && ADMIN_PATH='/My/Local/Path/vendor/shopware/platform/src/Administration/Resources/app/administration' npm test)
returns error
...
Configuration error:
Could not locate module src/core/factory/module.factory mapped as:
/My/Local/Path/custom/plugins/MyPlugin/src/Resources/app/administration/src$1.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^src(.*)$/": "/My/Local/Path/custom/plugins/MyPlugin/src/Resources/app/administration/src$1"
},
"resolver": undefined
}
// jest.config.js
module.exports = {
preset: '@shopware-ag/jest-preset-sw6-admin',
globals: {
adminPath: '../../../../../../../vendor/shopware/platform/src/Administration/Resources/app/administration'
}
}
// babel.config.json
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-class-properties"]
}
With following steps it works for me:
// package.json
...
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/preset-env": "^7.11.5",
"@shopware-ag/jest-preset-sw6-admin": "^1.1.1",
"@vue/test-utils": "^1.1.0",
"babel-plugin-module-resolver": "^4.0.0",
"jest": "^26.4.2",
"vue-jest": "^3.0.7"
},
"dependencies": {
"test": "^0.6.0",
"vue": "^2.6.12",
"vue-template-compiler": "^2.6.12"
}
...
// jest.config.js
module.exports = {
preset: '@shopware-ag/jest-preset-sw6-admin',
globals: {
// required, e.g. /www/sw6/platform/src/Administration/Resources/app/administration
adminPath: "/Project/vendor/shopware/platform/src/Administration/Resources/app/administration"
},
moduleNameMapper: {
'^src(.*)$': '/Project/vendor/shopware/platform/src/Administration/Resources/app/administration/src$1'
},
}
// babel.config.json
{
"presets": ["@babel/preset-env"],
"plugins": [
"@babel/plugin-proposal-class-properties",
["module-resolver", {
"root": ["./src"],
"alias": {
"/src": "./src"
}
}]
]
}
// index.spec.js (the test file)
import { shallowMount } from "@vue/test-utils";
import '/src/module/myplugin/view/mycomponent';
describe('view/mycomponent', () => {
let wrapper;
beforeEach(() => {
wrapper = shallowMount(Shopware.Component.build('mycomponent'));
});
afterEach(() => {
wrapper.destroy();
});
it('should be a Vue.js component', () => {
expect(wrapper.isVueInstance()).toBeTruthy();
})
})
Hey everyone, I'm trying to run administration jest tests for my SW6 plugin located at custom/plugins.
I am running into the following error when running a test via jest:
This is my package.json:
And my jest.config.js:
And my babel.config.json:
Any help would be appreciated, I also wouldn't rule out that I'm doing something wrong!