Comments (6)
@ilyagelman @morsdyce Should work just fine, add this to any page to test (ES6 must be supported):
/**
* Shredder API Dummy
*/
window.Shredder = {
sayHi: (one, two) => {
console.log('API sayHi', one, two);
}
};
/**
* Add an iFrame element for the Shredder UI
*/
let iframeElm = document.createElement('iframe');
iframeElm.src = '';
iframeElm.width = '100%';
iframeElm.height = '100%';
document.body.appendChild(iframeElm);
/**
* Get the iFrame's document, body and head
*/
let iframeRoot = iframeElm.contentDocument;
let iframeBody = iframeRoot.body || iframeRoot.querySelector('body');
let iframeHead = iframeRoot.querySelector('head') || iframeBody;
/**
* Prepare Shredder UI Styles
*/
let uiStyle = document.createElement('style');
uiStyle.textContent = `
h1 {
background: lightblue;
}
`;
/**
* Prepare Shredder UI View
*/
let uiHtml = document.createElement('div');
uiHtml.innerHTML = `
<div>
<h1>Bad Ass API Mocking</h1>
</div>
`;
/**
* Prepare Shredder UI Code
*/
let uiScript = document.createElement('script');
uiScript.type = 'text/javascript';
uiScript.text = `
// Execute methods from the Shredder API
window.parent.Shredder.sayHi('Foo', 'Bar')
`;
/**
* Inject the Shredder UI
*/
iframeBody.appendChild(uiHtml);
iframeHead.appendChild(uiStyle);
iframeBody.appendChild(uiScript);
Open questions
- The code and styles must be post transpilation, that's no issue on production, we could have them as strings and just inject them, but how would it work in development?
- We would still need some CSS to position the iframe and handle showing/hiding it, this would have to be added to the original page, the iframe styles would have to be as explicit as possible to avoid external styles from affecting it.
from mimic.
@alexilyaev What about mocking xhr requests within iframe?
from mimic.
@ilyagelman You don't, you mock them outside as usual, the iFrame is just the carrier that will communicate with the Shredder API.
from mimic.
Maayan wrote:
Please keep in mind for whoever implements the iframe, you need to test it in both loading scenarios.
- Global var via script injection
- Common js import (no global var is created at this method currently)
from mimic.
+1 for including this here.
On Wed, Dec 2, 2015 at 7:47 PM, Alex Ilyaev [email protected]
wrote:
Maayan wrote:
Please keep in mind for whoever implements the iframe, you need to test it
in both loading scenarios.
- Global var via script injection
- Common js import (no global var is created at this method currently)
—
Reply to this email directly or view it on GitHub
#22 (comment).
from mimic.
@ilyagelman Does it work with the 2 points Maayan mentioned?
from mimic.
Related Issues (20)
- Apply mocks once they are loaded HOT 4
- Dynamic import semiworking with import('mimic'); but working with require('mimic');. HOT 2
- getMatchingMock returns disabled mocks
- add support for sandbox / Iframes
- Keep mimic open on refresh HOT 2
- Set stopwatch to zero HOT 4
- Remote server black screen HOT 2
- Add virtualization to log
- Add reload & record button
- npm install issue HOT 1
- Match dynamic query parameters like dates HOT 1
- Import from postman collection HOT 2
- Added button to clean logs HOT 2
- When duplicating a mock, editing changes the original mock HOT 3
- Use secure connection: http => https
- Set default Content-Type to plain-text if it is not provided in response or request
- Request / Response body JSON validation
- Disable other scenarios
- Error response doesn't work with Angular HOT 3
- Does this support regular expression of request URL ?
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 mimic.