Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration test(s) for Web #10563

Merged
merged 11 commits into from Aug 7, 2022
1 change: 1 addition & 0 deletions .eslintignore
@@ -1 +1,2 @@
dist/*
test/integration/react-browser/*
11 changes: 9 additions & 2 deletions test/integration/integration-test.cjs
Expand Up @@ -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',
Expand All @@ -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');
Expand All @@ -42,5 +47,7 @@ describe('Integration Tests', () => {
}).timeout(5 * 60 * 1000);
}

testOnNodeProject('node');
for (const platform of platforms) {
testProjectOnPlatform(platform)
}
});
26 changes: 26 additions & 0 deletions test/integration/react-browser/package.json
@@ -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"
]
}
}
36 changes: 36 additions & 0 deletions test/integration/react-browser/public/index.html
@@ -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>
30 changes: 30 additions & 0 deletions test/integration/react-browser/src/App.js
@@ -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;
10 changes: 10 additions & 0 deletions test/integration/react-browser/src/index.js
@@ -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>
);