mirror of
https://github.com/twitter/twemoji.git
synced 2025-04-29 02:47:25 +09:00
Merge c7f864fff14162c071584b14a4da60777764df46 into d94f4cf793e6d5ca592aa00f58a88f6a4229ad43
This commit is contained in:
commit
cda024f111
@ -1,65 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>twemoji test</title>
|
||||
<meta http-equiv="content-language" content="en-US"/>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
|
||||
<!--
|
||||
### what is this ?
|
||||
this is a battle test script called wru:
|
||||
https://github.com/WebReflection/wru
|
||||
|
||||
It is compatible with every JS engine you can think of
|
||||
including ancient browsers.
|
||||
|
||||
If you see all tests as green, it means it worked.
|
||||
|
||||
-->
|
||||
<style type="text/css">
|
||||
#wru {
|
||||
font-family: sans-serif;
|
||||
font-size: 11pt;
|
||||
border: 1px solid #333;
|
||||
}
|
||||
#wru div {
|
||||
cursor: default;
|
||||
padding: 0;
|
||||
color: #000;
|
||||
}
|
||||
#wru div span,
|
||||
#wru div strong {
|
||||
display: block;
|
||||
padding: 4px;
|
||||
margin: 0;
|
||||
}
|
||||
#wru div ul {
|
||||
margin: 0;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
#wru div.pass {
|
||||
background: #90EE90;
|
||||
}
|
||||
#wru div.fail {
|
||||
background: #FF6347;
|
||||
}
|
||||
#wru div.error {
|
||||
background: #000;
|
||||
color: #FFF;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wru"></div>
|
||||
<script src="../../dist/twemoji.js"></script>
|
||||
<script>
|
||||
/*!
|
||||
(C) Andrea Giammarchi, @WebReflection - Mit Style License
|
||||
*/
|
||||
(function(wru){
|
||||
window.wru = wru;
|
||||
}(function(Y){function j(){A=K.call(m);if(A){if(typeof A=="function"){A={name:A[S]||"anonymous",test:A}}(P=l(l(Z.node,"div"),"span"))[E]=((ag(A,S)&&A[S])||(ag(A,e)&&A[e])||Q)+i+i;a=[];u=[];T=[];ab={};b("setup");T[ah]||b("test");N||r()}else{t()}}function p(aj){try{return O.call(h,aj)}catch(ai){return h.createElement(aj)}}function l(ai,aj){return ai.appendChild(p(aj))}function g(ai){P[E]=x.call(P[E],0,-2)+i+ai}function t(){var ak=Z.node.insertBefore(p("div"),Z.node.firstChild),al,aj,ai;if(ad){ai=aj="error";al="There Are Errors: "+ad}else{if(C){ai=aj="fail";al=C+" Tests Failed"}else{ai=aj="pass";al="Passed "+s+" Tests"}}Z.status=ai;ak[E]="<strong>"+al+"</strong>";ak.className=aj}function G(){var ai=this.lastChild.style;ai.display=ai.display=="none"?"block":"none"}function c(ai){P[E]+="<ul>"+D+v.call(ai,d+D)+d+"</ul>";(P.onclick=G).call(P)}function r(){f();s+=a[ah];C+=u[ah];ad+=T[ah];g("("+v.call([a[ah],M=u[ah],T[ah]],", ")+")");P=P.parentNode;T[ah]?c(T,W="error"):(M?c(u,W="fail"):W="pass");P.className=W;M=0;W=i;j()}function b(ai){if(ag(A,ai)){try{A[ai](ab)}catch(aj){aa.call(T,i+aj)}}}function ag(aj,ai){return q.call(aj,ai)}function w(){return F()<0.5?-1:1}function f(){if(R){H(R);R=0}b("teardown")}var Z={assert:function U(aj,ai){if(arguments[ah]==1){ai=aj;aj=Q}z=I;aa.call(ai?a:u,W+aj);return ai},async:function V(aj,am,ak,al){al=++N;if(typeof aj=="function"){ak=am;am=aj;aj="asynchronous test #"+al}ak=X(function(){al=0;aa.call(u,aj);--N||(R=X(r,0))},L(ak||y)||y);return function ai(){if(!al){return}z=ae;W=aj+": ";try{am.apply(this,arguments)}catch(an){z=I;aa.call(T,W+an)}W=i;if(z){H(ak);--N||(R=X(r,0))}}},test:function n(ai,aj){Z.after=aj||function(){};m=J.apply(m,[ai]);Z.random&&af.call(m,w);N||j()}},I=true,ae=!I,y=100,i=" ",Q="unknown",ah="length",S="name",e="description",D="<li>",d="</li>",k="\\|/-",q=Z.hasOwnProperty,W=i,ac=W.charAt,x=W.slice,m=[],J=m.concat,v=m.join,aa=m.push,K=m.shift,af=m.sort,N=0,M=0,s=0,C=0,ad=0,R=0,E="innerHTML",h=Y.document,O=h.createElement,B,L,F,X,H,A,P,a,u,T,ab,z;B=Y.Math;L=B.abs;F=B.random;X=Y.setTimeout;H=Y.clearTimeout;Z.node=(h.getElementById("wru")||h.body||h.documentElement);Y.setInterval(function(){N&&g(ac.call(k,M++%4))},y);undefined;Z.log=function o(aj,ai){ai?alert(aj):(typeof console!="undefined")&&console.log(aj)};y*=y;Z.random=ae;return Z}(this)));
|
||||
</script>
|
||||
<script src="test.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>twemoji test</title>
|
||||
<meta http-equiv="content-language" content="en-US"/>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="wru"></div>
|
||||
<script src="twemoji.js"></script>
|
||||
<script src="test.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
30
src/test/styles.css
Normal file
30
src/test/styles.css
Normal file
@ -0,0 +1,30 @@
|
||||
#wru {
|
||||
font-family: sans-serif;
|
||||
font-size: 11pt;
|
||||
border: 1px solid #333;
|
||||
}
|
||||
#wru div {
|
||||
cursor: default;
|
||||
padding: 0;
|
||||
color: #000;
|
||||
}
|
||||
#wru div span,
|
||||
#wru div strong {
|
||||
display: block;
|
||||
padding: 4px;
|
||||
margin: 0;
|
||||
}
|
||||
#wru div ul {
|
||||
margin: 0;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
#wru div.pass {
|
||||
background: #90EE90;
|
||||
}
|
||||
#wru div.fail {
|
||||
background: #FF6347;
|
||||
}
|
||||
#wru div.error {
|
||||
background: #000;
|
||||
color: #FFF;
|
||||
}
|
@ -1,48 +1,57 @@
|
||||
var
|
||||
webpage = require('webpage'),
|
||||
urls = [
|
||||
'src/test/index.html'
|
||||
]
|
||||
;
|
||||
const webpage = require('webpage');
|
||||
const urls = ['src/test/index.html'];
|
||||
|
||||
(function test() {'use strict';
|
||||
var page, url = urls.shift();
|
||||
if (!url) return phantom.exit(0);
|
||||
console.log('Loading: ' + url);
|
||||
page = webpage.create();
|
||||
page.open(url, function (status) {
|
||||
if (status === 'success') {
|
||||
setTimeout(function () {
|
||||
var results = page.evaluate(function() {
|
||||
// remove the first node with the total from the following counts
|
||||
var passed = Math.max(0, document.querySelectorAll('.pass').length - 1);
|
||||
var resultHeader = document.querySelector('#wru strong');
|
||||
return {
|
||||
// retrieve the total executed tests number
|
||||
total: ''.concat(
|
||||
passed,
|
||||
' tests (',
|
||||
resultHeader ? resultHeader.textContent.replace(/\D/g, '') : 'no',
|
||||
' assertions)'
|
||||
),
|
||||
async function runTests() {
|
||||
for (const url of urls) {
|
||||
console.log(`Loading: ${url}`);
|
||||
const page = await new Promise((resolve, reject) => {
|
||||
const page = webpage.create();
|
||||
page.onLoadFinished = status => {
|
||||
if (status === 'success') resolve(page);
|
||||
else reject(new Error(`Failed to load: ${url}`));
|
||||
};
|
||||
page.open(url);
|
||||
});
|
||||
|
||||
try {
|
||||
const results = await evaluateTestResults(page);
|
||||
printTestResults(results);
|
||||
if (results.passed === 0 || results.failed + results.errored > 0) {
|
||||
console.error('Tests failed.');
|
||||
process.exit(1);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
page.close();
|
||||
}
|
||||
}
|
||||
console.log('All tests completed successfully.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
async function evaluateTestResults(page) {
|
||||
return await page.evaluate(() => {
|
||||
const passed = Math.max(0, document.querySelectorAll('.pass').length - 1);
|
||||
const resultHeader = document.querySelector('#wru strong');
|
||||
return {
|
||||
total: `${passed} tests (${resultHeader ? resultHeader.textContent.replace(/\D/g, '') : 'no'} assertions)`,
|
||||
passed: passed,
|
||||
failed: Math.max(0, document.querySelectorAll('.fail').length - 1),
|
||||
errored: Math.max(0, document.querySelectorAll('.error').length - 1)
|
||||
};
|
||||
});
|
||||
page.stop();
|
||||
page.close();
|
||||
console.log('- - - - - - - - - -');
|
||||
console.log('total: ' + results.total);
|
||||
console.log('- - - - - - - - - -');
|
||||
console.log('passed: ' + results.passed);
|
||||
console.log('failed: ' + results.failed);
|
||||
console.log('errored: ' + results.errored);
|
||||
console.log('- - - - - - - - - -');
|
||||
if (results.passed === 0 || 0 < results.failed + results.errored) {
|
||||
phantom.exit(1);
|
||||
} else test();
|
||||
}, 1000);
|
||||
} else phantom.exit(1);
|
||||
});
|
||||
}());
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function printTestResults(results) {
|
||||
console.log('- - - - - - - - - -');
|
||||
console.log(`total: ${results.total}`);
|
||||
console.log('- - - - - - - - - -');
|
||||
console.log(`passed: ${results.passed}`);
|
||||
console.log(`failed: ${results.failed}`);
|
||||
console.log(`errored: ${results.errored}`);
|
||||
console.log('- - - - - - - - - -');
|
||||
}
|
||||
|
||||
runTests();
|
||||
|
208
src/test/twemoji.js
Normal file
208
src/test/twemoji.js
Normal file
@ -0,0 +1,208 @@
|
||||
/*!
|
||||
(C) Andrea Giammarchi, @WebReflection - Mit Style License
|
||||
*/
|
||||
(function(wru) {
|
||||
window.wru = wru;
|
||||
}(function(Y) {
|
||||
function j() {
|
||||
A = K.call(m);
|
||||
if (A) {
|
||||
if (typeof A == "function") {
|
||||
A = {
|
||||
name: A[S] || "anonymous",
|
||||
test: A
|
||||
}
|
||||
}(P = l(l(Z.node, "div"), "span"))[E] = ((ag(A, S) && A[S]) || (ag(A, e) && A[e]) || Q) + i + i;
|
||||
a = [];
|
||||
u = [];
|
||||
T = [];
|
||||
ab = {};
|
||||
b("setup");
|
||||
T[ah] || b("test");
|
||||
N || r()
|
||||
} else {
|
||||
t()
|
||||
}
|
||||
}
|
||||
|
||||
function p(aj) {
|
||||
try {
|
||||
return O.call(h, aj)
|
||||
} catch (ai) {
|
||||
return h.createElement(aj)
|
||||
}
|
||||
}
|
||||
|
||||
function l(ai, aj) {
|
||||
return ai.appendChild(p(aj))
|
||||
}
|
||||
|
||||
function g(ai) {
|
||||
P[E] = x.call(P[E], 0, -2) + i + ai
|
||||
}
|
||||
|
||||
function t() {
|
||||
var ak = Z.node.insertBefore(p("div"), Z.node.firstChild),
|
||||
al, aj, ai;
|
||||
if (ad) {
|
||||
ai = aj = "error";
|
||||
al = "There Are Errors: " + ad
|
||||
} else {
|
||||
if (C) {
|
||||
ai = aj = "fail";
|
||||
al = C + " Tests Failed"
|
||||
} else {
|
||||
ai = aj = "pass";
|
||||
al = "Passed " + s + " Tests"
|
||||
}
|
||||
}
|
||||
Z.status = ai;
|
||||
ak[E] = "<strong>" + al + "</strong>";
|
||||
ak.className = aj
|
||||
}
|
||||
|
||||
function G() {
|
||||
var ai = this.lastChild.style;
|
||||
ai.display = ai.display == "none" ? "block" : "none"
|
||||
}
|
||||
|
||||
function c(ai) {
|
||||
P[E] += "<ul>" + D + v.call(ai, d + D) + d + "</ul>";
|
||||
(P.onclick = G).call(P)
|
||||
}
|
||||
|
||||
function r() {
|
||||
f();
|
||||
s += a[ah];
|
||||
C += u[ah];
|
||||
ad += T[ah];
|
||||
g("(" + v.call([a[ah], M = u[ah], T[ah]], ", ") + ")");
|
||||
P = P.parentNode;
|
||||
T[ah] ? c(T, W = "error") : (M ? c(u, W = "fail") : W = "pass");
|
||||
P.className = W;
|
||||
M = 0;
|
||||
W = i;
|
||||
j()
|
||||
}
|
||||
|
||||
function b(ai) {
|
||||
if (ag(A, ai)) {
|
||||
try {
|
||||
A[ai](ab)
|
||||
} catch (aj) {
|
||||
aa.call(T, i + aj)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ag(aj, ai) {
|
||||
return q.call(aj, ai)
|
||||
}
|
||||
|
||||
function w() {
|
||||
return F() < 0.5 ? -1 : 1
|
||||
}
|
||||
|
||||
function f() {
|
||||
if (R) {
|
||||
H(R);
|
||||
R = 0
|
||||
}
|
||||
b("teardown")
|
||||
}
|
||||
var Z = {
|
||||
assert: function U(aj, ai) {
|
||||
if (arguments[ah] == 1) {
|
||||
ai = aj;
|
||||
aj = Q
|
||||
}
|
||||
z = I;
|
||||
aa.call(ai ? a : u, W + aj);
|
||||
return ai
|
||||
},
|
||||
async: function V(aj, am, ak, al) {
|
||||
al = ++N;
|
||||
if (typeof aj == "function") {
|
||||
ak = am;
|
||||
am = aj;
|
||||
aj = "asynchronous test #" + al
|
||||
}
|
||||
ak = X(function() {
|
||||
al = 0;
|
||||
aa.call(u, aj);
|
||||
--N || (R = X(r, 0))
|
||||
}, L(ak || y) || y);
|
||||
return function ai() {
|
||||
if (!al) {
|
||||
return
|
||||
}
|
||||
z = ae;
|
||||
W = aj + ": ";
|
||||
try {
|
||||
am.apply(this, arguments)
|
||||
} catch (an) {
|
||||
z = I;
|
||||
aa.call(T, W + an)
|
||||
}
|
||||
W = i;
|
||||
if (z) {
|
||||
H(ak);
|
||||
--N || (R = X(r, 0))
|
||||
}
|
||||
}
|
||||
},
|
||||
test: function n(ai, aj) {
|
||||
Z.after = aj || function() {};
|
||||
m = J.apply(m, [ai]);
|
||||
Z.random && af.call(m, w);
|
||||
N || j()
|
||||
}
|
||||
},
|
||||
I = true,
|
||||
ae = !I,
|
||||
y = 100,
|
||||
i = " ",
|
||||
Q = "unknown",
|
||||
ah = "length",
|
||||
S = "name",
|
||||
e = "description",
|
||||
D = "<li>",
|
||||
d = "</li>",
|
||||
k = "\\|/-",
|
||||
q = Z.hasOwnProperty,
|
||||
W = i,
|
||||
ac = W.charAt,
|
||||
x = W.slice,
|
||||
m = [],
|
||||
J = m.concat,
|
||||
v = m.join,
|
||||
aa = m.push,
|
||||
K = m.shift,
|
||||
af = m.sort,
|
||||
N = 0,
|
||||
M = 0,
|
||||
s = 0,
|
||||
C = 0,
|
||||
ad = 0,
|
||||
R = 0,
|
||||
E = "innerHTML",
|
||||
h = Y.document,
|
||||
O = h.createElement,
|
||||
B, L, F, X, H, A, P, a, u, T, ab, z;
|
||||
B = Y.Math;
|
||||
L = B.abs;
|
||||
F = B.random;
|
||||
X = Y.setTimeout;
|
||||
H = Y.clearTimeout;
|
||||
Z.node = (h.getElementById("wru") || h.body || h.documentElement);
|
||||
Y.setInterval(function() {
|
||||
N && g(ac.call(k, M++ % 4))
|
||||
}, y);
|
||||
undefined;
|
||||
Z.log = function o(aj, ai) {
|
||||
ai ? alert(aj) : (typeof console != "undefined") && console.log(aj)
|
||||
};
|
||||
y *= y;
|
||||
Z.random = ae;
|
||||
return Z
|
||||
}(this)));
|
Loading…
x
Reference in New Issue
Block a user