Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
['warn', 'error'].forEach((level) => {
// you can use .log[level].args to get args
sinon.stub(videojs.log, level);
fakeEnvironment.log[level] = videojs.log[level];
Object.defineProperty(videojs.log[level], 'calls', {
get() {
// reset callCount to 0 so they don't have to
const callCount = this.callCount;
this.callCount = 0;
return callCount;
}
});
});
fakeEnvironment.clock = sinon.useFakeTimers();
fakeEnvironment.xhr = sinon.useFakeXMLHttpRequest();
// Sinon 1.10.2 handles abort incorrectly (triggering the error event)
// Later versions fixed this but broke the ability to set the response
// to an arbitrary object (in our case, a typed array).
window.XMLHttpRequest.prototype = Object.create(window.XMLHttpRequest.prototype);
window.XMLHttpRequest.prototype.abort = function abort() {
this.response = this.responseText = '';
this.errorFlag = true;
this.requestHeaders = {};
this.responseHeaders = {};
if (this.readyState > 0 && this.sendFlag) {
this.readyStateChange(4);
this.sendFlag = false;
}
before(() => {
// prevent accidental ajax requests
sinon.useFakeXMLHttpRequest();
});
beforeEach(function() {
terria = new Terria({
baseUrl: './'
});
this.xhr = sinon.useFakeXMLHttpRequest();
this.xhr.onCreate = function (xhr) {
requests.push(xhr);
};
});
beforeEach(function() {
silentLogger = logger.createLogger({
logLevel: enums.LOG_LEVEL.INFO,
logToConsole: false,
});
sinon.stub(configValidator, 'validate');
sinon.stub(Optimizely.prototype, 'close');
xhr = sinon.useFakeXMLHttpRequest();
global.XMLHttpRequest = xhr;
requests = [];
xhr.onCreate = function(req) {
requests.push(req);
};
sinon.spy(console, 'log');
sinon.spy(console, 'info');
sinon.spy(console, 'warn');
sinon.spy(console, 'error');
sinon.spy(window, 'addEventListener');
});
beforeEach(() => {
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
xhr.onCreate = req => requests.push(req);
});
beforeEach(function () {
if (mock) {
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
xhr.onCreate = function (request) {
requests.push(request);
};
}
});
test.before(() => {
sinon.xhr.supportsCORS = true
global.XMLHttpRequest = sinon.useFakeXMLHttpRequest()
global.window = {
localStorage: {},
console: console
};
})
beforeEach(function() {
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
xhr.onCreate = function(req) {
requests.push(req);
};
});
afterEach(function() {
beforeEach(function (done) {
global.localStorage.clear();
user.save({
token: 'test'
});
xhr = sinon.useFakeXMLHttpRequest();
global.window.XMLHttpRequest = xhr;
xhr.onCreate = function (req) {
requests.push(req);
};
done();
});