mirror of
https://github.com/janishutz/color-thief.git
synced 2025-11-25 13:54:25 +00:00
test: Add test for CORS
This commit is contained in:
9
cypress/integration/cors_spec.js
Normal file
9
cypress/integration/cors_spec.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
describe('cross domain images with liberal CORS policy', function() {
|
||||||
|
it('load', function() {
|
||||||
|
cy.visit('http://localhost:8080/cypress/test-pages/cors.html');
|
||||||
|
cy.get('#result').should(($el) => {
|
||||||
|
const count = $el.text().split(',').length
|
||||||
|
expect(count).to.equal(3);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
38
cypress/test-pages/cors.html
Normal file
38
cypress/test-pages/cors.html
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||||
|
<title>Color Thief</title>
|
||||||
|
<link rel="stylesheet" href="./screen.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<img src="https://color-thief-cors-test-images.s3-us-west-1.amazonaws.com/boise-spacebar-arcade.jpeg" crossorigin="anonymous" />
|
||||||
|
|
||||||
|
<div id="result"></div>
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
import ColorThief from '../../dist/color-thief.mjs';
|
||||||
|
|
||||||
|
const colorThief = new ColorThief();
|
||||||
|
|
||||||
|
const img = document.querySelector('img');
|
||||||
|
|
||||||
|
function getColorFromImage(img) {
|
||||||
|
const result = colorThief.getColor(img);
|
||||||
|
document.querySelector('#result').innerText = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (img.complete) {
|
||||||
|
getColorFromImage(img);
|
||||||
|
} else {
|
||||||
|
image.addEventListener('load', function() {
|
||||||
|
getColorFromImage(img);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user