Skip to content

Upgrade dependencies and implementation of the integration test #827

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 44 additions & 19 deletions test/integration/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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');
});
});
5 changes: 3 additions & 2 deletions test/integration/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}