New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

deadunit-core

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deadunit-core - npm Package Compare versions

Comparing version 5.0.3 to 5.0.4

deadunitCore.browserConfig.js

150

deadunitCore.browser.js
"use strict";
/* Copyright (c) 2014 Billy Tetrud - Free to use for any purpose: MIT License*/
var path = require('path');
var Future = require('async-future')
var stackinfo = require('stackinfo')
var ajax = require("ajax")
var resolveSourceMap = Future.wrap(require('source-map-resolve').resolveSourceMap)
var deadunitCore = require("./deadunitCore")
var isRelative = require('./isRelative')
var browserConfig = require('./deadunitCore.browserConfig')
ajax.setSynchronous(true) // todo: REMOVE THIS once this chrome bug is fixed in a public release: https://code.google.com/p/chromium/issues/detail?id=368444
// add sourceFile contents into stacktrace.js's cache
var sourceCache = {}
var cacheGet = function(url) {
return sourceCache[url]
}
var cacheSet = function(url, responseFuture) {
sourceCache[url] = responseFuture
if(stackinfo.sourceCache[url] === undefined) {
responseFuture.then(function(response) {
stackinfo.sourceCache[url] = response.text.split('\n')
}).done()
}
}
if(window.setImmediate === undefined) {
window.setImmediate = function(fn, params) {
setTimeout(function() {
fn.apply(this,params)
},0)
}
}
ajax.cacheGet(cacheGet)
ajax.cacheSet(cacheSet)
// node.js errback style readFile
function readFile(url, callback) {
ajax(url).then(function(response) {
callback(undefined, response.text)
}).catch(callback).done()
}
module.exports = deadunitCore({
initialize: function() {},
initializeMainTest: function(testState) {
//testState.active = true // make sure
testState.oldOnerror = window.onerror
testState.newOnerror = window.onerror = function(errorMessage, filename, line, column) {
if(column === undefined) var columnText = ''
else var columnText = "/"+column
try {
throw new Error("Uncaught error in "+filename+" line "+line+columnText+": "+errorMessage) // IE needs the exception to actually be thrown before it will have a stack trace
} catch(e) {
testState.unhandledErrorHandler(e, true)
if(testState.oldOnerror)
testState.oldOnerror.apply(this, arguments)
}
}
},
mainTestDone: function(testState) {
//testState.active = false // make sure the test-specific onerror code is no longer run
/*if(testState.newOnerror === window.onerror) {
window.onerror = testState.oldOnerror // otherwise something else has overwritten onerror, so don't mess with it
}*/
},
getDomain: function() {
return undefined // domains don't exist in-browser
},
runTestGroup: function(deadunitState, tester, runTest, handleError, handleUnhandledError) {
runTest()
},
getScriptSourceLines: function(path) {
if(stackinfo.sourceCache[path] !== undefined) {
return Future(stackinfo.sourceCache[path])
} else {
return ajax(path).then(function(response) {
return Future(response.text.split('\n'))
})
}
},
getSourceMapObject: function(url, warningHandler) {
return ajax(url).then(function(response) {
var headers = response.headers
if(headers['SourceMap'] !== undefined) {
var headerSourceMap = headers['SourceMap']
} else if(headers['X-SourceMap']) {
var headerSourceMap = headers['X-SourceMap']
}
if(headerSourceMap !== undefined) {
if(isRelative(headerSourceMap)) {
headerSourceMap = path.join(path.dirname(url),headerSourceMap)
}
return ajax(headerSourceMap).then(function(response) {
return Future(JSON.parse(response.text))
})
} else {
return resolveSourceMap(response.text, url, readFile).catch(function(e){
warningHandler(e)
return Future(undefined)
}).then(function(sourceMapObject) {
if(sourceMapObject !== null) {
return Future(sourceMapObject.map)
} else {
return Future(undefined)
}
})
}
})
},
defaultUnhandledErrorHandler: function(e) {
//if(e !== undefined)
setTimeout(function() {
if(e.stack)
console.log(e.stack)
else
console.log(e)
},0)
},
defaultTestErrorHandler: function(tester) {
return function(e) {
tester.manager.emit('exception', {
parent: tester.mainSubTest.id,
time: (new Date()).getTime(),
error: e
})
}
},
getLineInfo: function(stackIncrease) {
return stackinfo()[3+stackIncrease]
},
getExceptionInfo: function(e) {
return stackinfo(e)
}
})
module.exports = deadunitCore(browserConfig())

@@ -219,2 +219,14 @@ "use strict";

var handleErrorInErrorHandler = function(warn, newError) {
if(warn !== false) {
try {
tester.warningHandler(newError)
} catch(warningHandlerError) {
tester.manager.emit('exception', Future(warningHandlerError)).done() // if shit gets this bad, that sucks
}
} else {
console.error(newError)
}
}
// warn should be set to false if the handler is being called to report a warning

@@ -228,9 +240,3 @@ return function(e, warn) {

} catch(newError) { // error handler had an error...
if(warn !== false) {
try {
tester.warningHandler(newError)
} catch(warningHandlerError) {
tester.manager.emit('exception', Future(warningHandlerError)).done() // if shit gets this bad, that sucks
}
}
handleErrorInErrorHandler(warn, newError)
}

@@ -242,3 +248,3 @@ }

if(newError.message !== "Accessing the 'caller' property of a function or arguments object is not allowed in strict mode") { // stacktrace.js doesn't support IE for certain things
tester.warningHandler(newError)
handleErrorInErrorHandler(warn, newError)
}

@@ -640,13 +646,18 @@ return Future(e) // use the original unmapped exception

