Skip to content

Commit

Permalink
Add integration test(s) for Node (#10554)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Aug 3, 2022
1 parent beaf370 commit 9224e57
Show file tree
Hide file tree
Showing 7 changed files with 664 additions and 13 deletions.
575 changes: 563 additions & 12 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"lint-types": "eslint \"types/**/*.ts\" && node -r esm types/tests/autogen.js && tsc -p types/tests/",
"lint": "concurrently \"npm:lint-*\"",
"test": "npm run lint && npm run test-ci",
"test-ci": "cross-env NODE_ENV=test karma start --auto-watch --single-run --coverage --grep"
"test-ci": "concurrently \"npm:test-ci-*\"",
"test-ci-karma": "cross-env NODE_ENV=test karma start --auto-watch --single-run --coverage --grep",
"test-ci-integration": "mocha --full-trace test/integration/*-test.js"
},
"devDependencies": {
"@kurkle/color": "^0.2.1",
Expand Down Expand Up @@ -84,6 +86,7 @@
"karma-spec-reporter": "0.0.32",
"luxon": "^2.2.0",
"markdown-it-include": "^2.0.0",
"mocha": "^10.0.0",
"moment": "^2.29.1",
"moment-timezone": "^0.5.34",
"pixelmatch": "^5.2.1",
Expand Down
46 changes: 46 additions & 0 deletions test/integration/integration-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

const os = require('os');
const fs = require('fs-extra');
const path = require('path');
const childProcess = require('child_process');

const {describe, it} = require('mocha');

function exec(command, options = {}) {
const output = childProcess.execSync(command, {
encoding: 'utf-8',
...options,
});
return output && output.trimEnd();
}

describe('Integration Tests', () => {
const tmpDir = path.join(os.tmpdir(), 'chart.js-tmp');
fs.rmSync(tmpDir, {recursive: true, force: true});
fs.mkdirSync(tmpDir);

const distDir = path.resolve('./');
const archiveName = exec(`npm --quiet pack ${distDir}`, {cwd: tmpDir});
fs.renameSync(
path.join(tmpDir, archiveName),
path.join(tmpDir, 'package.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'));

it(packageJSON.description, () => {
const cwd = path.join(tmpDir, projectName);
fs.copySync(projectPath, cwd);

exec('npm --quiet install', {cwd, stdio: 'inherit'});
exec('npm --quiet test', {cwd, stdio: 'inherit'});
}).timeout(5 * 60 * 1000);
}

testOnNodeProject('node');
});
24 changes: 24 additions & 0 deletions test/integration/node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions test/integration/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"description": "chart.js should work in Node",
"scripts": {
"test": "npm run test-cjs",
"test-cjs": "node test.cjs",
"test-mjs": "node test.mjs",
"TODO": "test-mjs should be enambled for chart.js v4"
},
"dependencies": {
"chart.js": "file:../package.tgz"
}
}
7 changes: 7 additions & 0 deletions test/integration/node/test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const Chart = require('chart.js');
const valueOrDefault = Chart.helpers.valueOrDefault;

Chart.register({
id: 'TEST_PLUGIN',
dummyValue: valueOrDefault(0, 1)
});
7 changes: 7 additions & 0 deletions test/integration/node/test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Chart} from 'chart.js';
import {valueOrDefault} from 'chart.js/helpers';

Chart.register({
id: 'TEST_PLUGIN',
dummyValue: valueOrDefault(0, 1)
});

0 comments on commit 9224e57

Please sign in to comment.