Default Jest preset for Shopware 6 administration development.
npm install jest @shopware-ag/jest-preset-sw6-admin @babel/preset-env @babel/plugin-proposal-class-properties --save-dev
After installaing the necessary required packages, please create a file called babel.config.json
right next to your own package.json
with the following content:
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-class-properties"]
}
Next up, create a file jest.config.js
which should contain the following content:
module.exports = {
preset: '@shopware-ag/jest-preset-sw6-admin',
globals: {
adminPath: '<file-path-to-sw6-administration>', // required, e.g. /www/sw6/platform/src/Administration/Resources/app/administration
}
}
collectCoverage
- Code coverage will be generated using the reporters listed undercoverageReporters
coverageReporters
- The presets useslcov
,text
&clover
as coverage reporterswatchPathIgnorePatterns
- Ignores thenode_modules
folder for the watch mode of JestclearMocks
- Automatically clear mock calls and instances before every test.moduleFileExtensions
- File with the extensionjs
will automatically used as extensions your module use.moduleNameMapper
- Allcss
,less
&scss
files will be mocked and relative paths tosrc
are getting mapped to the correct src directorytransform
- Transformsjs
files using babel-jest andtwig
files are transformed using a custom twig transformer which we use in the administration as wellmodulePathIgnorePatterns
- Ignores e2e test specs by defaultsetupFilesAfterEnv
- Provides a polyfill for Webpack'require.context
and sets up the global Shopware third-party interface for every test. The object can be accessed usingglobal.Shopware
in test files.testMatch
- Matches all files containing.spec.js
in the test directory