]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Change react integration test to TS (#10605)
authorJacco van den Berg <jaccoberg2281@gmail.com>
Thu, 18 Aug 2022 12:42:40 +0000 (14:42 +0200)
committerGitHub <noreply@github.com>
Thu, 18 Aug 2022 12:42:40 +0000 (08:42 -0400)
* switch to ts

* change web integration test to TS

* remove space

* lint things

* one more lint

* Add spaces

test/integration/node/package-lock.json [deleted file]
test/integration/react-browser/package.json
test/integration/react-browser/src/App.tsx [moved from test/integration/react-browser/src/App.js with 84% similarity]
test/integration/react-browser/src/AppAuto.tsx [new file with mode: 0644]
test/integration/react-browser/src/index.js [deleted file]
test/integration/react-browser/src/index.tsx [new file with mode: 0644]
test/integration/react-browser/tsconfig.json [new file with mode: 0644]

diff --git a/test/integration/node/package-lock.json b/test/integration/node/package-lock.json
deleted file mode 100644 (file)
index 1b503ac..0000000
+++ /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=="
-    }
-  }
-}
index b8a131f4d6ab085fdae0074e38b851a0067583df..a8a724b114c33a7373add8b1ccf384223ae9ec3a 100644 (file)
@@ -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": {
similarity index 84%
rename from test/integration/react-browser/src/App.js
rename to test/integration/react-browser/src/App.tsx
index 3f27816ac9081f9d0fd4a5f5995d87938f655232..a1ac021d83fe3067444c772c84a97c047c47636a 100644 (file)
@@ -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 (
     <div className="App">
diff --git a/test/integration/react-browser/src/AppAuto.tsx b/test/integration/react-browser/src/AppAuto.tsx
new file mode 100644 (file)
index 0000000..404550d
--- /dev/null
@@ -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 (
+    <div className="App">
+      <canvas id="myChart"></canvas>
+    </div>
+  );
+}
+
+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 (file)
index 593edf1..0000000
+++ /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(
-  <React.StrictMode>
-    <App />
-  </React.StrictMode>
-);
diff --git a/test/integration/react-browser/src/index.tsx b/test/integration/react-browser/src/index.tsx
new file mode 100644 (file)
index 0000000..7657c03
--- /dev/null
@@ -0,0 +1,12 @@
+import React from 'react';
+import {render} from 'react-dom';
+import App from './App';
+import AppAuto from './AppAuto';
+
+render(
+  <React.StrictMode>
+    <App />
+    <AppAuto />
+  </React.StrictMode>,
+  document.getElementById('root')
+);
diff --git a/test/integration/react-browser/tsconfig.json b/test/integration/react-browser/tsconfig.json
new file mode 100644 (file)
index 0000000..584ba40
--- /dev/null
@@ -0,0 +1,14 @@
+{
+    "compilerOptions": {
+      "jsx": "react",
+      "target": "ES6",
+      "moduleResolution": "Node",
+      "allowSyntheticDefaultImports": true,
+      "alwaysStrict": true,
+      "strict": true,
+      "noEmit": true
+    },
+    "include": [
+      "./**/*.tsx",
+    ]
+  }