if(sourceMapConsumerCache[url] === undefined) {
sourceMapConsumerCache[url] = options.getSourceMapObject(url, warningHandler).then(function(sourceMapObject) {
if(sourceMapObject !== undefined) {
if(sourceMapObject.version === undefined) {
warningHandler(new Error("Sourcemap for "+url+" doesn't contain the required 'version' property. Assuming version 2."))
sourceMapObject.version = 2 // assume version 2 to make browserify's broken sourcemap format that omits the version
try {
sourceMapConsumerCache[url] = options.getSourceMapObject(url, warningHandler).then(function(sourceMapObject) {
if(sourceMapObject !== undefined) {
if(sourceMapObject.version === undefined) {
warningHandler(new Error("Sourcemap for "+url+" doesn't contain the required 'version' property. Assuming version 2."))
sourceMapObject.version = 2 // assume version 2 to make browserify's broken sourcemap format that omits the version
}
return Future(new SourceMapConsumer(sourceMapObject))
} else {
return Future(undefined)
}
return Future(new SourceMapConsumer(sourceMapObject))
} else {
return Future(undefined)
}
})
})
} catch(e) {
sourceMapConsumerCache[url] = Future(undefined)
warningHandler(e)
}
}

@@ -653,0 +664,0 @@

{"name":"deadunit-core",
"description": "The core for deadunit - a dead-simple nestable unit testing library for javascript in node.js and the browser.",
"keywords": ["unit", "test", "testing", "javascript", "node", "deadunit", "asynchronous"],
"version":"5.0.3",
"version":"5.0.4",
"dependencies":{

@@ -12,3 +12,3 @@ "async-future":"1.0.0",

"source-map": "",
"ajax":"https://github.com/fresheneesz/ajax/archive/c0f12d10544a247bfa58b15e9535ee2ffd5787d1.tar.gz",
"ajax":"https://github.com/fresheneesz/ajax/archive/28d7ca2a922446ad9d2eae7d1bc615f3dbeb2f57.tar.gz",
"colors":"https://github.com/fresheneesz/colors.js/archive/e990804d7c301765409770582c6aa6d562a23198.tar.gz"

@@ -15,0 +15,0 @@ },

@@ -269,4 +269,4 @@ `deadunitCore`

* tests are timing out too easily - give each test a default timeout of 1 second (that can be overwritten by an explicit `this.timeout` call)
* counts are appearing at the end of test results - make their events send in-line to when they're called
* Look into using https://ci.testling.com/ for browser testing
* when chrome bug https://code.google.com/p/chromium/issues/detail?id=368444 is fixed, set ajax back to asynchronous
* There's already a way to work around dead fibers, but still need to make a way to work around dead futures

@@ -306,2 +306,5 @@ * put each subtest in its own timeout, and resolve a future either when the previous test completes or when it times out

* 5.0.4
* fixing memory leak that happened in certain rare error conditions
* updating ajax for better error handling
* 5.0.3

@@ -308,0 +311,0 @@ * fixing time calculating issue

@@ -10,8 +10,9 @@

this.timeout(10 * 1000)
var browserSpecificFuture = new Future
var browserSpecificFutures = []
var expectedExceptions = 10
var errorCount = 0
this.error(function(e) {
errorCount++
if(errorCount > 8) { // there are a bunch of exceptions that are expected
if(errorCount > expectedExceptions) { // there are a bunch of exceptions that are expected
t.ok(false, e)

@@ -25,2 +26,3 @@ } else {

this.test('browser-specific tests', function() {
this.test('sourcemap', function(t) {

@@ -30,2 +32,3 @@ this.count(5)

var f = new Future; browserSpecificFutures.push(f)
var unittest = Unit.test(function() {

@@ -36,3 +39,2 @@ this.test('webpack source map file', window.sourceMapTest3)

var results = unittest.results()
browserSpecificFuture.return()

@@ -45,8 +47,62 @@ t.ok(results.results[0].results[0].line === 4)

t.log(results.results[0].exceptions[0])
f.return()
}
})
})
// note: this test used to cause a stack loop that crashed chrome and blew firefoxes memory usage way up (probably until it'd crash too)
this.test('ajax failure', function(t) {
this.count(4)
var FailUnit = require('./deadunitCore.browserAjaxFailure')
var f = new Future; browserSpecificFutures.push(f)
var unittest = FailUnit.test(function(t) {
this.count(2)
this.ok(true)
setTimeout(function() {
t.ok(true)
throw new Error('asynchronous error')
}, 0)
throw new Error('synchronous error')
}).events({
end: function(e) {
var results = unittest.results()
t.ok(results.results.length === 2, results.results.length)
t.ok(results.exceptions.length >= 2, results.exceptions.length) // honestly i'm just happy if this test doesn't crash the browser
f.return()
}
})
//*
var FailUnit2 = require('./deadunitCore.browserAjaxThrow')
var f2 = new Future; browserSpecificFutures.push(f2)
var unittest2 = FailUnit2.test(function(t) {
this.count(2)
this.ok(true)
setTimeout(function() {
t.ok(true)
throw new Error('asynchronous error')
}, 0)
throw new Error('synchronous error')
}).events({
end: function(e) {
var results = unittest2.results()
t.ok(results.results.length === 3, results.results.length)
t.ok(results.exceptions.length >= 2, results.exceptions.length) // honestly i'm just happy if this test doesn't crash the browser
f2.return()
}
})
//*/
})
})
browserSpecificFuture.then(function() {
Future.all(browserSpecificFutures).then(function() {
t.test("common tests", tests.getTests(Unit, 'web', {return: function(){}}))

@@ -53,0 +109,0 @@ })

@@ -254,3 +254,3 @@ "use strict";

} else {
var subtest3line = 1194
var subtest3line = 7860
this.ok(subtest3.line === subtest3line, subtest3.line) // browserify bug causes sourcemap to not be found

@@ -257,0 +257,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc