Skip to content

Commit

Permalink
Merge branch 'better_tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpyder committed May 22, 2024
2 parents 5360544 + 774af37 commit 40e4b6f
Show file tree
Hide file tree
Showing 113 changed files with 4,471 additions and 1,081 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
cache: yarn
- run: yarn install
- run: yarn test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ node_modules/
/lib/js/src
/lib/js/tests/testHelpers.js
npm-debug.log
.yarn/install-state.gz
893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.2.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.2.cjs
3 changes: 0 additions & 3 deletions lib/js/examples/dom_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,17 @@ Belt_Option.map(Belt_Option.flatMap(Webapi__Dom__Document.asHtmlDocument(documen
return Caml_option.nullable_to_opt(prim.body);
})), (function (body) {
body.appendChild(el);

}));

document.createElement("div").addEventListener("mousemove", (function (e) {
console.log([
e.screenX,
e.screenY
]);

}));

function handleClick(param) {
console.log("clicked");

}

window.addEventListener("click", handleClick);
Expand Down
6 changes: 2 additions & 4 deletions lib/js/examples/image_examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ function processImage(url) {
var maybeImg = Curry._1(Webapi__Dom__HtmlImageElement.ofElement, e);
maybeImg.src = url;
maybeImg.addEventListener("load", (function ($$event) {
return resolve($$event);
resolve($$event);
}));
maybeImg.addEventListener("error", (function (error) {
return reject(error);
reject(error);
}));
var body = Belt_Option.flatMap(Webapi__Dom__Document.asHtmlDocument(document), (function (prim) {
return Caml_option.nullable_to_opt(prim.body);
}));
body.appendChild(maybeImg);
body.removeChild(maybeImg);

}));
}

Expand All @@ -33,7 +32,6 @@ var test = processImage(url).then(function ($$event) {
var width = img.naturalWidth;
var height = img.naturalHeight;
console.log("width", width, "height", height);

});

exports.url = url;
Expand Down
2 changes: 0 additions & 2 deletions lib/js/examples/webapi_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ var socket = new WebSocket("ws://localhost:8080");

socket.addEventListener("open", (function (param) {
socket.send("Hello Server!");

}));

socket.addEventListener("message", (function ($$event) {
console.log("Message from server ", $$event.data);

}));

/* socket Not a pure module */
68 changes: 68 additions & 0 deletions lib/js/tests/Webapi/Canvas/Webapi_Canvas__WebGl__test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';


var canvasEl = document.createElement("canvas");

var ctx = canvasEl.getContext("webgl");

ctx.clear(5);

ctx.clearColor(0, 1, 2, 3);

ctx.enable(5);

ctx.disable(5);

ctx.blendFunc(0, 1);

ctx.cullFace(5);

var buf = ctx.createBuffer();

ctx.deleteBuffer(buf);

ctx.bindBuffer(5, buf);

ctx.bufferData(5, new Uint16Array(5), 5);

ctx.bufferData(5, new Float32Array(5), 5);

var program = ctx.createProgram();

ctx.linkProgram(program);

ctx.useProgram(program);

var programlog = ctx.getProgramInfoLog(program);

ctx.bindAttribLocation(program, 5, "");

var shader = ctx.createShader(5);

ctx.shaderSource(shader, "");

ctx.compileShader(shader);

ctx.attachShader(program, shader);

var shaderlog = ctx.getShaderInfoLog(shader);

ctx.drawElements(0, 1, 2, 3);

ctx.enableVertexAttribArray(5);

ctx.vertexAttribPointer(0, 1, 2, false, 3, 4);

var loc = ctx.getAttribLocation(program, "");

ctx.drawArrays(0, 1, 2);

exports.canvasEl = canvasEl;
exports.ctx = ctx;
exports.buf = buf;
exports.program = program;
exports.programlog = programlog;
exports.shader = shader;
exports.shaderlog = shaderlog;
exports.loc = loc;
/* canvasEl Not a pure module */
67 changes: 29 additions & 38 deletions lib/js/tests/Webapi/Canvas/Webapi__Canvas__Canvas2d__test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var List = require("rescript/lib/js/list.js");
var Webapi__Canvas__Canvas2d = require("../../../src/Webapi/Canvas/Webapi__Canvas__Canvas2d.js");

var canvasEl = document.createElement("canvas");
Expand Down Expand Up @@ -95,45 +94,23 @@ ctx.arc(1, 1, 4, 1, 3, true);

ctx.rect(0, 0, 10, 10);

ctx.isPointInPath(0, 0);
var pointInPath = ctx.isPointInPath(0, 0);

var linearGradient = ctx.createLinearGradient(0.0, 0.0, 0.0, 0.0);

ctx.strokeStyle = linearGradient;

