]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Add integration test(s) for Web (#10563)
authorJacco van den Berg <jaccoberg2281@gmail.com>
Sun, 7 Aug 2022 17:25:11 +0000 (19:25 +0200)
committerGitHub <noreply@github.com>
Sun, 7 Aug 2022 17:25:11 +0000 (13:25 -0400)
Adds a basic react integration test

.eslintignore
test/integration/integration-test.cjs
test/integration/react-browser/package.json [new file with mode: 0644]
test/integration/react-browser/public/index.html [new file with mode: 0644]
test/integration/react-browser/src/App.js [new file with mode: 0644]
test/integration/react-browser/src/index.js [new file with mode: 0644]

index a261f291755404ef0ada9e519a6bf80c8172d305..15caa4d611871cecbbcd432f04bce6f121b91696 100644 (file)
@@ -1 +1,2 @@
 dist/*
+test/integration/react-browser/*
index 1d841cc6a1896c4b19a4b45cc28a905a9e51448d..560cde977c66066c4b0a5717bbb68e7373f2b078 100644 (file)
@@ -7,6 +7,11 @@ const childProcess = require('child_process');
 
 const {describe, it} = require('mocha');
 
+const platforms = [
+  'node',
+  'react-browser'
+];
+
 function exec(command, options = {}) {
   const output = childProcess.execSync(command, {
     encoding: 'utf-8',
@@ -27,7 +32,7 @@ describe('Integration Tests', () => {
     path.join(tmpDir, 'package.tgz'),
   );
 
-  function testOnNodeProject(projectName) {
+  function testProjectOnPlatform(projectName) {
     const projectPath = path.join(__dirname, projectName);
 
     const packageJSONPath = path.join(projectPath, 'package.json');
@@ -42,5 +47,7 @@ describe('Integration Tests', () => {
     }).timeout(5 * 60 * 1000);
   }
 
-  testOnNodeProject('node');
+  for (const platform of platforms) {
+    testProjectOnPlatform(platform)
+  }
 });
diff --git a/test/integration/react-browser/package.json b/test/integration/react-browser/package.json
new file mode 100644 (file)
index 0000000..b8a131f
--- /dev/null
@@ -0,0 +1,26 @@
+{
+  "private": true,
+  "description": "chart.js should work in react-browser (Web)",
+  "dependencies": {
+    "chart.js": "file:../package.tgz",
+    "react": "^18.2.0",
+    "react-dom": "^18.2.0",
+    "react-scripts": "5.0.1",
+    "web-vitals": "^2.1.4"
+  },
+  "scripts": {
+    "test": "react-scripts build"
+  },
+  "browserslist": {
+    "production": [
+      ">0.2%",
+      "not dead",
+      "not op_mini all"
+    ],
+    "development": [
+      "last 1 chrome version",
+      "last 1 firefox version",
+      "last 1 safari version"
+    ]
+  }
+}
diff --git a/test/integration/react-browser/public/index.html b/test/integration/react-browser/public/index.html
new file mode 100644 (file)
index 0000000..3051d24
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1" />
+    <meta name="theme-color" content="#000000" />
+    <meta
+      name="description"
+      content="Web site created using create-react-app"
+    />
+    <!--
+      Notice the use of %PUBLIC_URL% in the tags above.
+      It will be replaced with the URL of the `public` folder during the build.
+      Only files inside the `public` folder can be referenced from the HTML.
+
+      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
+      work correctly both with client-side routing and a non-root public URL.
+      Learn how to configure a non-root public URL by running `npm run build`.
+    -->
+    <title>Chartjs test React App</title>
+  </head>
+  <body>
+    <noscript>You need to enable JavaScript to run this app.</noscript>
+    <div id="root"></div>
+    <!--
+      This HTML file is a template.
+      If you open it directly in the browser, you will see an empty page.
+
+      You can add webfonts, meta tags, or analytics to this file.
+      The build step will place the bundled scripts into the <body> tag.
+
+      To begin the development, run `npm start` or `yarn start`.
+      To create a production bundle, use `npm run build` or `yarn build`.
+    -->
+  </body>
+</html>
diff --git a/test/integration/react-browser/src/App.js b/test/integration/react-browser/src/App.js
new file mode 100644 (file)
index 0000000..3f27816
--- /dev/null
@@ -0,0 +1,30 @@
+import { useEffect } from 'react';
+import {Chart, DoughnutController, ArcElement} from 'chart.js';
+import {merge} from 'chart.js/helpers';
+
+Chart.register(DoughnutController, ArcElement);
+
+function App() {
+  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 App;
diff --git a/test/integration/react-browser/src/index.js b/test/integration/react-browser/src/index.js
new file mode 100644 (file)
index 0000000..593edf1
--- /dev/null
@@ -0,0 +1,10 @@
+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>
+);