-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathnode_test_setup.js
64 lines (51 loc) · 2.14 KB
/
node_test_setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require('source-map-support/register');
require('./lib/assert');
// set the fabric framework as a global for tests
var chalk = require('chalk');
var commander = require('commander');
commander.program
.option('-d, --debug', 'debug visual tests by overriding refs (golden images) in case of visual changes', false)
.option('-r, --recreate', 'recreate visual refs (golden images)', false)
.action(options => {
QUnit.debug = QUnit.debugVisual = options.debug;
QUnit.recreateVisualRefs = options.recreate;
}).parse(process.argv);
// for now accept an env variable because qunit doesn't allow passing unknown options
QUnit.debugVisual = Number(process.env.QUNIT_DEBUG_VISUAL_TESTS);
QUnit.recreateVisualRefs = Number(process.env.QUNIT_RECREATE_VISUAL_REFS);
QUnit.config.filter = process.env.QUNIT_FILTER;
global.fabric = require('../dist/index.node.cjs');
global.pixelmatch = require('pixelmatch');
global.fs = require('fs');
global.visualCallback = {
addArguments: function() {},
};
global.visualTestLoop = require('./lib/visualTestLoop').visualTestLoop;
global.compareGoldensTest = require('./lib/visualTestLoop').compareGoldensTest;
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;
QUnit.config.testTimeout = 15000;
QUnit.config.noglobals = true;
QUnit.config.hidepassed = true;
global.isNode = () => true;
// QUnit Logging
// global error handling
process.on('uncaughtExceptionMonitor', (err, origin) => {
QUnit.onUncaughtException(err);
});
process.on('unhandledRejection', (reason, promise) => {
QUnit.onUncaughtException(reason);
});
// JSDOM catches errors and throws them to the window
fabric.getFabricWindow().addEventListener('unhandledrejection', (event) => {
// prevent logging to console
event.preventDefault();
QUnit.onUncaughtException(event.reason);
});
fabric.getFabricWindow().addEventListener('error', (event) => {
// prevent logging to console
event.preventDefault();
QUnit.onUncaughtException(event.error);
});