Skip to content

Commit 42c89fa

Browse files
author
valentinab25
committed
test: Update jest,Jenkinsfile,lint to volto-addons-template PR30
1 parent ae18833 commit 42c89fa

File tree

5 files changed

+70
-6
lines changed

5 files changed

+70
-6
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Jest configuration variables
2+
# - possible values: ON, OFF
3+
JEST_USE_SETUP=OFF

.eslintrc.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const projectRootPath = fs.existsSync('./project')
5+
? fs.realpathSync('./project')
6+
: fs.realpathSync('./../../../');
7+
const packageJson = require(path.join(projectRootPath, 'package.json'));
8+
const jsConfig = require(path.join(projectRootPath, 'jsconfig.json')).compilerOptions;
9+
10+
const pathsConfig = jsConfig.paths;
11+
12+
let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto');
13+
14+
Object.keys(pathsConfig).forEach(pkg => {
15+
if (pkg === '@plone/volto') {
16+
voltoPath = `./${jsConfig.baseUrl}/${pathsConfig[pkg][0]}`;
17+
}
18+
});
19+
const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`);
20+
const reg = new AddonConfigurationRegistry(projectRootPath);
21+
22+
// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons
23+
const addonAliases = Object.keys(reg.packages).map(o => [
24+
o,
25+
reg.packages[o].modulePath,
26+
]);
27+
28+
29+
module.exports = {
30+
extends: `${projectRootPath}/node_modules/@plone/volto/.eslintrc`,
31+
settings: {
32+
'import/resolver': {
33+
alias: {
34+
map: [
35+
['@plone/volto', '@plone/volto/src'],
36+
...addonAliases,
37+
['@package', `${__dirname}/src`],
38+
['~', `${__dirname}/src`],
39+
],
40+
extensions: ['.js', '.jsx', '.json'],
41+
},
42+
'babel-plugin-root-import': {
43+
rootPathSuffix: 'src',
44+
},
45+
},
46+
},
47+
rules: {
48+
'react/jsx-no-target-blank': [
49+
'error',
50+
{
51+
allowReferrer: true,
52+
},
53+
],
54+
}
55+
};

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.vscode/
22
.history
3-
.eslintrc.js
43
.nyc_output
54
project
65
coverage

jest-addon.config.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require('dotenv').config({ path: __dirname + '/.env' })
2+
13
module.exports = {
24
testMatch: ['**/src/addons/**/?(*.)+(spec|test).[jt]s?(x)'],
35
collectCoverageFrom: [
@@ -13,6 +15,8 @@ module.exports = {
1315
'@root/(.*)$': '<rootDir>/node_modules/@plone/volto/src/$1',
1416
'@plone/volto-quanta/(.*)$': '<rootDir>/src/addons/volto-quanta/src/$1',
1517
'@eeacms/(.*?)/(.*)$': '<rootDir>/node_modules/@eeacms/$1/src/$2',
18+
'@plone/volto-slate$':
19+
'<rootDir>/node_modules/@plone/volto/packages/volto-slate/src',
1620
'@plone/volto-slate/(.*)$':
1721
'<rootDir>/node_modules/@plone/volto/packages/volto-slate/src/$1',
1822
'~/(.*)$': '<rootDir>/src/$1',
@@ -36,7 +40,9 @@ module.exports = {
3640
statements: 5,
3741
},
3842
},
39-
setupFilesAfterEnv: [
40-
'<rootDir>/node_modules/@eeacms/volto-block-style/jest.setup.js',
41-
],
42-
};
43+
...(process.env.JEST_USE_SETUP === 'ON' && {
44+
setupFilesAfterEnv: [
45+
'<rootDir>/node_modules/@eeacms/volto-block-style/jest.setup.js',
46+
],
47+
}),
48+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"husky": "^8.0.3",
3333
"lint-staged": "^14.0.1",
3434
"md5": "^2.3.0",
35-
"postcss-less": "6.0.0"
35+
"postcss-less": "6.0.0",
36+
"dotenv": "^16.3.2"
3637
},
3738
"lint-staged": {
3839
"src/**/*.{js,jsx,ts,tsx,json}": [

0 commit comments

Comments
 (0)