Skip to content

Commit

Permalink
Migrate to chartjs-test-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Feb 5, 2021
1 parent 7ea6c3a commit ad2c69b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 318 deletions.
38 changes: 38 additions & 0 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"acorn": "^8.0.4",
"archiver": "^5.1.0",
"chart.js": "~2.9.4",
"chartjs-test-utils": "^0.1.2",
"eslint": "^7.15.0",
"eslint-config-chartjs": "^0.3.0",
"eslint-plugin-es": "^3.0.1",
Expand All @@ -54,7 +55,6 @@
"karma-jasmine-html-reporter": "^1.5.4",
"karma-rollup-preprocessor": "^7.0.5",
"karma-spec-reporter": "^0.0.32",
"pixelmatch": "^5.2.1",
"rollup": "^2.33.1",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-istanbul": "^2.0.1",
Expand Down
81 changes: 0 additions & 81 deletions test/fixture.js

This file was deleted.

33 changes: 9 additions & 24 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import Chart from 'chart.js';
import fixture from './fixture';
import matchers from './matchers';
import utils from './utils';

var charts = {};
import {acquireChart, addMatchers, releaseChart, releaseCharts, specsFromFixtures, triggerMouseEvent} from 'chartjs-test-utils';

// force ratio=1 for tests on high-res/retina devices
window.devicePixelRatio = 1;

jasmine.chart = {
acquire: function() {
var chart = utils.acquireChart.apply(utils, arguments);
charts[chart.id] = chart;
return chart;
},
release: function(chart) {
utils.releaseChart.apply(utils, arguments);
delete charts[chart.id];
},
acquire: acquireChart,
release: releaseChart,

// Since version 1.x, this plugin isn't anymore automatically registered on first
// import. This helper allows to register the given plugin for all specs contained
Expand All @@ -43,11 +32,13 @@ jasmine.chart = {
}
};

jasmine.fixture = fixture;
jasmine.triggerMouseEvent = utils.triggerMouseEvent;
jasmine.fixture = {
specs: specsFromFixtures
};
jasmine.triggerMouseEvent = triggerMouseEvent;

beforeEach(function() {
jasmine.addMatchers(matchers);
addMatchers();

Chart.helpers.merge(Chart.defaults.global, {
animation: false,
Expand Down Expand Up @@ -83,11 +74,5 @@ beforeEach(function() {
});

afterEach(function() {
// Auto releasing acquired charts
Object.keys(charts).forEach(function(id) {
var chart = charts[id];
if (!(chart.$test || {}).persistent) {
jasmine.chart.release(chart);
}
});
releaseCharts();
});
84 changes: 0 additions & 84 deletions test/matchers.js

This file was deleted.

Loading

0 comments on commit ad2c69b

Please sign in to comment.