mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 18:27:58 +08:00
refactor: remove custom typescript settings for tests
This commit is contained in:
@@ -21,8 +21,8 @@ beforeEach(function () {
|
||||
|
||||
// clear after test
|
||||
afterEach(function () {
|
||||
var isFailed = this.currentTest.state == 'failed';
|
||||
var isManual = this.currentTest.parent.title === 'Manual';
|
||||
var isFailed = this.currentTest?.state === 'failed';
|
||||
var isManual = this.currentTest?.parent?.title === 'Manual';
|
||||
|
||||
Konva.stages.forEach(function (stage) {
|
||||
clearTimeout(stage._mouseDblTimeout);
|
||||
@@ -44,7 +44,7 @@ export const isNode = typeof global.document === 'undefined';
|
||||
export const isBrowser = !isNode;
|
||||
|
||||
export function getContainer() {
|
||||
return document.getElementById('konva-container');
|
||||
return document.getElementById('konva-container')!;
|
||||
}
|
||||
|
||||
export function addContainer() {
|
||||
@@ -69,7 +69,7 @@ export function addStage(attrs?) {
|
||||
});
|
||||
|
||||
if (!isNode) {
|
||||
getContainer().appendChild(container);
|
||||
getContainer().appendChild(container!);
|
||||
}
|
||||
|
||||
return stage;
|
||||
@@ -111,9 +111,7 @@ export function compareCanvases(canvas1, canvas2, tol?, secondTol?) {
|
||||
var equal = imagediff.equal(canvas1, canvas2, tol, secondTol);
|
||||
if (!equal) {
|
||||
const diff = imagediff.diff(canvas1, canvas2);
|
||||
const diffCanvas = createCanvas();
|
||||
|
||||
const context = diffCanvas.getContext('2d');
|
||||
const { canvas: diffCanvas, context } = createCanvasAndContext();
|
||||
context.putImageData(diff, 0, 0);
|
||||
|
||||
var base64 = diffCanvas.toDataURL();
|
||||
@@ -171,12 +169,13 @@ export function compareLayers(layer1: Layer, layer2: Layer, tol?, secondTol?) {
|
||||
);
|
||||
}
|
||||
|
||||
export function createCanvas() {
|
||||
var node = Konva.Util.createCanvasElement();
|
||||
node.width = 578 * Konva.pixelRatio;
|
||||
node.height = 200 * Konva.pixelRatio;
|
||||
node.getContext('2d').scale(Konva.pixelRatio, Konva.pixelRatio);
|
||||
return node;
|
||||
export function createCanvasAndContext() {
|
||||
const canvas = Konva.Util.createCanvasElement();
|
||||
canvas.width = 578 * Konva.pixelRatio;
|
||||
canvas.height = 200 * Konva.pixelRatio;
|
||||
const context = canvas.getContext('2d')!;
|
||||
context.scale(Konva.pixelRatio, Konva.pixelRatio);
|
||||
return { canvas, context };
|
||||
}
|
||||
|
||||
export function showHit(layer) {
|
||||
@@ -189,7 +188,10 @@ export function showHit(layer) {
|
||||
getContainer().appendChild(canvas);
|
||||
}
|
||||
|
||||
export function simulateMouseDown(stage, pos) {
|
||||
export function simulateMouseDown(
|
||||
stage: Stage,
|
||||
pos: { x: number; y: number; button?: number }
|
||||
) {
|
||||
simulatePointerDown(stage, pos);
|
||||
var top = isNode ? 0 : stage.content.getBoundingClientRect().top;
|
||||
|
||||
@@ -198,10 +200,13 @@ export function simulateMouseDown(stage, pos) {
|
||||
clientY: pos.y + top,
|
||||
button: pos.button || 0,
|
||||
type: 'mousedown',
|
||||
});
|
||||
} as any);
|
||||
}
|
||||
|
||||
export function simulateMouseMove(stage, pos) {
|
||||
export function simulateMouseMove(
|
||||
stage: Stage,
|
||||
pos: { x: number; y: number; button?: number }
|
||||
) {
|
||||
simulatePointerMove(stage, pos);
|
||||
var top = isNode ? 0 : stage.content.getBoundingClientRect().top;
|
||||
var evt = {
|
||||
@@ -212,7 +217,7 @@ export function simulateMouseMove(stage, pos) {
|
||||
};
|
||||
|
||||
Konva.DD._drag(evt);
|
||||
stage._pointermove(evt);
|
||||
stage._pointermove(evt as any);
|
||||
}
|
||||
|
||||
export function simulateMouseUp(stage, pos) {
|
||||
@@ -344,7 +349,13 @@ export function simulateTouchEnd(stage, pos, changed?) {
|
||||
Konva.DD._endDragAfter(evt);
|
||||
}
|
||||
|
||||
export function simulatePointerDown(stage: Stage, pos) {
|
||||
type SimulatedPointerEvent = {
|
||||
x: number;
|
||||
y: number;
|
||||
button?: number;
|
||||
pointerId?: number;
|
||||
};
|
||||
export function simulatePointerDown(stage: Stage, pos: SimulatedPointerEvent) {
|
||||
var top = isNode ? 0 : stage.content.getBoundingClientRect().top;
|
||||
stage._pointerdown({
|
||||
clientX: pos.x,
|
||||
@@ -355,7 +366,7 @@ export function simulatePointerDown(stage: Stage, pos) {
|
||||
} as any);
|
||||
}
|
||||
|
||||
export function simulatePointerMove(stage: Stage, pos) {
|
||||
export function simulatePointerMove(stage: Stage, pos: SimulatedPointerEvent) {
|
||||
var top = isNode ? 0 : stage.content.getBoundingClientRect().top;
|
||||
var evt = {
|
||||
clientX: pos.x,
|
||||
@@ -369,7 +380,7 @@ export function simulatePointerMove(stage: Stage, pos) {
|
||||
// Konva.DD._drag(evt);
|
||||
}
|
||||
|
||||
export function simulatePointerUp(stage: Stage, pos) {
|
||||
export function simulatePointerUp(stage: Stage, pos: SimulatedPointerEvent) {
|
||||
var top = isNode ? 0 : stage.content.getBoundingClientRect().top;
|
||||
var evt = {
|
||||
clientX: pos.x,
|
||||
|
Reference in New Issue
Block a user