Skip to content

Commit 795220f

Browse files
authored
Merge pull request #3969 from plotly/jasmine-core-3.4.0
Use jasmine-core 3.4.0
2 parents 2b4de3e + de644e6 commit 795220f

12 files changed

+96
-82
lines changed

Diff for: package-lock.json

+13-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,15 @@
132132
"gzip-size": "^5.1.1",
133133
"image-size": "^0.7.4",
134134
"into-stream": "^4.0.0",
135-
"jasmine-core": "^2.99.1",
135+
"jasmine-core": "^3.4.0",
136136
"jsdom": "^11.12.0",
137137
"karma": "^4.1.0",
138138
"karma-browserify": "^6.0.0",
139139
"karma-chrome-launcher": "^2.0.0",
140-
"karma-fail-fast-reporter": "^1.0.5",
141140
"karma-firefox-launcher": "^1.0.1",
142141
"karma-ie-launcher": "^1.0.0",
143-
"karma-jasmine": "^1.1.2",
144-
"karma-jasmine-spec-tags": "^1.0.1",
142+
"karma-jasmine": "^2.0.1",
143+
"karma-jasmine-spec-tags": "^1.1.0",
145144
"karma-spec-reporter": "0.0.32",
146145
"karma-verbose-reporter": "0.0.6",
147146
"karma-viewport": "^1.0.4",

Diff for: test/jasmine/assets/custom_assertions.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var d3 = require('d3');
4+
var negateIf = require('./negate_if');
45

56
exports.assertDims = function(dims) {
67
var traces = d3.selectAll('.trace');
@@ -122,8 +123,7 @@ exports.assertHoverLabelContent = function(expectation, msg) {
122123
assertLabelContent(nameSel, expectation.name, ptMsg + ' (name)');
123124

124125
if('isRotated' in expectation) {
125-
expect(g.attr('transform').match(reRotate))
126-
.negateIf(expectation.isRotated)
126+
negateIf(expectation.isRotated, expect(g.attr('transform').match(reRotate)))
127127
.toBe(null, ptMsg + ' should be rotated');
128128
}
129129
} else if(ptCnt > 1) {
@@ -162,8 +162,7 @@ exports.assertHoverLabelContent = function(expectation, msg) {
162162
});
163163

164164
if('isRotated' in expectation) {
165-
expect(g.attr('transform').match(reRotate))
166-
.negateIf(expectation.isRotated)
165+
negateIf(expectation.isRotated, expect(g.attr('transform').match(reRotate)))
167166
.toBe(null, ptMsg + ' ' + i + ' should be rotated');
168167
}
169168
});

Diff for: test/jasmine/assets/custom_matchers.js

-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
/*
22
* custom_matchers - to be included in karma.conf.js, so it can
33
* add these matchers to jasmine globally and all suites have access.
4-
*
5-
* Also adds `.negateIf` which is not a matcher but a conditional `.not`:
6-
*
7-
* expect(x).negateIf(condition).toBe(0);
8-
*
9-
* is equivalent to:
10-
*
11-
* if(condition) expect(x).toBe(0);
12-
* else expect(x).not.toBe(0);
134
*/
145

