Skip to content
Closed
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
8 changes: 4 additions & 4 deletions build/wrapper_end
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

/**
* export the module via AMD, CommonJS or as a browser global
* Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
* Export code from https://github.com/umdjs/umd/blob/master/templates/returnExports.js
*/
;(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory)
} else if (typeof exports === 'object') {
define([], factory)
} else if (typeof module === 'object' && module.exports) {
/**
* Node. Does not work with strict CommonJS, but
* only CommonJS-like enviroments that support module.exports,
Expand All @@ -18,7 +18,7 @@
// Browser globals (root is window)
root.lunr = factory()
}
}(this, function () {
}(typeof self !== 'undefined' ? self : this, function () {
/**
* Just return a value to define the module export.
* This example returns an object, but the module
Expand Down
2 changes: 1 addition & 1 deletion build/wrapper_start
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*/

;(function(){

'use strict';
11 changes: 5 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ lunr.utils = {}
* @memberOf lunr.utils
* @function
*/
lunr.utils.warn = (function (global) {
lunr.utils.warn = function (message) {
/* eslint-disable no-console */
return function (message) {
if (global.console && console.warn) {
console.warn(message)
}
if (typeof console !== 'undefined' && console.warn) {
console.warn(message)
}
/* eslint-enable no-console */
})(this)
}


/**
* Convert an object to a string.
Expand Down
8 changes: 8 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"env": {
"mocha": true
},
"globals": {
"assert": false
}
}
38 changes: 38 additions & 0 deletions test/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,42 @@ suite('lunr.utils', function () {
})
})
})

suite('#warn', function () {
test('do nothing when console or console.warn is not implemented', function () {
var root = typeof self !== 'undefined' ? self : global
var origConsole = root.console

try {
root.console = undefined
lunr.utils.warn('foo')

root.console = {}
lunr.utils.warn('foo')
} finally {
root.console = origConsole
}
})

test('calls console.warn', function () {
var root = typeof self !== 'undefined' ? self : global
var origConsole = root.console

try {
var warnCalled = false

root.console = Object.create(root.console)
root.console.warn = function (message) {
assert.equal(message, 'foo')
warnCalled = true
}

lunr.utils.warn('foo')

assert.equal(warnCalled, true)
} finally {
root.console = origConsole
}
})
})
})