Skip to content

Commit

Permalink
ci(): Node test cleanup - remove JSDOM custom resource loader (#8707)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Feb 19, 2023
1 parent 7a3954a commit b5416c6
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 84 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- ci(test): cleanup node config (#8694 followup) [#8707](https://github.com/fabricjs/fabric.js/issues/8707)
- fix(): BREAKING set/discard active object return value, discard active object now return false if no discard happened [#8672](https://github.com/fabricjs/fabric.js/issues/8672)
- fix(): selection logic to support nested multiselection [#8665](https://github.com/fabricjs/fabric.js/issues/8665)
- fix(test): remove bad node config [#8694](https://github.com/fabricjs/fabric.js/issues/8694)
Expand Down
3 changes: 1 addition & 2 deletions fabric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ import { Textbox } from './src/shapes/Textbox';
import { Group } from './src/shapes/Group';
import { ActiveSelection } from './src/shapes/ActiveSelection';
import { Image } from './src/shapes/Image';
import { getEnv, getDocument, getWindow, setEnvForTests } from './src/env';
import { getEnv, getDocument, getWindow } from './src/env';
import { createCollectionMixin } from './src/Collection';
import { parseAttributes } from './src/parser/parseAttributes';
import { parseElements } from './src/parser/parseElements';
Expand Down Expand Up @@ -416,7 +416,6 @@ export {
getEnv,
getDocument,
getWindow,
setEnvForTests,
parseStyleAttribute,
parsePointsAttribute,
parseFontDeclaration,
Expand Down
13 changes: 0 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"busboy": "^1.6.0",
"chalk": "^2.4.1",
"commander": "^9.1.0",
"deep-object-diff": "^1.1.7",
"eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
"fireworm": "^0.7.2",
Expand Down
5 changes: 0 additions & 5 deletions src/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,3 @@ export const getEnv = () => env || getBrowserEnv();
export const getDocument = (): Document => getEnv().document;

export const getWindow = (): Window | DOMWindow => getEnv().window;

export const setEnvForTests = (window: Window | DOMWindow) => {
env.document = window.document;
env.window = window;
};
7 changes: 0 additions & 7 deletions test/lib/visualTestLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,15 @@
exports.visualTestLoop = function(QUnit) {
var _pixelMatch;
var visualCallback;
var imageDataToChalk;
if (isNode()) {
_pixelMatch = global.pixelmatch;
visualCallback = global.visualCallback;
imageDataToChalk = global.imageDataToChalk;
}
else {
if (window) {
_pixelMatch = window.pixelmatch;
visualCallback = window.visualCallback;
}
imageDataToChalk = function() { return ''; };
}

var pixelmatchOptions = {
Expand Down Expand Up @@ -179,10 +176,6 @@
isOK,
testName + ' [' + golden + '] has too many different pixels ' + differentPixels + '(' + okDiff + ') representing ' + percDiff + '% (>' + (percentage * 100) + '%)'
);
if (!isOK) {
var stringa = imageDataToChalk(output);
console.log(stringa);
}
if (!testObj.testOnly && ((!isOK && QUnit.debugVisual) || QUnit.recreateVisualRefs)) {
await generateGolden(getGoldeName(golden), renderedCanvas);
}
Expand Down
57 changes: 1 addition & 56 deletions test/node_test_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ require('source-map-support/register');
require('./lib/assert');
// set the fabric framework as a global for tests
var chalk = require('chalk');
var diff = require('deep-object-diff').diff;
var commander = require('commander');

// TODO remove block and dependency when node 14 fades out
Expand Down Expand Up @@ -37,54 +36,13 @@ global.getFixture = require('./lib/visualTestLoop').getFixture;
global.getAsset = require('./lib/visualTestLoop').getAsset;
global.getAssetName = require('./lib/visualTestLoop').getAssetName;
global.simulateEvent = require('./lib/event.simulate').simulateEvent;
global.imageDataToChalk = function(imageData) {
// actually this does not work on travis-ci, so commenting it out
return '';
var block = String.fromCharCode(9608);
var data = imageData.data;
var width = imageData.width;
var height = imageData.height;
var outputString = '';
var cp = 0;
for (var i = 0; i < height; i++) {
outputString += '\n';
for (var j = 0; j < width; j++) {
cp = (i * width + j) * 4;
outputString += chalk.rgb(data[cp], data[cp + 1], data[cp + 2])(block);
}
}
return outputString;
};

QUnit.config.testTimeout = 15000;
QUnit.config.noglobals = true;
QUnit.config.hidepassed = true;

global.isNode = () => true;

var jsdom = require('jsdom');

// make a jsdom version for tests that does not spam too much.
class CustomResourceLoader extends jsdom.ResourceLoader {
fetch(url, options) {
return super.fetch(url, options).catch(e => {
console.log('JSDOM CATCHED FETCHING', url);
throw new Error('JSDOM FETCH CATCHED');
});
}
}

var virtualWindow = new jsdom.JSDOM(
decodeURIComponent('%3C!DOCTYPE%20html%3E%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody%3E%3C%2Fbody%3E%3C%2Fhtml%3E'),
{
features: {
FetchExternalResources: ['img']
},
resources: new CustomResourceLoader(),
pretendToBeVisual: true
}).window;
fabric.setEnvForTests(virtualWindow);


// QUnit Logging

// global error handling
Expand All @@ -110,16 +68,3 @@ fabric.getWindow().addEventListener('error', (event) => {
event.preventDefault();
QUnit.onUncaughtException(event.error);
});

// testID
var objectInit = fabric.Object.prototype.initialize;
var canvasInit = fabric.StaticCanvas.prototype.initialize;
var testID = 0;
fabric.Object.prototype.initialize = function () {
objectInit.apply(this, arguments);
this.testID = `${this.type}#${++testID}`;
}
fabric.StaticCanvas.prototype.initialize = function () {
canvasInit.apply(this, arguments);
this.testID = `Canvas#${++testID}`;
}

0 comments on commit b5416c6

Please sign in to comment.