156
'use strict';
@@ -241,9 +232,4 @@ function arrayToStr(array) {
241232

242233
beforeAll(function() {
243234
jasmine.addMatchers(matchers);
244-
245-
jasmine.Expectation.prototype.negateIf = function(negate) {
246-
if(negate) return this.not;
247-
return this;
248-
};
249235
});

Diff for: test/jasmine/assets/negate_if.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
/**
4+
* Helpers that can negate an expectation given a condition
5+
*
6+
* @param {boolean OR function} condition
7+
* @param {jasmine expect return} expectation
8+
* @returns {jasmine expect return}
9+
*
10+
* Example:
11+
*
12+
* negateIf(myCondition, expect(actual)).toBe(expected);
13+
*
14+
*/
15+
function negateIf(condition, expectation) {
16+
return (typeof condition === 'function' ? condition() : condition) ?
17+
expectation.not :
18+
expectation;
19+
}
20+
21+
module.exports = negateIf;

Diff for: test/jasmine/karma.conf.js

+36-30
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ var path = require('path');
44
var minimist = require('minimist');
55
var constants = require('../../tasks/util/constants');
66

7-
var isCI = !!process.env.CI;
7+
var isCI = Boolean(process.env.CI);
8+
89
var argv = minimist(process.argv.slice(4), {
910
string: ['bundleTest', 'width', 'height'],
10-
'boolean': ['info', 'nowatch', 'failFast', 'verbose', 'Chrome', 'Firefox', 'IE11'],
11+
'boolean': [
12+
'info',
13+
'nowatch', 'failFast', 'verbose', 'randomize',
14+
'Chrome', 'Firefox', 'IE11'
15+
],
1116
alias: {
1217
'Chrome': 'chrome',
1318
'Firefox': ['firefox', 'FF'],
@@ -21,6 +26,7 @@ var argv = minimist(process.argv.slice(4), {
2126
nowatch: isCI,
2227
failFast: false,
2328
verbose: false,
29+
randomize: false,
2430
width: '1035',
2531
height: '617'
2632
}
@@ -60,6 +66,7 @@ if(argv.info) {
6066
' - `--failFast` (dflt: `false`): exit karma upon first test failure',
6167
' - `--verbose` (dflt: `false`): show test result using verbose reporter',
6268
' - `--showSkipped` (dflt: `false`): show tests that are skipped',
69+
' - `--randomize` (dflt: `false`): randomize test ordering (useful to detect bad test teardown)',
6370
' - `--tags`: run only test with given tags (using the `jasmine-spec-tags` framework)',
6471
' - `--width`(dflt: 1035): set width of the browser window',
6572
' - `--height` (dflt: 617): set height of the browser window',
@@ -113,7 +120,6 @@ var pathToUnpolyfill = path.join(__dirname, 'assets', 'unpolyfill.js');
113120
var pathToMathJax = path.join(constants.pathToDist, 'extras', 'mathjax');
114121

115122
var reporters = ((isFullSuite && !argv.tags) || argv.showSkipped) ? ['dots', 'spec'] : ['progress'];
116-
if(argv.failFast) reporters.push('fail-fast');
117123
if(argv.verbose) reporters.push('verbose');
118124

119125
function func(config) {
@@ -224,27 +230,33 @@ func.defaultConfig = {
224230
debug: true
225231
},
226232

227-
// Options for `karma-jasmine-spec-tags`
228-
// see https://www.npmjs.com/package/karma-jasmine-spec-tags
229-
//
230-
// A few tests don't behave well on CI
231-
// add @noCI to the spec description to skip a spec on CI
232-
//
233-
// Although not recommended, some tests "depend" on other
234-
// tests to pass (e.g. the Plotly.react tests check that
235-
// all available traces and transforms are tested). Tag these
236-
// with @noCIdep, so that
237-
// - $ npm run test-jasmine -- tags=noCI,noCIdep
238-
// can pass.
239-
//
240-
// Label tests that require a WebGL-context by @gl so that
241-
// they can be skipped using:
242-
// - $ npm run test-jasmine -- --skip-tags=gl
243-
// or run is isolation easily using:
244-
// - $ npm run test-jasmine -- --tags=gl
245233
client: {
234+
// Options for `karma-jasmine-spec-tags`
235+
// see https://www.npmjs.com/package/karma-jasmine-spec-tags
236+
//
237+
// A few tests don't behave well on CI
238+
// add @noCI to the spec description to skip a spec on CI
239+
//
240+
// Although not recommended, some tests "depend" on other
241+
// tests to pass (e.g. the Plotly.react tests check that
242+
// all available traces and transforms are tested). Tag these
243+
// with @noCIdep, so that
244+
// - $ npm run test-jasmine -- tags=noCI,noCIdep
245+
// can pass.
246+
//
247+
// Label tests that require a WebGL-context by @gl so that
248+
// they can be skipped using:
249+
// - $ npm run test-jasmine -- --skip-tags=gl
250+
// or run is isolation easily using:
251+
// - $ npm run test-jasmine -- --tags=gl
246252
tagPrefix: '@',
247-
skipTags: isCI ? 'noCI' : null
253+
skipTags: isCI ? 'noCI' : null,
254+
255+
// See https://jasmine.github.io/api/3.4/Configuration.html
256+
jasmine: {
257+
random: argv.randomize,
258+
failFast: argv.failFast
259+
}
248260
},
249261

250262
// use 'karma-spec-reporter' to log info about skipped specs
@@ -253,14 +265,8 @@ func.defaultConfig = {
253265
suppressFailed: true,
254266
suppressPassed: true,
255267
suppressSkipped: false,
256-
showSpecTiming: false,
257-
// use 'karma-fail-fast-reporter' to fail fast w/o conflicting
258-
// with other karma plugins
259-
failFast: false
260-
},
261-
262-
// e.g. when a test file does not container a given spec tags
263-
failOnEmptyTestSuite: false
268+
showSpecTiming: false
269+
}
264270
};
265271

266272
func.defaultConfig.preprocessors[pathToCustomMatchers] = ['browserify'];

Diff for: test/jasmine/tests/bar_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var DBLCLICKDELAY = require('../../../src/constants/interactions').DBLCLICKDELAY
1212
var createGraphDiv = require('../assets/create_graph_div');
1313
var destroyGraphDiv = require('../assets/destroy_graph_div');
1414
var failTest = require('../assets/fail_test');
15+
var negateIf = require('../assets/negate_if');
1516
var checkTicks = require('../assets/custom_assertions').checkTicks;
1617
var supplyAllDefaults = require('../assets/supply_defaults');
1718
var color = require('../../../src/components/color');
@@ -1759,7 +1760,7 @@ describe('A bar plot', function() {
17591760
if(!i) return;
17601761
var bbox = this.getBoundingClientRect();
17611762
['left', 'right', 'top', 'bottom', 'width', 'height'].forEach(function(dim) {
1762-
expect(bbox[dim]).negateIf(dims.indexOf(dim) === -1)
1763+
negateIf(dims.indexOf(dim) === -1, expect(bbox[dim]))
17631764
.toBeWithin(bbox1[dim], 0.1, msg + ' (' + i + '): ' + dim);
17641765
});
17651766
});

Diff for: test/jasmine/tests/colorbar_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var subroutines = require('@src/plot_api/subroutines');
88
var createGraphDiv = require('../assets/create_graph_div');
99
var destroyGraphDiv = require('../assets/destroy_graph_div');
1010
var failTest = require('../assets/fail_test');
11+
var negateIf = require('../assets/negate_if');
1112
var supplyAllDefaults = require('../assets/supply_defaults');
1213
var assertPlotSize = require('../assets/custom_assertions').assertPlotSize;
1314
var drag = require('../assets/drag');
@@ -119,7 +120,7 @@ describe('Test colorbar:', function() {
119120
var cbbg = colorbars.selectAll('.cbbg');
120121
var cbfills = colorbars.selectAll('.cbfill');
121122

122-
expect(cbfills.size()).negateIf(multiFill).toBe(1);
123+
negateIf(multiFill, expect(cbfills.size())).toBe(1);
123124

124125
if(!cbHeight) cbHeight = 400;
125126
var bgHeight = +cbbg.attr('height');

Diff for: test/jasmine/tests/geo_test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var d3 = require('d3');
1111
var createGraphDiv = require('../assets/create_graph_div');
1212
var destroyGraphDiv = require('../assets/destroy_graph_div');
1313
var failTest = require('../assets/fail_test');
14+
var negateIf = require('../assets/negate_if');
1415
var getClientPosition = require('../assets/get_client_position');
1516
var mouseEvent = require('../assets/mouse_event');
1617
var click = require('../assets/click');
@@ -1571,8 +1572,8 @@ describe('Test geo base layers', function() {
15711572
var cd0 = gd.calcdata[0];
15721573
var subplot = gd._fullLayout.geo._subplot;
15731574

1574-
expect(cd0[0].geojson).negateIf(geojson[0]).toBe(null);
1575-
expect(cd0[1].geojson).negateIf(geojson[1]).toBe(null);
1575+
negateIf(geojson[0], expect(cd0[0].geojson)).toBe(null);
1576+
negateIf(geojson[1], expect(cd0[1].geojson)).toBe(null);
15761577

15771578
expect(Object.keys(subplot.layers).length).toEqual(layers.length, '# of layers');
15781579

Diff for: test/jasmine/tests/plot_api_test.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var d3 = require('d3');
1717
var createGraphDiv = require('../assets/create_graph_div');
1818
var destroyGraphDiv = require('../assets/destroy_graph_div');
1919
var failTest = require('../assets/fail_test');
20+
var negateIf = require('../assets/negate_if');
2021
var checkTicks = require('../assets/custom_assertions').checkTicks;
2122
var supplyAllDefaults = require('../assets/supply_defaults');
2223

@@ -1110,9 +1111,9 @@ describe('Test plot api', function() {
11101111
var zmax1 = 10;
11111112

11121113
function check(auto, msg) {
1113-
expect(gd._fullData[0].zmin).negateIf(auto).toBe(zmin0, msg);
1114+
negateIf(auto, expect(gd._fullData[0].zmin)).toBe(zmin0, msg);
11141115
expect(gd._fullData[0].zauto).toBe(auto, msg);
1115-
expect(gd._fullData[1].zmax).negateIf(auto).toBe(zmax1, msg);
1116+
negateIf(auto, expect(gd._fullData[1].zmax)).toBe(zmax1, msg);
11161117
expect(gd._fullData[1].zauto).toBe(auto, msg);
11171118
}
11181119

@@ -1153,12 +1154,12 @@ describe('Test plot api', function() {
11531154

11541155
function check(auto, autocolorscale, msg) {
11551156
expect(gd._fullData[0].marker.cauto).toBe(auto, msg);
1156-
expect(gd._fullData[0].marker.cmin).negateIf(auto).toBe(mcmin0);
1157+
negateIf(auto, expect(gd._fullData[0].marker.cmin)).toBe(mcmin0);
11571158
expect(gd._fullData[0].marker.autocolorscale).toBe(autocolorscale, msg);
11581159
expect(gd._fullData[0].marker.colorscale).toEqual(auto ? autocscale : scales[mcscl0]);
11591160

11601161
expect(gd._fullData[1].marker.line.cauto).toBe(auto, msg);
1161-
expect(gd._fullData[1].marker.line.cmax).negateIf(auto).toBe(mlcmax1);
1162+
negateIf(auto, expect(gd._fullData[1].marker.line.cmax)).toBe(mlcmax1);
11621163
expect(gd._fullData[1].marker.line.autocolorscale).toBe(autocolorscale, msg);
11631164
expect(gd._fullData[1].marker.line.colorscale).toEqual(auto ? autocscale : scales[mlcscl1]);
11641165
}
@@ -1323,8 +1324,8 @@ describe('Test plot api', function() {
13231324
function check(auto, msg) {
13241325
expect(gd.data[0].autocontour).toBe(auto, msg);
13251326
expect(gd.data[1].autocontour).toBe(auto, msg);
1326-
expect(gd.data[0].contours.start).negateIf(auto).toBe(start0, msg);
1327-
expect(gd.data[1].contours.size).negateIf(auto).toBe(size1, msg);
1327+
negateIf(auto, expect(gd.data[0].contours.start)).toBe(start0, msg);
1328+
negateIf(auto, expect(gd.data[1].contours.size)).toBe(size1, msg);
13281329
}
13291330

13301331
Plotly.plot(gd, [
@@ -1411,9 +1412,9 @@ describe('Test plot api', function() {
14111412
var dtick1 = 0.8;
14121413

14131414
function check(auto, msg) {
1414-
expect(gd._fullData[0].colorbar.tick0).negateIf(auto).toBe(tick00, msg);
1415+
negateIf(auto, expect(gd._fullData[0].colorbar.tick0)).toBe(tick00, msg);
14151416
expect(gd._fullData[0].colorbar.tickmode).toBe(auto ? 'auto' : 'linear', msg);
1416-
expect(gd._fullData[1].colorbar.dtick).negateIf(auto).toBe(dtick1, msg);
1417+
negateIf(auto, expect(gd._fullData[1].colorbar.dtick)).toBe(dtick1, msg);
14171418
expect(gd._fullData[1].colorbar.tickmode).toBe(auto ? 'auto' : 'linear', msg);
14181419
}
14191420

Diff for: test/jasmine/tests/polar_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var d3 = require('d3');
77
var createGraphDiv = require('../assets/create_graph_div');
88
var destroyGraphDiv = require('../assets/destroy_graph_div');
99
var failTest = require('../assets/fail_test');
10+
var negateIf = require('../assets/negate_if');
1011
var mouseEvent = require('../assets/mouse_event');
1112
var click = require('../assets/click');
1213
var doubleClick = require('../assets/double_click');
@@ -460,7 +461,7 @@ describe('Test relayout on polar subplots:', function() {
460461
expect(txt.text()).toBe(content, 'radial axis title');
461462
}
462463

463-
expect(newBBox).negateIf(didBBoxChanged).toEqual(lastBBox, 'did bbox change');
464+
negateIf(didBBoxChanged, expect(newBBox)).toEqual(lastBBox, 'did bbox change');
464465
lastBBox = newBBox;
465466
}
466467

0 commit comments

Comments
 (0)