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 11 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
8 changes: 8 additions & 0 deletions .github/workflows/visual-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ jobs:
- run: npm ci
- run: npm run build -- -f -x gestures,accessors
- run: npm run test -- -s visual -p 8080 -c node
env:
RUNNER: node
- name: Archive artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: node-failing-visual-tests
path: cli_output/failed_visual_tests/node/*
6 changes: 6 additions & 0 deletions .github/workflows/visual-test-chrome.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ jobs:
uses: GabrielBB/xvfb-action@v1
with:
run: npm run test -- -s visual -p 8080 -c chrome
- name: Archive artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: chrome-failing-visual-tests
path: cli_output/failed_visual_tests/chrome/*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work yet

6 changes: 6 additions & 0 deletions .github/workflows/visual-test-firefox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ jobs:
uses: GabrielBB/xvfb-action@v1
with:
run: npm run test -- -s visual -p 8080 -c firefox
- name: Archive artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: firefox-failing-visual-tests
path: cli_output/failed_visual_tests/firefox/*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work yet

3 changes: 2 additions & 1 deletion scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ async function test(suite, tests, options = {}) {
QUNIT_DEBUG_VISUAL_TESTS: Number(options.debug),
QUNIT_RECREATE_VISUAL_REFS: Number(options.recreate),
QUNIT_FILTER: options.filter,
REPORT_FILE: options.out
REPORT_FILE: options.out,
RUNNER: options.context[0],
},
shell: true,
stdio: 'inherit',
Expand Down
14 changes: 10 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,18 @@ 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);
console.log('here', filename);
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
41 changes: 39 additions & 2 deletions test/lib/visualTestLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,38 @@
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 {
console.log('running here', fileName)
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 +207,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
3 changes: 1 addition & 2 deletions test/node_test_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ 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;
Expand Down Expand Up @@ -126,4 +125,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 @@ -36,8 +36,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 @@ -48,6 +49,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