Skip to content

Commit

Permalink
tests should not run if a protocol is not supported by test-runner en…
Browse files Browse the repository at this point in the history
…vironment
  • Loading branch information
latel committed Sep 7, 2018
1 parent 751fc42 commit c26b3ea
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
12 changes: 5 additions & 7 deletions dist/logline.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ var Pool = function () {
return Pool;
}();

var READ_WRITE = 'readwrite';

/**
* IndexedDB protocol
* @class IndexedDBLogger
Expand Down Expand Up @@ -485,7 +487,7 @@ var IndexedDBLogger = function (_LoggerInterface) {
}

debug(this._namespace, level, descriptor, data);
var transaction = IndexedDBLogger.db.transaction(['logs'], IDBTransaction.READ_WRITE || 'readwrite');
var transaction = IndexedDBLogger.db.transaction(['logs'], READ_WRITE || 'readwrite');
transaction.onerror = function (event) {
return throwError(event.target.error);
};
Expand Down Expand Up @@ -649,7 +651,7 @@ var IndexedDBLogger = function (_LoggerInterface) {
});
}

var store = IndexedDBLogger._getTransactionStore(IDBTransaction.READ_WRITE);
var store = IndexedDBLogger._getTransactionStore(READ_WRITE);
if (!store) {
return false;
}
Expand Down Expand Up @@ -722,7 +724,7 @@ var IndexedDBLogger = function (_LoggerInterface) {
value: function _getTransactionStore(mode) {
try {
if (IndexedDBLogger.db) {
var transaction = IndexedDBLogger.db.transaction(['logs'], mode || IDBTransaction.READ_WRITE);
var transaction = IndexedDBLogger.db.transaction(['logs'], mode || READ_WRITE);
transaction.onerror = function (event) {
return throwError(event.target.error);
};
Expand All @@ -745,10 +747,6 @@ var IndexedDBLogger = function (_LoggerInterface) {
key: 'support',
get: function get$$1() {
var support = !!(window.indexedDB && window.IDBTransaction && window.IDBKeyRange);
if (support) {
window.IDBTransaction.READ_WRITE = 'readwrite';
window.IDBTransaction.READ_ONLY = 'readonly';
}
return support;
}
}]);
Expand Down
2 changes: 1 addition & 1 deletion dist/logline.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/logline.min.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logline",
"version": "1.1.1",
"version": "1.1.2",
"description": "logs for the frontend",
"main": "dist/logline.min.js",
"scripts": {
Expand Down Expand Up @@ -31,6 +31,7 @@
"homepage": "https://github.com/latel/logline#readme",
"devDependencies": {
"babel-core": "^6.7.7",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-preset-env": "^1.7.0",
"chai": "^3.5.0",
Expand All @@ -42,11 +43,13 @@
"gulp-compile-handlebars": "^0.6.1",
"gulp-rename": "^1.2.2",
"html-loader": "^0.4.3",
"install": "^0.12.1",
"jsonfile": "^2.4.0",
"minimist": "^1.2.0",
"mocha": "^2.5.3",
"mocha-headless-chrome": "1.7.1",
"moment": "^2.13.0",
"npm": "^6.4.1",
"rollup": "^0.41.4",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-license": "^0.2.0",
Expand Down
27 changes: 16 additions & 11 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Logline.config({
});

var readyTimer, repeated, isReady = function(readyFn) {
clearInterval(readyTimer), repeated = 0;
clearInterval(readyTimer);
repeated = 0;
readyTimer = setInterval(function() {
var ready = 0, i;
if (repeated++ > 20) {
Expand Down Expand Up @@ -58,23 +59,27 @@ describe('Logline', function() {

it('should be able to specialfy any available protocols', function(done) {
for (var i = 0; i < Object.keys(window.Logline.PROTOCOL).length; i++) {
window.Logline.using(window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]]);
assert.equal(window.Logline._protocol, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'protocol should be properly setted');
window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].clean();
delete window.Logline._protocol;
if (window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].support) {
window.Logline.using(window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]]);
assert.equal(window.Logline._protocol, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'protocol should be properly setted');
window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].clean();
delete window.Logline._protocol;
}
}
done();
});

it('should be able to create any available protocols instance', function(done) {
isReady(function() {
for (var i = 0; i < Object.keys(window.Logline.PROTOCOL).length; i++) {
window.Logline.using(window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]]);
var logger = new window.Logline('a');
assert.equal(window.Logline._protocol, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'protocol should be properly setted');
assert.instanceOf(logger, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'log instance should be correctly created');
window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].clean();
delete window.Logline._protocol;
if (window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].support) {
window.Logline.using(window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]]);
var logger = new window.Logline('a');
assert.equal(window.Logline._protocol, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'protocol should be properly setted');
assert.instanceOf(logger, window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]], 'log instance should be correctly created');
window.Logline.PROTOCOL[Object.keys(window.Logline.PROTOCOL)[i]].clean();
delete window.Logline._protocol;
}
}
done();
});
Expand Down

0 comments on commit c26b3ea

Please sign in to comment.