Skip to content

Commit eb01cf8

Browse files
authored
Merge pull request #121 from InetIntel/116-setup-testing
116: setup testing
2 parents 7601314 + bc657cd commit eb01cf8

File tree

9 files changed

+2640
-84
lines changed

9 files changed

+2640
-84
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import '@testing-library/dom'
2+
import '@testing-library/jest-dom/extend-expect';
3+
import React from 'react'
4+
import { render, act, screen } from '@testing-library/react'
5+
import ChartTabCard from './ChartTabCard'
6+
import { HashRouter } from "react-router-dom";
7+
8+
jest.mock('./ChartLegendCard', () => () => <div>ChartLegendCard</div>)
9+
const ChartTabCardWrapper = () => <HashRouter><ChartTabCard /></HashRouter>
10+
11+
describe('ChartTabChart', () => {
12+
it('is fine', async () => {
13+
render(<ChartTabCardWrapper />)
14+
15+
expect(screen.getByText('ChartLegendCard')).toBeInTheDocument()
16+
})
17+
})

babel.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = function (api) {
2+
const presets = ["@babel/preset-react", "@babel/preset-env"];
3+
const plugins = [
4+
"transform-class-properties",
5+
"syntax-dynamic-import",
6+
"@babel/plugin-proposal-object-rest-spread",
7+
"istanbul",
8+
];
9+
10+
// Cache the Babel configuration based on the environment
11+
api.cache.using(() => process.env.NODE_ENV);
12+
13+
return {
14+
presets,
15+
plugins,
16+
};
17+
};

jest-puppeteer.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// jest-puppeteer.config.cjs
2+
3+
/** @type {import('jest-environment-puppeteer').JestPuppeteerConfig} */
4+
module.exports = {
5+
launch: {
6+
headless: "new",
7+
product: "chrome",
8+
},
9+
browserContext: "default",
10+
};

jest.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
moduleFileExtensions: ["js", "jsx", "json", "node"],
3+
preset: "jest-puppeteer",
4+
testEnvironment: "jsdom",
5+
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$",
6+
transform: {
7+
"\\.[jt]sx?$": "babel-jest",
8+
},
9+
};
10+

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ module.exports = function (config) {
2929
type: 'text'
3030
}
3131
});
32-
};
32+
};

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@
22
"devDependencies": {
33
"@babel/core": "^7.20.7",
44
"@babel/eslint-parser": "^7.19.1",
5+
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
56
"@babel/preset-react": "^7.18.6",
67
"@symfony/webpack-encore": "^0.30.2",
8+
"@testing-library/jest-dom": "5.11.6",
9+
"@testing-library/react": "12.1.0",
710
"autoprefixer": "^9.8.4",
811
"babel-cli": "^6.26.0",
912
"babel-plugin-istanbul": "^5.0.1",
1013
"babel-plugin-syntax-dynamic-import": "^6.18.0",
1114
"babel-plugin-transform-class-properties": "^6.24.1",
12-
"babel-plugin-transform-object-rest-spread": "^6.26.0",
1315
"babel-polyfill": "^6.26.0",
1416
"babel-preset-env": "^1.7.0",
1517
"babel-preset-react": "^6.24.1",
1618
"babel-register": "^6.26.0",
1719
"chai": "^4.2.0",
1820
"copy-webpack-plugin": "^4.5.4",
1921
"es-check": "^6.0.0",
22+
"jest": "^29.7.0",
23+
"jest-environment-jsdom": "^29.7.0",
24+
"jest-image-snapshot": "^6.4.0",
25+
"jest-puppeteer": "^10.0.1",
2026
"karma": "^3.0.0",
2127
"karma-chai": "^0.1.0",
2228
"karma-chrome-launcher": "^2.2.0",
@@ -26,6 +32,8 @@
2632
"node-sass": "^8.0.0",
2733
"npm-run-all": "^4.1.5",
2834
"postcss-cli": "^7.1.1",
35+
"puppeteer": "19",
36+
"puppeteer-core": "19",
2937
"sass-lint-auto-fix": "^0.21.2",
3038
"yaml-loader": "^0.6.0"
3139
},
@@ -42,9 +50,7 @@
4250
"prefix:sass": "postcss --use autoprefixer -b \"last 10 versions\" assets/css/style.comp.css -o assets/css/style.prefix.css",
4351
"compress:css": "node-sass assets/css/style.prefix.css assets/css/style.css --output-style compressed",
4452
"build:css": "npm-run-all compile:sass prefix:sass compress:css",
45-
"test": "karma start --browsers FirefoxHeadless",
46-
"test:full": "karma start",
47-
"test:watch": "karma start --auto-watch --no-single-run --browsers FirefoxHeadless",
53+
"test": "jest",
4854
"lint": "sass-lint -v",
4955
"test:es-check": "es-check es5 'assets/js/Ioda/*.js'",
5056
"sitemap": "babel-node assets/js/Ioda/constants/sitemap/Generator.js"

templates/ioda.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<img width="180" src="/apple-touch-icon.png" alt="IODA logo" />
4848
</div>
4949
</div>
50+
<script src="{{ asset('build/runtime.js') }}"></script>
5051
<script>
5152
const div = document.querySelector('.contentLoading');
5253
/* documentMode is an IE-only property */

webpack.config.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ Encore
4949
// enables React support
5050
.enableReactPreset()
5151

52+
/*
53+
* Makes webpack consolidate the runtime logic into a single runtime chunk rather
54+
* than creating a separate runtime chunk for each entry chunk.
55+
*/
56+
.enableSingleRuntimeChunk()
57+
5258
// enables Sass/SCSS support
5359
//.enableSassLoader()
5460

@@ -58,12 +64,7 @@ Encore
5864
// uncomment if you're having problems with a jQuery plugin
5965
//.autoProvidejQuery()
6066

61-
.configureBabel(function (babelConfig) {
62-
babelConfig.plugins.push('transform-class-properties');
63-
babelConfig.plugins.push('syntax-dynamic-import');
64-
babelConfig.plugins.push('transform-object-rest-spread');
65-
babelConfig.plugins.push('istanbul');
66-
})
67+
.configureBabel()
6768
;
6869

6970
let webpackConfig = Encore.getWebpackConfig();

0 commit comments

Comments
 (0)