peter-leonov / introscope Goto Github PK
View Code? Open in Web Editor NEWAutomated mocking and spying tool for delightful ES6 modules testing
License: MIT License
Automated mocking and spying tool for delightful ES6 modules testing
License: MIT License
Add this or try to integrate with jest
object to just jest.fn.dispatch
with a "test global" effects log.
effects.mocker = testPlan(newLog())
it's too nice to just write mocker.fn.dispatch()
instead of creating a new wrapper around log every time.
Just in case :)
Say, we have a mocked object:
const nested = { x: { y: { z: () => () } } }
accessing calling nested.x.y.z()
will log only
nested.x
but it would be nice to see in the log:
nested.x
nested.x.y
nested.x.y.z()
Anyway, snapshots are free to create and update ๐ช
console.log()
It is now this:
ENOENT: no such file or directory, open 'null'
TypeError: (0 , _scope.scope) is not a function
as scope
has been removed by the transform.
With "enable": true
all the imports of a file will lead to transpiling it, which makes it impossible to test second level modules (those which import functions from others with introscope enabled).
By default "introscope"
.
Should look like
@introscope "exportName": "microscope"
console.log(someGlobalVar)
function foo() {
let someGlobalVar = 1
}
gives
// ...
let _scope.someGlobalVar = 1
// ...
const x = (x(): number);
gives
export const introscope = function(_scope = {}) {
const x = (_scope.x = x(): number);
return _scope;
};
But make it possible to still mock them.
It makes it simpler to test, as all the micro side effects are really hard to enumerate in a big module.
But provide a switch.
- MOCK
+ KEEP
Currently it massively breaks if there are any TS type annotations present in both test file and tested file.
Currently all globals turn into locals and properties on scope. But it would be nice to also set their values:
// - var Date
var _global.Date = Date
export function introscope (_scope) {
_scope.Date = _global.Date
new (0, _scope.Date)()
}
OMG :)
type A = {
localVar: number,
};
const x = () => {
const localVar = '';
};
Iterate not only over scope but also over plan.
// module has only `foo`
const { effects, foo, bar } = effectsLogger(introscope)({
bar: () => {}
})
foo(bar)
Actually as easy as:
require('introscope/logger/jest')
Also, remove const { serialize } = require('jest-serializer');
opaque type OpaqueTokenSecret = string;
export type TokenSecret = OpaqueTokenSecret;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.