Comments (6)
@jamestalmage Yeah, that's exactly what I'm thinking of.
from empower.
Let me explain a history behind the code.
Also, instead of re-throwing an error (which messes with the existing stack trace needlessly). You could just use serialize-error attach the context, and throw.
I've implemented the same strategy, but some of old browsers (including PhantomJS) have strange behavior. When I rethrow Errors after attaching some props, the props disappear.
try {
try {
...
} catch (e) {
e.foo = 'bar';
throw e;
}
} catch (e) {
assert(e.foo === 'bar'); // Error on old PhantomJS
}
However, I found that the attached props are remaining on current PhantomJS.
So I can just attach and rethrow the original Error now.
It's a delightful discovery. Thanks!
from empower.
@twada - serialize-error
actually does not create an error. It creates a plain old javascript object with deep copies of the Errors properties. An Error object does not survive JSON.stringify()
very well. Especially assertion errors that have circular references.
Check the unit tests for all it does.
For use outside AVA, throwing non-errors is probably a bad idea. Could you maybe split most of the functionality into another module? empower-core
or something. It should take a copyAssertion
callback. empower
can continue to copy the Assertion the way you've been doing it here, and we can make a custom version that uses serialize-error
to make the copy.
from empower.
Could you maybe split most of the functionality into another module? empower-core or something. It should take a copyAssertion callback.
Yeah I'm working on that !
from empower.
Update: Now in a beta stage
from empower.
Close this issue since twada/empower-core is going on.
from empower.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from empower.