ctx.createRadialGradient(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
var radialGradient = ctx.createRadialGradient(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);

linearGradient.addColorStop(0.0, "red");

var partial_arg = document.createElement("img");

List.map((function (param) {
return createPattern(ctx, partial_arg, (function () {
switch (param) {
case "repeat" :
return "repeat";
case "repeatX" :
return "repeat-x";
case "repeatY" :
return "repeat-y";
case "noRepeat" :
return "no-repeat";

}
})());
}), {
hd: "noRepeat",
tl: {
hd: "repeat",
tl: {
hd: "repeatX",
tl: {
hd: "repeatY",
tl: /* [] */0
}
}
}
});
var noRepeatPatern = createPattern(ctx, document.createElement("img"), "no-repeat");

var repeatPatern = createPattern(ctx, document.createElement("img"), "repeat");

var repeatXPatern = createPattern(ctx, document.createElement("img"), "repeat-x");

var repeatYPatern = createPattern(ctx, document.createElement("img"), "repeat-y");

var measureText = ctx.measureText("foo");

Expand All @@ -151,15 +128,19 @@ ctx.drawImage(image, 0.0, 0.0, 16.0, 16.0);

ctx.drawImage(image, 0.0, 0.0, 16.0, 16.0, 0.0, 0.0, 16.0, 16.0);

var imageData = ctx.createImageData(0.0, 0.0);
var imageFromCoords = ctx.createImageData(0.0, 0.0);

var imageFromData = ctx.createImageData(imageFromCoords);

var w = imageFromCoords.width;

ctx.createImageData(imageData);
var h = imageFromCoords.height;

ctx.getImageData(0.0, 0.0, 0.0, 0.0);
var frameFromImage = ctx.getImageData(0.0, 0.0, 0.0, 0.0);

ctx.putImageData(imageData, 0.0, 0.0);
ctx.putImageData(imageFromCoords, 0.0, 0.0);

ctx.putImageData(imageData, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
ctx.putImageData(imageFromCoords, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);

ctx.font = "10px Courier";

Expand Down Expand Up @@ -187,10 +168,20 @@ ctx.fill(path);

exports.canvasEl = canvasEl;
exports.ctx = ctx;
exports.pointInPath = pointInPath;
exports.linearGradient = linearGradient;
exports.radialGradient = radialGradient;
exports.noRepeatPatern = noRepeatPatern;
exports.repeatPatern = repeatPatern;
exports.repeatXPatern = repeatXPatern;
exports.repeatYPatern = repeatYPatern;
exports.measureText = measureText;
exports.width = width;
exports.image = image;
exports.imageData = imageData;
exports.imageFromCoords = imageFromCoords;
exports.imageFromData = imageFromData;
exports.w = w;
exports.h = h;
exports.frameFromImage = frameFromImage;
exports.path = path;
/* canvasEl Not a pure module */
39 changes: 38 additions & 1 deletion lib/js/tests/Webapi/Dom/Webapi__Dom__AnimationEvent__test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,50 @@ var Webapi__Dom__AnimationEvent = require("../../../src/Webapi/Dom/Webapi__Dom__

var $$event = new AnimationEvent("my-event");

Curry._1(Webapi__Dom__AnimationEvent.eventPhase, $$event);
var bubbles = $$event.bubbles;

var cancelable = $$event.cancelable;

var composed = $$event.composed;

var currentTarget = $$event.currentTarget;

var defaultPrevented = $$event.defaultPrevented;

var eventPhase = Curry._1(Webapi__Dom__AnimationEvent.eventPhase, $$event);

var target = $$event.target;

var timeStamp = $$event.timeStamp;

var type_ = $$event.type;

var isTrusted = $$event.isTrusted;

$$event.preventDefault();

$$event.stopImmediatePropagation();

$$event.stopPropagation();

var animationName = $$event.animationName;

var elapsedTime = $$event.elapsedTime;

var pseudoElement = $$event.pseudoElement;

exports.$$event = $$event;
exports.bubbles = bubbles;
exports.cancelable = cancelable;
exports.composed = composed;
exports.currentTarget = currentTarget;
exports.defaultPrevented = defaultPrevented;
exports.eventPhase = eventPhase;
exports.target = target;
exports.timeStamp = timeStamp;
exports.type_ = type_;
exports.isTrusted = isTrusted;
exports.animationName = animationName;
exports.elapsedTime = elapsedTime;
exports.pseudoElement = pseudoElement;
/* event Not a pure module */
33 changes: 32 additions & 1 deletion lib/js/tests/Webapi/Dom/Webapi__Dom__BeforeUnloadEvent__test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,44 @@ var Webapi__Dom__BeforeUnloadEvent = require("../../../src/Webapi/Dom/Webapi__Do

var $$event = new BeforeUnloadEvent("my-event");

Curry._1(Webapi__Dom__BeforeUnloadEvent.eventPhase, $$event);
var bubbles = $$event.bubbles;

var cancelable = $$event.cancelable;

var composed = $$event.composed;

var currentTarget = $$event.currentTarget;

var defaultPrevented = $$event.defaultPrevented;

var eventPhase = Curry._1(Webapi__Dom__BeforeUnloadEvent.eventPhase, $$event);

var target = $$event.target;

var timeStamp = $$event.timeStamp;

var type_ = $$event.type;

var isTrusted = $$event.isTrusted;

$$event.preventDefault();

$$event.stopImmediatePropagation();

$$event.stopPropagation();

var returnValue = $$event.returnValue;

exports.$$event = $$event;
exports.bubbles = bubbles;
exports.cancelable = cancelable;
exports.composed = composed;
exports.currentTarget = currentTarget;
exports.defaultPrevented = defaultPrevented;
exports.eventPhase = eventPhase;
exports.target = target;
exports.timeStamp = timeStamp;
exports.type_ = type_;
exports.isTrusted = isTrusted;
exports.returnValue = returnValue;
/* event Not a pure module */
Loading

0 comments on commit 40e4b6f

Please sign in to comment.