diff --git a/test/integration/integration-test.js b/test/integration/integration-test.js index 6fbcc42c3..1111c5e3d 100644 --- a/test/integration/integration-test.js +++ b/test/integration/integration-test.js @@ -7,6 +7,9 @@ const childProcess = require('child_process'); const {describe, it} = require('mocha'); +const npmVersionRegExp = new RegExp('^.*([0-9]+).([0-9]+).([0-9]+)$'); +const npmMajorVersion = (version) => npmVersionRegExp.exec(version)[1]; + function exec(command, options = {}) { const output = childProcess.execSync(command, { encoding: 'utf-8', @@ -15,32 +18,54 @@ function exec(command, options = {}) { return output && output.trimEnd(); } -describe('Integration Tests', () => { - const tmpDir = path.join(os.tmpdir(), 'chartjs-plugin-annotation-tmp'); - fs.rmSync(tmpDir, {recursive: true, force: true}); - fs.mkdirSync(tmpDir); +function getChartJsVersions(projectPath) { + const mainPackageJSONPath = path.join(projectPath, 'package.json'); + const mainPackageJSON = JSON.parse(fs.readFileSync(mainPackageJSONPath, 'utf-8')); + const dev = npmMajorVersion(mainPackageJSON.devDependencies['chart.js']); + const peer = npmMajorVersion(mainPackageJSON.peerDependencies['chart.js']); + const result = []; + for (let i = peer; i <= dev; i++) { + result.push(i + '.x.x'); + } + return result; +} +describe('Integration Tests', () => { const distDir = path.resolve('./'); - const archiveName = exec(`npm --quiet pack ${distDir}`, {cwd: tmpDir}); - fs.renameSync( - path.join(tmpDir, archiveName), - path.join(tmpDir, 'plugin.tgz'), - ); + const chartjsVersions = getChartJsVersions(distDir); + const baseTmpDir = path.join(os.tmpdir(), 'chartjs-plugin-annotation-tmp'); + fs.rmSync(baseTmpDir, {recursive: true, force: true}); + fs.mkdirSync(baseTmpDir); - function testOnNodeProject(projectName) { - const projectPath = path.join(__dirname, projectName); + chartjsVersions.forEach(function(chartjs) { + const tmpDir = path.join(baseTmpDir, chartjs); + fs.mkdirSync(tmpDir); - const packageJSONPath = path.join(projectPath, 'package.json'); - const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8')); + const archiveName = exec(`npm --quiet pack ${distDir}`, {cwd: tmpDir}); + fs.renameSync( + path.join(tmpDir, archiveName), + path.join(tmpDir, 'plugin.tgz'), + ); + + function testOnNodeProject(projectName) { + const projectPath = path.join(__dirname, projectName); + + const packageJSONPath = path.join(projectPath, 'package.json'); + const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8')); + packageJSON.dependencies['chart.js'] = chartjs; - it(packageJSON.description, () => { const cwd = path.join(tmpDir, projectName); + const distPackageJSONFile = path.join(cwd, 'package.json'); fs.copySync(projectPath, cwd); + fs.outputJson(distPackageJSONFile, packageJSON, {spaces: 2, encoding: 'utf-8'}); - exec('npm --quiet install', {cwd, stdio: 'inherit'}); - exec('npm --quiet test', {cwd, stdio: 'inherit'}); - }).timeout(5 * 60 * 1000); - } + it(`${packageJSON.description} on Chart.js version ${chartjs}`, () => { + exec('npm --quiet install', {cwd, stdio: 'inherit'}); + exec('npm --quiet test', {cwd, stdio: 'inherit'}); + }).timeout(5 * 60 * 1000); - testOnNodeProject('ts'); + } + + testOnNodeProject('ts'); + }); }); diff --git a/test/integration/ts/package.json b/test/integration/ts/package.json index 39b929587..853aba869 100644 --- a/test/integration/ts/package.json +++ b/test/integration/ts/package.json @@ -5,13 +5,14 @@ "test": "node test.js" }, "dependencies": { - "chart.js": "^3.1.0", + "chart.js": "^4.1.1", "chartjs-plugin-annotation": "file:../plugin.tgz", "typescript-4.1": "npm:typescript@4.1.x", "typescript-4.2": "npm:typescript@4.2.x", "typescript-4.3": "npm:typescript@4.3.x", "typescript-4.4": "npm:typescript@4.4.x", "typescript-4.5": "npm:typescript@4.5.x", - "typescript-4.6": "npm:typescript@4.6.x" + "typescript-4.6": "npm:typescript@4.6.x", + "typescript-4.7": "npm:typescript@4.7.x" } }