Upgrade Jasmine and Karma dependencies (Fixes #6867) (#7339)

This commit is contained in:
Alex Gibson 2019-07-12 17:22:46 +01:00 коммит произвёл Craig Cook
Родитель 66539aa3fb
Коммит d83bd3934b
16 изменённых файлов: 536 добавлений и 582 удалений

Просмотреть файл

@ -12,7 +12,7 @@ jobs:
test_js:
docker:
- image: "circleci/node:6.14.0-browsers"
- image: "circleci/node:10.15.0-browsers"
steps:
- checkout
- restore_cache:

Просмотреть файл

@ -15,7 +15,7 @@ module.exports = {
* */
overrides: [
{
files: 'gulpfile.js',
files: ['gulpfile.js', 'tests/unit/karma.conf.js'],
env: {
'commonjs': true,
'node': true,

Просмотреть файл

@ -46,7 +46,8 @@ if (typeof window.Mozilla === 'undefined') {
* @return {String} url + additional parameters.
*/
StubAttributionMacOS.appendToDownloadURL = function (url, data) {
var finalParams = data;
// clone the passed `data` object to avoid mutating it indirectly.
var finalParams = Object.assign({}, data);
var linkParams;
// if the link has a querystring, merge it with the utm_ params in the current

Просмотреть файл

@ -199,8 +199,9 @@ if (typeof window.Mozilla === 'undefined') {
};
TPTour.handleVisibilityChange = function() {
var hidden = typeof TPTour.documentHidden === 'boolean' ? TPTour.documentHidden : document.hidden;
clearTimeout(_highlightTimeout);
if (TPTour.documentHidden || document.hidden) {
if (hidden) {
TPTour.hidePanels();
} else {
_highlightTimeout = setTimeout(TPTour.showTourStep, 300);

Просмотреть файл

@ -22,7 +22,7 @@
"gulp-sourcemaps": "^2.6.4",
"gulp-stylelint": "^3.9.0",
"gulp-uglify": "^3.0.0",
"merge-stream": "^1.0.1",
"merge-stream": "2.0.0",
"yargs": "13.2.1"
},
"repository": {
@ -37,12 +37,12 @@
"devDependencies": {
"browser-sync": "2.26.3",
"concurrently": "4.1.0",
"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma-coverage": "^0.5.5",
"karma-firefox-launcher": "^0.1.7",
"karma-jasmine": "^0.3.8",
"sinon": "^1.17.3"
"jasmine-core": "3.4.0",
"karma": "4.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "1.1.0",
"karma-jasmine": "2.0.1",
"sinon": "7.3.2"
},
"bin": {
"browser-sync": "/.bin/browser-sync"

Просмотреть файл

@ -1,3 +1,5 @@
'use strict';
module.exports = function(config) {
config.set({
// Karma configuration
@ -9,58 +11,55 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
// begin common dependencies.
'media/js/libs/jquery-3.4.1.min.js',
'media/js/base/site.js',
'media/js/base/mozilla-utils.js',
'media/js/base/dnt-helper.js',
'media/js/base/core-datalayer-page-id.js',
'media/js/base/mozilla-accordion-gatrack.js',
'media/js/base/mozilla-accordion.js',
'media/js/base/mozilla-client.js',
'media/js/base/search-params.js',
// end common dependencies.
'media/js/base/core-datalayer-page-id.js',
'media/js/base/core-datalayer.js',
'media/js/base/dnt-helper.js',
'media/js/base/fxa-utm-referral.js',
'media/js/base/mozilla-accordion.js',
'media/js/base/mozilla-fxa.js',
'media/js/base/mozilla-lazy-load.js',
'media/js/base/mozilla-notification-banner.js',
'media/js/base/mozilla-modal.js',
'media/js/base/mozilla-pager.js',
'media/js/base/mozilla-pixel.js',
'media/js/base/mozilla-share-cta.js',
'media/js/base/mozilla-traffic-cop-funnelcake-geo.js',
'media/js/base/mozilla-video-poster.js',
'media/js/base/mozilla-smoothscroll.js',
'media/js/base/search-params.js',
'media/js/base/stub-attribution.js',
'media/js/base/send-to-device.js',
'media/js/base/stub-attribution-custom.js',
'media/js/base/stub-attribution-macos.js',
'media/js/base/stub-attribution.js',
'media/js/firefox/all/all-downloads-unified.js',
'media/js/firefox/new/yandex/scene1.js',
'media/js/firefox/tracking-protection-tour.js',
'media/js/ie8/mozilla-utils-ie8.js',
'media/js/base/send-to-device.js',
'media/js/base/core-datalayer.js',
'media/js/base/fxa-utm-referral.js',
'tests/unit/spec/base/site.js',
'tests/unit/spec/base/mozilla-utils.js',
'tests/unit/spec/base/core-datalayer-page-id.js',
'tests/unit/spec/base/core-datalayer.js',
'tests/unit/spec/base/dnt-helper.js',
'tests/unit/spec/base/fxa-utm-referral.js',
'tests/unit/spec/base/core-datalayer-page-id.js',
'tests/unit/spec/base/mozilla-accordion.js',
'tests/unit/spec/base/mozilla-client.js',
'tests/unit/spec/base/mozilla-fxa.js',
'tests/unit/spec/base/mozilla-lazy-load.js',
'tests/unit/spec/base/mozilla-notification-banner.js',
'tests/unit/spec/base/mozilla-accordion.js',
'tests/unit/spec/base/mozilla-pager.js',
'tests/unit/spec/base/mozilla-pixel.js',
'tests/unit/spec/base/search-params.js',
'tests/unit/spec/base/mozilla-traffic-cop-funnelcake-geo.js',
'tests/unit/spec/base/mozilla-utils.js',
'tests/unit/spec/base/search-params.js',
'tests/unit/spec/base/send-to-device.js',
'tests/unit/spec/base/site.js',
'tests/unit/spec/base/stub-attribution-custom.js',
'tests/unit/spec/base/stub-attribution-macos.js',
'tests/unit/spec/base/stub-attribution.js',
'tests/unit/spec/firefox/all/all-downloads-unified.js',
'tests/unit/spec/firefox/new/yandex/scene1.js',
'tests/unit/spec/firefox/tracking-protection-tour.js',
'tests/unit/spec/ie8/mozilla-utils-ie8.js',
'tests/unit/spec/base/send-to-device.js',
'tests/unit/spec/base/core-datalayer.js',
'tests/unit/spec/base/stub-attribution.js',
'tests/unit/spec/base/stub-attribution-custom.js',
'tests/unit/spec/base/stub-attribution-macos.js',
{
pattern: 'node_modules/sinon/pkg/sinon.js',
watched: false,
@ -82,21 +81,7 @@ module.exports = function(config) {
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'coverage'
reporters: ['dots', 'coverage'],
preprocessors: {
'media/js/**/!(libs|test)/*.js': ['coverage']
},
coverageReporter: {
type: 'lcov',
dir: 'tests/unit/coverage/',
instrumenterOptions: {
istanbul: {
noCompact: true
}
}
},
reporters: ['progress'],
// web server port
port: 9876,
@ -112,7 +97,7 @@ module.exports = function(config) {
//logLevel: console.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
autoWatch: false,
// Start these browsers, currently available:
// - Chrome
@ -122,7 +107,7 @@ module.exports = function(config) {
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Firefox'],
browsers: ['Firefox', 'Chrome'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,

Просмотреть файл

@ -528,19 +528,16 @@ describe('mozilla-client.js', function() {
it('should fire the callback function with a FxA details object', function() {
var callback1 = jasmine.createSpy('callback1');
var result = {
'firefox': true,
'legacy': false,
'mobile': false,
'setup': false,
'desktopDevices': false,
'mobileDevices': false
};
window.Mozilla.Client.getFxaDetails(callback1);
jasmine.clock().tick(500);
expect(callback1).toHaveBeenCalledWith(result);
expect(window.Mozilla.Client.FxaDetails).toEqual(result);
expect(callback1).toHaveBeenCalled();
expect(typeof window.Mozilla.Client.FxaDetails.firefox).toEqual('boolean');
expect(typeof window.Mozilla.Client.FxaDetails.legacy).toEqual('boolean');
expect(typeof window.Mozilla.Client.FxaDetails.mobile).toEqual('boolean');
expect(typeof window.Mozilla.Client.FxaDetails.setup).toEqual('boolean');
expect(typeof window.Mozilla.Client.FxaDetails.desktopDevices).toEqual('boolean');
expect(typeof window.Mozilla.Client.FxaDetails.mobileDevices).toEqual('boolean');
});
});

Просмотреть файл

@ -16,10 +16,22 @@ describe('mozilla-notification-banner.js', function() {
window.Mozilla.Cookies.setItem = sinon.stub();
window.Mozilla.Cookies.getItem = sinon.stub();
window.Mozilla.Cookies.hasItem = sinon.stub();
// stub out google tag manager
window.dataLayer = sinon.stub();
window.dataLayer.push = sinon.stub();
});
describe('init', function() {
afterEach(function() {
var notification = document.querySelector('.notification-banner');
if (notification) {
document.body.removeChild(notification);
}
});
var options = {
'id': 'fx-out-of-date-banner-copy1-direct-1',
'name': 'fx-out-of-date',
@ -124,6 +136,14 @@ describe('mozilla-notification-banner.js', function() {
describe('show', function() {
afterEach(function() {
var notification = document.querySelector('.notification-banner');
if (notification) {
document.body.removeChild(notification);
}
});
it('should display the notification and set a cookie', function() {
var options = {
'id': 'fx-out-of-date-banner-copy1-direct-1',
@ -151,7 +171,6 @@ describe('mozilla-notification-banner.js', function() {
expect(Mozilla.NotificationBanner.bind).toHaveBeenCalled();
expect(Mozilla.NotificationBanner.setCookie).toHaveBeenCalledWith(options.id);
expect(Mozilla.NotificationBanner.trackGAShow).toHaveBeenCalledWith(options);
document.body.removeChild(notification);
});
});
@ -239,7 +258,31 @@ describe('mozilla-notification-banner.js', function() {
describe('confirm', function() {
afterEach(function() {
var notification = document.querySelector('.notification-banner');
if (notification) {
document.body.removeChild(notification);
}
});
it('should set a cookie before redirecting for regular click', function() {
var options = {
'id': 'fx-out-of-date-banner-copy1-direct-1',
'name': 'fx-out-of-date',
'experimentName': 'fx-out-of-date-banner-copy1',
'experimentVariant': 'direct-1',
'heading': 'Your browser security is at risk.',
'message': 'Update Firefox now to protect yourself from the latest malware.',
'confirm': 'Update now',
'gaConfirmAction': 'Update Firefox',
'gaConfirmLabel': 'Firefox for Desktop',
'url': '/firefox/download/thanks/',
'close': 'Close',
'gaCloseLabel': 'Close',
'confirmClick': null
};
var event = {
'metaKey': false,
'ctrlKey': false,
@ -251,6 +294,7 @@ describe('mozilla-notification-banner.js', function() {
spyOn(Mozilla.NotificationBanner, 'doRedirect');
spyOn(Mozilla.NotificationBanner, 'trackGAConfirm');
spyOn(event, 'preventDefault');
Mozilla.NotificationBanner.init(options);
Mozilla.NotificationBanner.confirm(event);
expect(event.preventDefault).toHaveBeenCalled();
expect(Mozilla.NotificationBanner.setCookie).toHaveBeenCalledWith(Mozilla.NotificationBanner.COOKIE_INTERACTION_VALUE);
@ -259,6 +303,22 @@ describe('mozilla-notification-banner.js', function() {
});
it('should only set cookie for control click', function() {
var options = {
'id': 'fx-out-of-date-banner-copy1-direct-1',
'name': 'fx-out-of-date',
'experimentName': 'fx-out-of-date-banner-copy1',
'experimentVariant': 'direct-1',
'heading': 'Your browser security is at risk.',
'message': 'Update Firefox now to protect yourself from the latest malware.',
'confirm': 'Update now',
'gaConfirmAction': 'Update Firefox',
'gaConfirmLabel': 'Firefox for Desktop',
'url': '/firefox/download/thanks/',
'close': 'Close',
'gaCloseLabel': 'Close',
'confirmClick': null
};
var event = {
'metaKey': false,
'ctrlKey': true,
@ -270,6 +330,7 @@ describe('mozilla-notification-banner.js', function() {
spyOn(Mozilla.NotificationBanner, 'doRedirect');
spyOn(Mozilla.NotificationBanner, 'trackGAConfirm');
spyOn(event, 'preventDefault');
Mozilla.NotificationBanner.init(options);
Mozilla.NotificationBanner.confirm(event);
expect(event.preventDefault).not.toHaveBeenCalled();
expect(Mozilla.NotificationBanner.setCookie).toHaveBeenCalledWith(Mozilla.NotificationBanner.COOKIE_INTERACTION_VALUE);
@ -291,7 +352,7 @@ describe('mozilla-notification-banner.js', function() {
'url': '/firefox/download/thanks/',
'close': 'Close',
'gaCloseLabel': 'Close',
confirmClick: function() {} // eslint-disable-line no-empty-function
'confirmClick': function() {} // eslint-disable-line no-empty-function
};
var event = {

Просмотреть файл

@ -236,6 +236,7 @@ describe('mozilla-pager.js', function () {
describe('Mozilla.Pager history', function () {
beforeEach(function () {
Mozilla.Pager.monitoringHash = false;
$('<div id="pager" class="pager pager-with-tabs"><ol class="pager-tabs"><li><a href="#page1">Page 1</a></li><li><a href="#page2">Page 2</a></li></ol><div class="pager-content"><div class="pager-page"><p>Page 1</p></div><div class="pager-page"><p>Page 2</p></div></div></div>').appendTo('body');
});
@ -246,7 +247,7 @@ describe('mozilla-pager.js', function () {
});
it('should monitor hash changes', function () {
spyOn(Mozilla.Pager, 'initHashMonitor');
spyOn(Mozilla.Pager, 'initHashMonitor').and.callThrough();
Mozilla.Pager.createPagers();
expect(Mozilla.Pager.initHashMonitor).toHaveBeenCalled();
expect(Mozilla.Pager.monitoringHash).toBeTruthy();

Просмотреть файл

@ -10,6 +10,15 @@
describe('mozilla-traffic-cop-funnelcake-geo.js', function() {
'use strict';
beforeEach(function() {
// stub out Mozilla.Cookie lib
window.Mozilla.Cookies = sinon.stub();
window.Mozilla.Cookies.enabled = sinon.stub().returns(true);
window.Mozilla.Cookies.setItem = sinon.stub();
window.Mozilla.Cookies.getItem = sinon.stub();
window.Mozilla.Cookies.hasItem = sinon.stub();
});
describe('checkInCohort', function() {
it('should return true if user has the provided cookie', function() {
spyOn(Mozilla.Cookies, 'hasItem').and.returnValue(true);

Просмотреть файл

@ -11,15 +11,15 @@ describe('search-params.js', function() {
describe('_SearchParams', function () {
var params = new _SearchParams('scene=2&source=getfirefox');
it('should return a proper value', function () {
var params = new _SearchParams('scene=2&source=getfirefox');
expect(params.get('scene')).toEqual(2);
expect(params.get('source')).toEqual('getfirefox');
expect(params.get('utm_campaign')).toBeUndefined();
});
it('should set a proper value', function () {
var params = new _SearchParams('scene=2&source=getfirefox');
params.set('scene', '3');
params.set('utm_medium', 'referral');
expect(params.get('scene')).toEqual(3);
@ -27,19 +27,22 @@ describe('search-params.js', function() {
});
it('should detect if the key exists', function () {
var params = new _SearchParams('scene=2&source=getfirefox');
expect(params.has('scene')).toBeTruthy();
expect(params.has('utm_medium')).toBeTruthy();
expect(params.has('source')).toBeTruthy();
expect(params.has('utm_source')).toBeFalsy();
});
it('should remove a value', function () {
var params = new _SearchParams('scene=2&source=getfirefox');
params.remove('utm_medium');
expect(params.has('utm_medium')).toBeFalsy();
expect(params.get('utm_medium')).toBeUndefined();
});
it('should return a param string', function () {
expect(params.toString()).toEqual('scene=3&source=getfirefox');
var params = new _SearchParams('scene=2&source=getfirefox');
expect(params.toString()).toEqual('scene=2&source=getfirefox');
});
it('should return an object of utm_ values', function () {

Просмотреть файл

@ -37,9 +37,14 @@ describe('send-to-device.js', function() {
$(formMarkup).appendTo('body');
// stub out spinner.js
window.Spinner = sinon.stub();
window.Spinner.prototype.spin = sinon.stub();
// stub out google tag manager
window.dataLayer = sinon.stub();
window.dataLayer.push = sinon.stub();
form = new Mozilla.SendToDevice();
});

Просмотреть файл

@ -19,7 +19,7 @@ describe('all-downloads-unified.js', function() {
].join();
beforeEach(function () {
document.documentElement.insertAdjacentHTML('beforeend', select);
document.body.insertAdjacentHTML('beforeend', select);
});
afterEach(function () {
@ -53,7 +53,7 @@ describe('all-downloads-unified.js', function() {
].join();
beforeEach(function () {
document.documentElement.insertAdjacentHTML('beforeend', select);
document.body.insertAdjacentHTML('beforeend', select);
});
afterEach(function () {
@ -105,7 +105,7 @@ describe('all-downloads-unified.js', function() {
].join();
beforeEach(function () {
document.documentElement.insertAdjacentHTML('beforeend', downloadList);
document.body.insertAdjacentHTML('beforeend', downloadList);
});
afterEach(function () {
@ -127,7 +127,7 @@ describe('all-downloads-unified.js', function() {
var downloadLink = '<a href="#" id="download-button-primary">Download Now</a>';
beforeEach(function () {
document.documentElement.insertAdjacentHTML('beforeend', downloadLink);
document.body.insertAdjacentHTML('beforeend', downloadLink);
});
afterEach(function () {
@ -249,10 +249,10 @@ describe('all-downloads-unified.js', function() {
'</ul>' +
'</li>' +
'</ol>'
];
].join();
beforeEach(function () {
document.documentElement.insertAdjacentHTML('beforeend', options);
document.body.insertAdjacentHTML('beforeend', options);
});
afterEach(function () {

Просмотреть файл

@ -10,6 +10,19 @@
describe('yandex-scene1.js', function() {
'use strict';
beforeEach(function() {
// stub out Mozilla.Cookie lib
window.Mozilla.Cookies = sinon.stub();
window.Mozilla.Cookies.enabled = sinon.stub().returns(true);
window.Mozilla.Cookies.setItem = sinon.stub();
window.Mozilla.Cookies.getItem = sinon.stub();
window.Mozilla.Cookies.hasItem = sinon.stub();
// stub out google tag manager
window.dataLayer = sinon.stub();
window.dataLayer.push = sinon.stub();
});
describe('getLocation', function() {
var xhr;
@ -79,16 +92,14 @@ describe('yandex-scene1.js', function() {
spyOn(Mozilla.Yandex, 'setCookie');
});
it('should update page content on first call and set a cookie', function() {
it('should update page content on first call only and set a cookie', function() {
Mozilla.Yandex.onRequestComplete(country);
expect(Mozilla.Yandex.updatePageContent).toHaveBeenCalled();
expect(Mozilla.Yandex.setCookie).toHaveBeenCalledWith(country);
});
it('should not update page content on second call', function() {
Mozilla.Yandex.onRequestComplete(country);
expect(Mozilla.Yandex.updatePageContent).not.toHaveBeenCalled();
expect(Mozilla.Yandex.setCookie).not.toHaveBeenCalled();
expect(Mozilla.Yandex.updatePageContent).toHaveBeenCalledTimes(1);
expect(Mozilla.Yandex.setCookie).toHaveBeenCalledTimes(1);
});
});

Просмотреть файл

@ -161,7 +161,7 @@ describe('tracking-protection-tour.js', function() {
describe('shoud open "controlCenter" and highlight "trackingUnblock" if target is available', function() {
beforeEach(function() {
beforeEach(function() {
spyOn(Mozilla.UITour, 'getConfiguration').and.callFake(function(configName, callback) {
callback({
targets: ['controlCenter-trackingUnblock']
@ -361,6 +361,10 @@ describe('tracking-protection-tour.js', function() {
describe('handleVisibilityChange', function() {
afterEach(function() {
Mozilla.TPTour.documentHidden = null;
});
it('should hide UITour highlights when document is hidden', function() {
Mozilla.TPTour.documentHidden = true;
spyOn(Mozilla.TPTour, 'hidePanels');

880
yarn.lock

Разница между файлами не показана из-за своего большого размера Загрузить разницу