Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test() When a test fails in node, dump the result in cli_output #8206

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Unit tests on Chrome
uses: actions/setup-node@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
Expand All @@ -36,7 +35,7 @@ jobs:
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
# supported Node.js release schedule: https://nodejs.org/en/about/releases/
node-version: [14.x, 16.x]
node-version: [14.x, 16.x]
suite: [unit, visual]
steps:
- uses: actions/checkout@v2
Expand All @@ -51,3 +50,9 @@ jobs:
run: npm run build -- -f
- name: Run ${{ matrix.suite }} tests
run: npm run test -- -c node -s ${{ matrix.suite }}
- name: Archive artifacts
if: always() && matrix.suite == 'visual' && matrix.node-version == '16.x'
uses: actions/upload-artifact@v3
with:
name: node-failing-visual-tests
path: cli_output/failed_visual_tests/node/*
6 changes: 3 additions & 3 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Dearest fabric maintainer 💗,
* This file contains the cli logic, which governs most of the available commands fabric has to offer.
*
*
* 📢 **IMPORTANT**
* CI uses these commands.
* In order for CI to correctly report the result of the command, the process must receive a correct exit code
Expand Down Expand Up @@ -166,7 +166,7 @@ function build(options = {}) {
process.exit(1);
}
}

}

function startWebsite() {
Expand Down Expand Up @@ -273,7 +273,7 @@ function exportToWebsite(options) {
}

/**
*
*
* @returns {Promise<boolean | undefined>} true if some tests failed
*/
async function runTestem({ suite, port, launch, dev, processOptions, context } = {}) {
Expand Down
13 changes: 9 additions & 4 deletions test/GoldensServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const busboy = require('busboy');
const wd = path.resolve(__dirname, '..');

/**
*
* @param {http.IncomingMessage} req
* @returns
*
* @param {http.IncomingMessage} req
* @returns
*/
function parseRequest(req) {
const bb = busboy({ headers: req.headers });
Expand Down Expand Up @@ -48,12 +48,17 @@ function startGoldensServer() {
const goldenPath = path.resolve(wd, 'test', 'visual', 'golden', filename);
res.end(JSON.stringify({ exists: fs.existsSync(goldenPath) }));
}
else if (req.method.toUpperCase() === 'POST') {
else if (req.method.toUpperCase() === 'POST' && req.url === '/goldens') {
const { files: [{ rawData, filename }] } = await parseRequest(req);
const goldenPath = path.resolve(wd, 'test', 'visual', 'golden', filename);
console.log(chalk.gray('[info]'), `creating golden ${path.relative(wd, goldenPath)}`);
fs.writeFileSync(goldenPath, rawData, { encoding: 'binary' });
res.end();
} else if (req.method.toUpperCase() === 'POST' && req.url === '/failed') {
const { files: [{ rawData, filename }] } = await parseRequest(req);
const filepath = path.resolve(wd, 'cli_output', 'failed_visual_tests', 'chrome', filename);
fs.writeFileSync(filepath, rawData, { encoding: 'binary' });
res.status(200).end();
}
}).listen();
const port = server.address().port;
Expand Down
40 changes: 38 additions & 2 deletions test/lib/visualTestLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,37 @@
img.src = filename;
}

function dumpFailedTest(testName, original, golden, difference, runner) {
if (original && difference && golden) {
var largeCanvas = fabric.util.createCanvasElement();
largeCanvas.width = original.width + golden.width + difference.width;
largeCanvas.height = Math.max(original.height, golden.height, difference.height);
var ctx = largeCanvas.getContext('2d');
ctx.drawImage(original, 0, 0);
ctx.putImageData(difference, original.width, 0);
ctx.drawImage(golden, original.width + difference.width, 0);
var path = `../../cli_output/failed_visual_tests/${runner}`;
const fileName = localPath(path, `${testName.replaceAll(' ', '_')}.png`);
console.log('dumping failed test', testName, runner);
if (fabric.isLikelyNode) {
var dataUrl = largeCanvas.toDataURL().split(',')[1];
if (!fs.existsSync(`${__dirname}/${path}`)) {
fs.mkdirSync(`${__dirname}/${path}`, { recursive: true });
}
fs.writeFileSync(fileName.replace('file://', ''), dataUrl, { encoding: 'base64' });
} else {
largeCanvas.toBlob(blob => {
const formData = new FormData();
formData.append('file', blob, fileName);
const request = new XMLHttpRequest();
request.open('POST', '/failed', true);
request.send(formData);
}, 'image/png');
}
}

}

exports.visualTestLoop = function(QUnit) {
var _pixelMatch;
var visualCallback;
Expand Down Expand Up @@ -175,8 +206,13 @@
testName + ' [' + golden + '] has too many different pixels ' + differentPixels + '(' + okDiff + ') representing ' + percDiff + '% (>' + (percentage * 100) + '%)'
);
if (!isOK) {
var stringa = imageDataToChalk(output);
console.log(stringa);
// var stringa = imageDataToChalk(output);
// console.log(stringa);
try {
dumpFailedTest(testName, renderedCanvas, canvas, output, QUnit.runner);
} catch(e) {
console.log(e)
}
}
if ((!isOK && QUnit.debugVisual) || QUnit.recreateVisualRefs) {
generateGolden(getGoldeName(golden), renderedCanvas);
Expand Down
20 changes: 1 addition & 19 deletions test/node_test_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,6 @@ 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;
Expand Down Expand Up @@ -135,4 +117,4 @@ QUnit.assert.strictEqual = function (actual, expected, message) {
expected: getLoggingRepresentation(expected),
message
});
};
};
1 change: 1 addition & 0 deletions test/testem.visual.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ module.exports = {
...config.qunit,
recreate: Number(process.env.QUNIT_RECREATE_VISUAL_REFS) || false,
debug: Number(process.env.QUNIT_DEBUG_VISUAL_TESTS) || false,
runner: process.env.RUNNER,
},
}
4 changes: 3 additions & 1 deletion test/tests.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ var vendorName = winNav.vendor;
var isOpera = typeof window.opr !== "undefined";
var isIEedge = winNav.userAgent.indexOf("Edg") > -1;
var isIOSChrome = winNav.userAgent.match("CriOS");
QUnit.runner = "{{qunit.runner}}";
if(
isIOSChrome ||
isIOSChrome ||
(isChromium !== null &&
//typeof isChromium !== "undefined" && // fails on headless chrome
vendorName === "Google Inc." &&
Expand All @@ -52,6 +53,7 @@ if(
QUnit.recreateVisualRefs = {{qunit.recreate}};
QUnit.debugVisual = {{qunit.debug}};
{{#qunit.filter}}QUnit.config.filter = {{qunit.filter}};{{/qunit.filter}}
QUnit.runner = 'chrome';
}
</script>
{{/visual}}
Expand Down