my project was created with the swdc create-project ...
Is there a documentation, a tutorial or description for the right setup/configuration unit testing with JEST for custom plugin in administration?
This tutorial describes only how to write a test
But i think there must be a official setup documentation because of versions etc.
CodePudding user response:
I think it is easiest to just copy and adapt from a plugin that already has jest tests set up. Look at the administration
directory for SwagPayPal
for example. Copy the dependency and script sections from their package.json
. Also copy the entire jest.config.js
. Then within the administration
directory of your plugin you should be able to npm install
followed by npm run unit
or npm run unit-watch
and it should find *.spec.js
files within the test
sub-directory.
CodePudding user response:
Using the suggested solution and execute the test, throws an configuration error:
● Test suite failed to run
Configuration error:
Could not locate module src/core/factory/module.factory mapped as:
undefined/src$1.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^src(.*)$/": "undefined/src$1"
},
"resolver": undefined
}
...
Cause of error:
process.env.ADMIN_PATH
not setted but required in %Project%/custom/plugins/%MyPlugin%/src/Resources/app/administration/node_modules/@shopware-ag/jest-preset-sw6-admin/jest-preset.js
My solution:
set process.env.ADMIN_PATH
in %Project%/custom/plugins/%MyPlugin%/src/Resources/app/administration/jest.config.js
// jest.config.js
...
const { join, resolve } = require('path');
process.env.ADMIN_PATH = resolve('../../../../../../../src/Administration/Resources/app/administration');
...