Skip to content

Use jasmine-core 3.4.0 #3969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions package-lock.json

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

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,15 @@
"gzip-size": "^5.1.1",
"image-size": "^0.7.4",
"into-stream": "^4.0.0",
"jasmine-core": "^2.99.1",
"jasmine-core": "^3.4.0",
"jsdom": "^11.12.0",
"karma": "^4.1.0",
"karma-browserify": "^6.0.0",
"karma-chrome-launcher": "^2.0.0",
"karma-fail-fast-reporter": "^1.0.5",
"karma-firefox-launcher": "^1.0.1",
"karma-ie-launcher": "^1.0.0",
"karma-jasmine": "^1.1.2",
"karma-jasmine-spec-tags": "^1.0.1",
"karma-jasmine": "^2.0.1",
"karma-jasmine-spec-tags": "^1.1.0",
"karma-spec-reporter": "0.0.32",
"karma-verbose-reporter": "0.0.6",
"karma-viewport": "^1.0.4",
Expand Down
7 changes: 3 additions & 4 deletions test/jasmine/assets/custom_assertions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var d3 = require('d3');
var negateIf = require('./negate_if');

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

if('isRotated' in expectation) {
expect(g.attr('transform').match(reRotate))
.negateIf(expectation.isRotated)
negateIf(expectation.isRotated, expect(g.attr('transform').match(reRotate)))
.toBe(null, ptMsg + ' should be rotated');
}
} else if(ptCnt > 1) {
Expand Down Expand Up @@ -162,8 +162,7 @@ exports.assertHoverLabelContent = function(expectation, msg) {
});

if('isRotated' in expectation) {
expect(g.attr('transform').match(reRotate))
.negateIf(expectation.isRotated)
negateIf(expectation.isRotated, expect(g.attr('transform').match(reRotate)))
.toBe(null, ptMsg + ' ' + i + ' should be rotated');
}
});
Expand Down
14 changes: 0 additions & 14 deletions test/jasmine/assets/custom_matchers.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
/*
* custom_matchers - to be included in karma.conf.js, so it can
* add these matchers to jasmine globally and all suites have access.
*
* Also adds `.negateIf` which is not a matcher but a conditional `.not`:
*
* expect(x).negateIf(condition).toBe(0);
*
* is equivalent to:
*
* if(condition) expect(x).toBe(0);
* else expect(x).not.toBe(0);
*/

'use strict';
Expand Down Expand Up @@ -241,9 +232,4 @@ function arrayToStr(array) {

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

jasmine.Expectation.prototype.negateIf = function(negate) {
if(negate) return this.not;
return this;
};
});
21 changes: 21 additions & 0 deletions test/jasmine/assets/negate_if.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

/**
* Helpers that can negate an expectation given a condition
*
* @param {boolean OR function} condition
* @param {jasmine expect return} expectation
* @returns {jasmine expect return}
*
* Example:
*
* negateIf(myCondition, expect(actual)).toBe(expected);
*
*/
function negateIf(condition, expectation) {
return (typeof condition === 'function' ? condition() : condition) ?
expectation.not :
expectation;
}

module.exports = negateIf;
66 changes: 36 additions & 30 deletions test/jasmine/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ var path = require('path');
var minimist = require('minimist');
var constants = require('../../tasks/util/constants');

var isCI = !!process.env.CI;
var isCI = Boolean(process.env.CI);

