-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test(s) for Node (#10554)
- Loading branch information
Showing
7 changed files
with
664 additions
and
13 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); |