Skip to content

Commit

Permalink
fix less tests #963
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Sep 24, 2024
1 parent 204c194 commit bc1ddc5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/jquery.terminal)
![bower](https://img.shields.io/badge/bower-DEV-yellow.svg)
[![Build and test](https://github.com/jcubic/jquery.terminal/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/jquery.terminal/actions/workflows/build.yaml)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&cd09bc55e55c92b2e6b07bb29830ae68)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=devel&e15e2bfb24d4c72436426f15f9be3eba)](https://coveralls.io/github/jcubic/jquery.terminal?branch=devel)
![NPM Downloads](https://img.shields.io/npm/dm/jquery.terminal.svg?style=flat)
[![jsDelivr Downloads](https://data.jsdelivr.com/v1/package/npm/jquery.terminal/badge?style=rounded&n=1)](https://www.jsdelivr.com/package/npm/jquery.terminal)
[![Paid Support](https://img.shields.io/badge/paid-support-354465.svg)](https://support.jcubic.pl/)
Expand Down
86 changes: 43 additions & 43 deletions __tests__/__snapshots__/terminal.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -561,49 +561,49 @@ exports[`Terminal utils $.terminal.from_ansi should render Denis Richie ANSI art
exports[`Terminal utils $.terminal.less should split image 1`] = `
"xxx
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
[[@;;;terminal-less;data:image/jpg,<BLOB>] ]
xxx
~
Expand Down
31 changes: 20 additions & 11 deletions __tests__/terminal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,28 @@ window.Image = class Image {
}
}
};
window.HTMLCanvasElement.prototype.getContext = function () {

const context = {
putImageData: function(data, x, y) {
},
getImageData: function(x, y, w, h) {
return [1,1,1];
},
drawImage: function(image, x1, y1, iw, ih, out_x, out_y, out_w, out_h) {
}
};

global.OffscreenCanvas = function(width, height) {
return {
putImageData: function(data, x, y) {
},
getImageData: function(x, y, w, h) {
return [1,1,1];
},
drawImage: function(image, x1, y1, iw, ih, out_x, out_y, out_w, out_h) {
}
height,
width,
getContext: () => context,
convertToBlob: () => Promise.resolve('<BLOB>')
};
};
window.HTMLCanvasElement.prototype.toBlob = function(fn) {
fn('<BLOB>');
};

window.HTMLCanvasElement.prototype.getContext = () => context;
window.HTMLCanvasElement.prototype.toBlob = (fn) => fn('<BLOB>');
global.URL = window.URL = {
createObjectURL: function(blob) {
return 'data:image/jpg,' + blob;
Expand Down Expand Up @@ -2209,6 +2217,7 @@ describe('Terminal utils', function() {
numRows: rows
});
term.css('width', 800);
term.find('.terminal-output').css('width', 800);
term.focus();
});
function key(ord, key) {
Expand Down
7 changes: 2 additions & 5 deletions js/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
return URL.createObjectURL(blob);
}
});
return defer.promise();
}
function slice(src, options) {
var settings = $.extend({
Expand All @@ -116,10 +115,8 @@
height = img.height;
width = img.width;
}
var canvas = document.createElement('canvas');
var canvas = new OffscreenCanvas(width, height);
var ctx = canvas.getContext('2d', {willReadFrequently: true});
canvas.width = width;
canvas.height = height;
// scale the image to fit the terminal
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, width, height);
(function recur(start) {
Expand Down Expand Up @@ -314,7 +311,7 @@
return text.split('\n');
}
var parts = text.split(img_split_re).filter(Boolean);
var width = term.find('.terminal-fill').width();
var width = term.find('.terminal-output').width();
var result = [];
(function recur() {
function concat_slices(slices) {
Expand Down

0 comments on commit bc1ddc5

Please sign in to comment.