generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Update jest,Jenkinsfile,lint to volto-addons-template PR30
- Loading branch information
valentinab25
committed
Jan 24, 2024
1 parent
21271e9
commit da3e7c3
Showing
8 changed files
with
155 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
], | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
.vscode/ | ||
.history | ||
.eslintrc.js | ||
.nyc_output | ||
project | ||
coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { jest } from '@jest/globals'; | ||
import configureStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import { blocksConfig } from '@plone/volto/config/Blocks'; | ||
import installSlate from '@plone/volto-slate/index'; | ||
|
||
var mockSemanticComponents = jest.requireActual('semantic-ui-react'); | ||
var mockComponents = jest.requireActual('@plone/volto/components'); | ||
var config = jest.requireActual('@plone/volto/registry').default; | ||
|
||
config.blocks.blocksConfig = { | ||
...blocksConfig, | ||
...config.blocks.blocksConfig, | ||
}; | ||
|
||
jest.doMock('semantic-ui-react', () => ({ | ||
__esModule: true, | ||
...mockSemanticComponents, | ||
Popup: ({ content, trigger }) => { | ||
return ( | ||
<div className="popup"> | ||
<div className="trigger">{trigger}</div> | ||
<div className="content">{content}</div> | ||
</div> | ||
); | ||
}, | ||
})); | ||
|
||
jest.doMock('@plone/volto/components', () => { | ||
return { | ||
__esModule: true, | ||
...mockComponents, | ||
SidebarPortal: ({ children }) => <div id="sidebar">{children}</div>, | ||
}; | ||
}); | ||
|
||
jest.doMock('@plone/volto/registry', () => | ||
[installSlate].reduce((acc, apply) => apply(acc), config), | ||
); | ||
|
||
const mockStore = configureStore([thunk]); | ||
|
||
global.fetch = jest.fn(() => | ||
Promise.resolve({ | ||
json: () => Promise.resolve({}), | ||
}), | ||
); | ||
|
||
global.store = mockStore({ | ||
intl: { | ||
locale: 'en', | ||
messages: {}, | ||
formatMessage: jest.fn(), | ||
}, | ||
content: { | ||
create: {}, | ||
subrequests: [], | ||
}, | ||
connected_data_parameters: {}, | ||
screen: { | ||
page: { | ||
width: 768, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters