Skip to content

Commit

Permalink
Add support for options.run and iife fixtures (#7)
Browse files Browse the repository at this point in the history
* Add support for options.run and iife fixtures

* Update deps
  • Loading branch information
kurkle committed Feb 5, 2021
1 parent 037629f commit 4e22677
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 66 deletions.
135 changes: 85 additions & 50 deletions package-lock.json

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

12 changes: 6 additions & 6 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "chartjs-test-utils",
"version": "0.1.2",
"version": "0.1.3",
"description": "Chart.js test utils",
"main": "dist/chartjs-test-utils.js",
"module": "dist/chartjs-test-utils.js",
Expand Down Expand Up @@ -30,15 +30,15 @@
},
"homepage": "https://github.com/chartjs/chartjs-test-utils#readme",
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"eslint": "^7.16.0",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.1.1",
"eslint": "^7.19.0",
"eslint-config-chartjs": "^0.3.0",
"eslint-plugin-es": "^4.1.0",
"rollup": "^2.35.1"
"rollup": "^2.38.4"
},
"dependencies": {
"jasmine": "^3.6.3",
"jasmine": "^3.6.4",
"karma": "^5.2.3",
"karma-jasmine": "^4.0.1",
"pixelmatch": "^5.2.1"
Expand Down
28 changes: 18 additions & 10 deletions src/fixture.js
Expand Up @@ -21,7 +21,7 @@ function loadConfig(url, callback) {
readFile(url, function(content) {
switch (type) {
case 'js':
cfg = new Function('"use strict"; var module = {};' + content + '; return module.exports;')();
cfg = new Function('"use strict"; var module = {};' + content + '; return module.exports || fixture;')();
break;
case 'json':
cfg = JSON.parse(content);
Expand All @@ -48,16 +48,24 @@ function specFromFixture(description, inputs) {
}

var chart = _acquireChart(config, json.options);
if (!inputs.png) {
fail(descr + '\r\nMissing PNG comparison file for ' + input);
done();
}
const _done = () => {
if (!inputs.png) {
fail(descr + '\r\nMissing PNG comparison file for ' + input);
done();
}

readImageData(inputs.png, function(expected) {
expect(chart).toEqualImageData(expected, json);
_releaseChart(chart);
done();
});
readImageData(inputs.png, function(expected) {
expect(chart).toEqualImageData(expected, json);
_releaseChart(chart);
done();
});
};
const run = json.options && json.options.run;
if (typeof run === 'function') {
json.options.run(chart, _done);
} else {
_done();
}
});
});
}
Expand Down

0 comments on commit 4e22677

Please sign in to comment.