Skip to content

Commit

Permalink
test: Update jest,Jenkinsfile,lint to volto-addons-template PR30
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinab25 committed Jan 24, 2024
1 parent a70001e commit 6c2690c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Jest configuration variables
# - possible values: ON, OFF
JEST_USE_SETUP=OFF
55 changes: 55 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const fs = require('fs');
const path = require('path');

const projectRootPath = fs.existsSync('./project')
? fs.realpathSync('./project')
: fs.realpathSync('./../../../');
const packageJson = require(path.join(projectRootPath, 'package.json'));
const jsConfig = require(path.join(projectRootPath, 'jsconfig.json')).compilerOptions;

const pathsConfig = jsConfig.paths;

let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto');

Object.keys(pathsConfig).forEach(pkg => {
if (pkg === '@plone/volto') {
voltoPath = `./${jsConfig.baseUrl}/${pathsConfig[pkg][0]}`;
}
});
const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`);
const reg = new AddonConfigurationRegistry(projectRootPath);

// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons
const addonAliases = Object.keys(reg.packages).map(o => [
o,
reg.packages[o].modulePath,
]);


module.exports = {
extends: `${projectRootPath}/node_modules/@plone/volto/.eslintrc`,
settings: {
'import/resolver': {
alias: {
map: [
['@plone/volto', '@plone/volto/src'],
...addonAliases,
['@package', `${__dirname}/src`],
['~', `${__dirname}/src`],
],
extensions: ['.js', '.jsx', '.json'],
},
'babel-plugin-root-import': {
rootPathSuffix: 'src',
},
},
},
rules: {
'react/jsx-no-target-blank': [
'error',
{
allowReferrer: true,
},
],
}
};
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.vscode/
.history
.eslintrc.js
.nyc_output
project
coverage
Expand Down
12 changes: 8 additions & 4 deletions jest-addon.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('dotenv').config({ path: __dirname + '/.env' })

module.exports = {
testMatch: ['**/src/addons/**/?(*.)+(spec|test).[jt]s?(x)'],
collectCoverageFrom: [
Expand Down Expand Up @@ -38,7 +40,9 @@ module.exports = {
statements: 5,
},
},
setupFilesAfterEnv: [
'<rootDir>/node_modules/@eeacms/volto-accordion-block/jest.setup.js',
],
};
...(process.env.JEST_USE_SETUP === 'ON' && {
setupFilesAfterEnv: [
'<rootDir>/node_modules/@eeacms/volto-accordion-block/jest.setup.js',
],
}),
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"babel-plugin-transform-class-properties": "^6.24.1",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"md5": "^2.3.0"
"md5": "^2.3.0",
"dotenv": "^16.3.2"
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json}": [
Expand Down

0 comments on commit 6c2690c

Please sign in to comment.