Skip to content

Commit

Permalink
Setup testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktSeidlSWM committed Jun 19, 2024
1 parent 4bb6d63 commit b256f91
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 10 deletions.
13 changes: 11 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
parser: "@babel/eslint-parser", // https://github.com/babel/babel/tree/main/eslint/babel-eslint-parser
parserOptions: {
babelOptions: {
configFile: "./.babelrc.json"
configFile: "./babel.config.json"
},
ecmaFeatures: {
arrowFunctions: true,
Expand All @@ -25,7 +25,10 @@ module.exports = {
},
plugins: [
"perfectionist", // https://github.com/azat-io/eslint-plugin-perfectionist
"react" // https://github.com/yannickcr/eslint-plugin-react
"react", // https://github.com/yannickcr/eslint-plugin-react
"jest", // https://github.com/jest-community/eslint-plugin-jest
"jest-dom", // https://github.com/testing-library/eslint-plugin-jest-dom
"testing-library" // https://github.com/testing-library/eslint-plugin-testing-library
],
extends: [
"eslint:recommended",
Expand All @@ -36,6 +39,12 @@ module.exports = {
browser: true, // browser global variables
node: true // Node.js global variables and Node.js-specific rules
},
overrides: [
{
files: ["tests/**/*"],
env: { jest: true }
}
],
settings: {
react: {
version: "detect"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules/
coverage/
.idea/
npm-debug.log

# On a fresh install with yarn 3.3.0 these extra files were generated.
Expand Down
7 changes: 1 addition & 6 deletions .babelrc.json → babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
"@babel/plugin-transform-object-rest-spread"
],
"presets": [
[
"@babel/preset-env",
{
"modules": false
}
],
"@babel/preset-env",
"@babel/preset-react"
]
}
20 changes: 20 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"collectCoverageFrom": [
"./**/*.{js,jsx}"
],
"coverageDirectory": "coverage",
"moduleNameMapper": {
"^openlayers$": "<rootDir>/libs/openlayers.js",
"\\.(css|less|svg|png)$": "<rootDir>/tests/mocks/AssetMock.js"
},
"setupFilesAfterEnv": [
"<rootDir>/tests/jest.setup.js"
],
"testEnvironment": "jsdom",
"testMatch": [
"<rootDir>/tests/**/*.test.(js|jsx|ts|tsx)"
],
"transformIgnorePatterns": [
"node_modules/(?!(color-name|color-parse|color-rgba|color-space|flat|ol|ol-ext)/)"
]
}
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,28 @@
"@babel/preset-env": "^7.24.5",
"@babel/preset-react": "^7.24.1",
"@furkot/webfonts-generator": "^2.0.2",
"@testing-library/dom": "^10.1.0",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^16.0.0",
"@types/react": "^18.3.1",
"eslint": "^8.56.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-jest-dom": "^5.4.0",
"eslint-plugin-perfectionist": "^2.10.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-testing-library": "^6.2.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"mkdirp": "^3.0.1",
"object-path": "^0.11.8",
"react-docgen": "^5.4.3",
"redux-mock-store": "^1.5.4",
"typescript": "^5.4.5"
},
"scripts": {
"plugindoc": "node scripts/gen-plugin-docs.js"
"plugindoc": "node scripts/gen-plugin-docs.js",
"lint": "eslint . --config .eslintrc.js --ext .js,.jsx,.ts,.tsx",
"test": "jest",
"coverage": "jest --coverage"
}
}
1 change: 1 addition & 0 deletions tests/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom';
5 changes: 5 additions & 0 deletions tests/libs/openlayers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ol from 'openlayers';

test('import openlayers', () => {
expect(ol).not.toBe(undefined);
});
1 change: 1 addition & 0 deletions tests/mocks/AssetMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};

0 comments on commit b256f91

Please sign in to comment.