var argv = minimist(process.argv.slice(4), {
string: ['bundleTest', 'width', 'height'],
'boolean': ['info', 'nowatch', 'failFast', 'verbose', 'Chrome', 'Firefox', 'IE11'],
'boolean': [
'info',
'nowatch', 'failFast', 'verbose', 'randomize',
'Chrome', 'Firefox', 'IE11'
],
alias: {
'Chrome': 'chrome',
'Firefox': ['firefox', 'FF'],
Expand All @@ -21,6 +26,7 @@ var argv = minimist(process.argv.slice(4), {
nowatch: isCI,
failFast: false,
verbose: false,
randomize: false,
width: '1035',
height: '617'
}
Expand Down Expand Up @@ -60,6 +66,7 @@ if(argv.info) {
' - `--failFast` (dflt: `false`): exit karma upon first test failure',
' - `--verbose` (dflt: `false`): show test result using verbose reporter',
' - `--showSkipped` (dflt: `false`): show tests that are skipped',
' - `--randomize` (dflt: `false`): randomize test ordering (useful to detect bad test teardown)',
' - `--tags`: run only test with given tags (using the `jasmine-spec-tags` framework)',
' - `--width`(dflt: 1035): set width of the browser window',
' - `--height` (dflt: 617): set height of the browser window',
Expand Down Expand Up @@ -113,7 +120,6 @@ var pathToUnpolyfill = path.join(__dirname, 'assets', 'unpolyfill.js');
var pathToMathJax = path.join(constants.pathToDist, 'extras', 'mathjax');

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

function func(config) {
Expand Down Expand Up @@ -224,27 +230,33 @@ func.defaultConfig = {
debug: true
},

// Options for `karma-jasmine-spec-tags`
// see https://www.npmjs.com/package/karma-jasmine-spec-tags
//
// A few tests don't behave well on CI
// add @noCI to the spec description to skip a spec on CI
//
// Although not recommended, some tests "depend" on other
// tests to pass (e.g. the Plotly.react tests check that
// all available traces and transforms are tested). Tag these
// with @noCIdep, so that
// - $ npm run test-jasmine -- tags=noCI,noCIdep
// can pass.
//
// Label tests that require a WebGL-context by @gl so that
// they can be skipped using:
// - $ npm run test-jasmine -- --skip-tags=gl
// or run is isolation easily using:
// - $ npm run test-jasmine -- --tags=gl
client: {
// Options for `karma-jasmine-spec-tags`
// see https://www.npmjs.com/package/karma-jasmine-spec-tags
//
// A few tests don't behave well on CI
// add @noCI to the spec description to skip a spec on CI
//
// Although not recommended, some tests "depend" on other
// tests to pass (e.g. the Plotly.react tests check that
// all available traces and transforms are tested). Tag these
// with @noCIdep, so that
// - $ npm run test-jasmine -- tags=noCI,noCIdep
// can pass.
//
// Label tests that require a WebGL-context by @gl so that
// they can be skipped using:
// - $ npm run test-jasmine -- --skip-tags=gl
// or run is isolation easily using:
// - $ npm run test-jasmine -- --tags=gl
tagPrefix: '@',
skipTags: isCI ? 'noCI' : null
skipTags: isCI ? 'noCI' : null,

// See https://jasmine.github.io/api/3.4/Configuration.html
jasmine: {
random: argv.randomize,
failFast: argv.failFast
}
},

// use 'karma-spec-reporter' to log info about skipped specs
Expand All @@ -253,14 +265,8 @@ func.defaultConfig = {
suppressFailed: true,
suppressPassed: true,
suppressSkipped: false,
showSpecTiming: false,
// use 'karma-fail-fast-reporter' to fail fast w/o conflicting
// with other karma plugins
failFast: false
},

// e.g. when a test file does not container a given spec tags
failOnEmptyTestSuite: false
showSpecTiming: false
}
};

func.defaultConfig.preprocessors[pathToCustomMatchers] = ['browserify'];
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var DBLCLICKDELAY = require('../../../src/constants/interactions').DBLCLICKDELAY
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var negateIf = require('../assets/negate_if');
var checkTicks = require('../assets/custom_assertions').checkTicks;
var supplyAllDefaults = require('../assets/supply_defaults');
var color = require('../../../src/components/color');
Expand Down Expand Up @@ -1759,7 +1760,7 @@ describe('A bar plot', function() {
if(!i) return;
var bbox = this.getBoundingClientRect();
['left', 'right', 'top', 'bottom', 'width', 'height'].forEach(function(dim) {
expect(bbox[dim]).negateIf(dims.indexOf(dim) === -1)
negateIf(dims.indexOf(dim) === -1, expect(bbox[dim]))
.toBeWithin(bbox1[dim], 0.1, msg + ' (' + i + '): ' + dim);
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/colorbar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var subroutines = require('@src/plot_api/subroutines');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var negateIf = require('../assets/negate_if');
var supplyAllDefaults = require('../assets/supply_defaults');
var assertPlotSize = require('../assets/custom_assertions').assertPlotSize;
var drag = require('../assets/drag');
Expand Down Expand Up @@ -119,7 +120,7 @@ describe('Test colorbar:', function() {
var cbbg = colorbars.selectAll('.cbbg');
var cbfills = colorbars.selectAll('.cbfill');

expect(cbfills.size()).negateIf(multiFill).toBe(1);
negateIf(multiFill, expect(cbfills.size())).toBe(1);

if(!cbHeight) cbHeight = 400;
var bgHeight = +cbbg.attr('height');
Expand Down
5 changes: 3 additions & 2 deletions test/jasmine/tests/geo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var negateIf = require('../assets/negate_if');
var getClientPosition = require('../assets/get_client_position');
var mouseEvent = require('../assets/mouse_event');
var click = require('../assets/click');
Expand Down Expand Up @@ -1571,8 +1572,8 @@ describe('Test geo base layers', function() {
var cd0 = gd.calcdata[0];
var subplot = gd._fullLayout.geo._subplot;

expect(cd0[0].geojson).negateIf(geojson[0]).toBe(null);
expect(cd0[1].geojson).negateIf(geojson[1]).toBe(null);
negateIf(geojson[0], expect(cd0[0].geojson)).toBe(null);
negateIf(geojson[1], expect(cd0[1].geojson)).toBe(null);

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

Expand Down
17 changes: 9 additions & 8 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var negateIf = require('../assets/negate_if');
var checkTicks = require('../assets/custom_assertions').checkTicks;
var supplyAllDefaults = require('../assets/supply_defaults');

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

function check(auto, msg) {
expect(gd._fullData[0].zmin).negateIf(auto).toBe(zmin0, msg);
negateIf(auto, expect(gd._fullData[0].zmin)).toBe(zmin0, msg);
expect(gd._fullData[0].zauto).toBe(auto, msg);
expect(gd._fullData[1].zmax).negateIf(auto).toBe(zmax1, msg);
negateIf(auto, expect(gd._fullData[1].zmax)).toBe(zmax1, msg);
expect(gd._fullData[1].zauto).toBe(auto, msg);
}

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

function check(auto, autocolorscale, msg) {
expect(gd._fullData[0].marker.cauto).toBe(auto, msg);
expect(gd._fullData[0].marker.cmin).negateIf(auto).toBe(mcmin0);
negateIf(auto, expect(gd._fullData[0].marker.cmin)).toBe(mcmin0);
expect(gd._fullData[0].marker.autocolorscale).toBe(autocolorscale, msg);
expect(gd._fullData[0].marker.colorscale).toEqual(auto ? autocscale : scales[mcscl0]);

expect(gd._fullData[1].marker.line.cauto).toBe(auto, msg);
expect(gd._fullData[1].marker.line.cmax).negateIf(auto).toBe(mlcmax1);
negateIf(auto, expect(gd._fullData[1].marker.line.cmax)).toBe(mlcmax1);
expect(gd._fullData[1].marker.line.autocolorscale).toBe(autocolorscale, msg);
expect(gd._fullData[1].marker.line.colorscale).toEqual(auto ? autocscale : scales[mlcscl1]);
}
Expand Down Expand Up @@ -1323,8 +1324,8 @@ describe('Test plot api', function() {
function check(auto, msg) {
expect(gd.data[0].autocontour).toBe(auto, msg);
expect(gd.data[1].autocontour).toBe(auto, msg);
expect(gd.data[0].contours.start).negateIf(auto).toBe(start0, msg);
expect(gd.data[1].contours.size).negateIf(auto).toBe(size1, msg);
negateIf(auto, expect(gd.data[0].contours.start)).toBe(start0, msg);
negateIf(auto, expect(gd.data[1].contours.size)).toBe(size1, msg);
}

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

function check(auto, msg) {
expect(gd._fullData[0].colorbar.tick0).negateIf(auto).toBe(tick00, msg);
negateIf(auto, expect(gd._fullData[0].colorbar.tick0)).toBe(tick00, msg);
expect(gd._fullData[0].colorbar.tickmode).toBe(auto ? 'auto' : 'linear', msg);
expect(gd._fullData[1].colorbar.dtick).negateIf(auto).toBe(dtick1, msg);
negateIf(auto, expect(gd._fullData[1].colorbar.dtick)).toBe(dtick1, msg);
expect(gd._fullData[1].colorbar.tickmode).toBe(auto ? 'auto' : 'linear', msg);
}

Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/polar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var negateIf = require('../assets/negate_if');
var mouseEvent = require('../assets/mouse_event');
var click = require('../assets/click');
var doubleClick = require('../assets/double_click');
Expand Down Expand Up @@ -460,7 +461,7 @@ describe('Test relayout on polar subplots:', function() {
expect(txt.text()).toBe(content, 'radial axis title');
}

expect(newBBox).negateIf(didBBoxChanged).toEqual(lastBBox, 'did bbox change');
negateIf(didBBoxChanged, expect(newBBox)).toEqual(lastBBox, 'did bbox change');
lastBBox = newBBox;
}

Expand Down
Loading