Skip to content

Commit

Permalink
Testing forAllImagesInElement with throttle
Browse files Browse the repository at this point in the history
  • Loading branch information
hejny committed Sep 12, 2021
1 parent 15d84dc commit e8147b1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
4 changes: 3 additions & 1 deletion cypress/integration/forAllImagesInElement.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { forAllImagesInElement } from '../../src/functions/forAllImagesInElement';

context('waitasecond samples', () => {
// TODO: !!! Test working and non working samples

/*
beforeEach(() => {
// TODO: Run server (there is problem with running the express/http here)
// TODO: !!! Run server (there is problem with running the express/http here)
});
*/

Expand Down
4 changes: 4 additions & 0 deletions samples/assets/common.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
img {
min-width: 50px;
min-height: 50px;
max-width: 50vw;
max-height: 30vh;
border: 2px solid black;
}
Binary file added samples/assets/images/photo1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 28 additions & 9 deletions samples/forAllImagesInElement.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,46 @@
</head>
<body>
<h1 class="counter"><h1>
<img src="./assets/images/image.svg" />
<img src="./assets/images/simple.png" />

<!--
TODO:
<script type="module">
import { forAllImagesInElement } from '../dist/main.js';
await forAllImagesInElement(document.body);
window.renderMe();
</script>
<img src="./assets/images/image.svg" />
<img src="./assets/images/simple.png" />
-->


<img src="./assets/images/photo1.jpg?throttle=0" />
<img src="./assets/images/photo1.jpg?throttle=1000" />
<img src="./assets/images/photo1.jpg?throttle=3000" />
<img src="./assets/images/photo1.jpg?throttle=5000" />


<script type="module">
import { forTime } from '../dist/main.js';
import { forAllImagesInElement, forTime } from '../dist/main.js';


forAllImagesInElement(document.body).then(()=>{
document.body.style.backgroundColor='#22ff99';
//window.renderMe();
})

const counterElement = document.querySelector('.counter')
let i = 1;
while(true){
await forTime(10);
counterElement.innerText = i++;
}





</script>


<script type="module">
import { forTime } from '../dist/main.js';


</script>
</body>
</html>
14 changes: 10 additions & 4 deletions samples/samplesServer/samplesServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ const app = express();
//app.use(throttle(10 /* bits per second */));

app.use(async (request, response, next) => {
request;
response;
await forTime(3333);
next();
if (request.query.throttle) {
const throttle = parseInt(request.query.throttle as string);
if (isNaN(throttle)) {
return response
.status(400)
.send(`Query parameter "throttle" should be valid number.`);
}
await forTime(throttle);
}
return next();
});
app.use(serveStatic(staticBasePath, { index: false, cacheControl: false }));
app.use(serveIndex(staticBasePath, { icons: true }));
Expand Down

0 comments on commit e8147b1

Please sign in to comment.