From: Jacco van den Berg Date: Thu, 18 Aug 2022 12:42:40 +0000 (+0200) Subject: Change react integration test to TS (#10605) X-Git-Tag: v4.0.0~52 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=49b16c967833534b6bad7b1f2b8a0df8f69368ad;p=thirdparty%2FChart.js.git Change react integration test to TS (#10605) * switch to ts * change web integration test to TS * remove space * lint things * one more lint * Add spaces --- diff --git a/test/integration/node/package-lock.json b/test/integration/node/package-lock.json deleted file mode 100644 index 1b503acf7..000000000 --- a/test/integration/node/package-lock.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "node", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "dependencies": { - "chart.js": "^3.8.2" - } - }, - "node_modules/chart.js": { - "version": "3.8.2", - "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-3.8.2.tgz", - "integrity": "sha512-7rqSlHWMUKFyBDOJvmFGW2lxULtcwaPLegDjX/Nu5j6QybY+GCiQkEY+6cqHw62S5tcwXMD8Y+H5OBGoR7d+ZQ==" - } - }, - "dependencies": { - "chart.js": { - "version": "3.8.2", - "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-3.8.2.tgz", - "integrity": "sha512-7rqSlHWMUKFyBDOJvmFGW2lxULtcwaPLegDjX/Nu5j6QybY+GCiQkEY+6cqHw62S5tcwXMD8Y+H5OBGoR7d+ZQ==" - } - } -} diff --git a/test/integration/react-browser/package.json b/test/integration/react-browser/package.json index b8a131f4d..a8a724b11 100644 --- a/test/integration/react-browser/package.json +++ b/test/integration/react-browser/package.json @@ -3,9 +3,13 @@ "description": "chart.js should work in react-browser (Web)", "dependencies": { "chart.js": "file:../package.tgz", + "@types/node": "^18.7.6", + "@types/react": "^18.0.17", + "@types/react-dom": "^18.0.6", "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "5.0.1", + "typescript": "^4.7.4", "web-vitals": "^2.1.4" }, "scripts": { diff --git a/test/integration/react-browser/src/App.js b/test/integration/react-browser/src/App.tsx similarity index 84% rename from test/integration/react-browser/src/App.js rename to test/integration/react-browser/src/App.tsx index 3f27816ac..a1ac021d8 100644 --- a/test/integration/react-browser/src/App.js +++ b/test/integration/react-browser/src/App.tsx @@ -1,4 +1,4 @@ -import { useEffect } from 'react'; +import React, {useEffect} from 'react'; import {Chart, DoughnutController, ArcElement} from 'chart.js'; import {merge} from 'chart.js/helpers'; @@ -7,7 +7,9 @@ Chart.register(DoughnutController, ArcElement); function App() { useEffect(() => { const c = Chart.getChart('myChart'); - if(c) c.destroy(); + if (c) { + c.destroy(); + } new Chart('myChart', { type: 'doughnut', @@ -17,8 +19,8 @@ function App() { data: [2, 3] }] } - }) - }, []) + }); + }, []); return (
diff --git a/test/integration/react-browser/src/AppAuto.tsx b/test/integration/react-browser/src/AppAuto.tsx new file mode 100644 index 000000000..404550dfe --- /dev/null +++ b/test/integration/react-browser/src/AppAuto.tsx @@ -0,0 +1,30 @@ +import React, {useEffect} from 'react'; +import Chart from 'chart.js/auto'; +import {merge} from 'chart.js/helpers'; + +function AppAuto() { + useEffect(() => { + const c = Chart.getChart('myChart'); + if (c) { + c.destroy(); + } + + new Chart('myChart', { + type: 'doughnut', + data: { + labels: ['Chart', 'JS'], + datasets: [{ + data: [2, 3] + }] + } + }); + }, []); + + return ( +
+ +
+ ); +} + +export default AppAuto; diff --git a/test/integration/react-browser/src/index.js b/test/integration/react-browser/src/index.js deleted file mode 100644 index 593edf121..000000000 --- a/test/integration/react-browser/src/index.js +++ /dev/null @@ -1,10 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom/client'; -import App from './App'; - -const root = ReactDOM.createRoot(document.getElementById('root')); -root.render( - - - -); diff --git a/test/integration/react-browser/src/index.tsx b/test/integration/react-browser/src/index.tsx new file mode 100644 index 000000000..7657c03b6 --- /dev/null +++ b/test/integration/react-browser/src/index.tsx @@ -0,0 +1,12 @@ +import React from 'react'; +import {render} from 'react-dom'; +import App from './App'; +import AppAuto from './AppAuto'; + +render( + + + + , + document.getElementById('root') +); diff --git a/test/integration/react-browser/tsconfig.json b/test/integration/react-browser/tsconfig.json new file mode 100644 index 000000000..584ba40bd --- /dev/null +++ b/test/integration/react-browser/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "jsx": "react", + "target": "ES6", + "moduleResolution": "Node", + "allowSyntheticDefaultImports": true, + "alwaysStrict": true, + "strict": true, + "noEmit": true + }, + "include": [ + "./**/*.tsx", + ] + }