forked from trezor/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.plugin.js
77 lines (65 loc) · 2.6 KB
/
karma.plugin.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
65
66
67
68
69
70
71
72
73
74
75
76
77
// Karma custom plugin
const { CACHE } = require('./__txcache__');
const { createServer, transformCoinsJson } = require('./__wscache__');
const CustomReporter = (rootConfig, logger) => {
const log = logger.create('reporter.TrezorConnect');
return {
onRunStart: () => {
log.info('Running trezor-connect tests...');
log.info('FW:', process.env.TESTS_FIRMWARE);
log.info('Methods:', process.env.TESTS_INCLUDED_METHODS || 'All');
},
onSpecStart: (_browser, spec) => {
log.warn('onSpecStart', spec);
},
onSpecComplete: (_browser, spec) => {
log.info('onSpecComplete...', spec.fullName);
log.info('onSpecComplete success:', spec.success);
},
onRunComplete: () => {
log.warn('onRunComplete');
},
onExit: done => {
log.warn('onExit');
done();
},
};
};
CustomReporter.$inject = ['config', 'logger'];
// node.js "fs" package is not available in karma (browser) env.
// stringify CACHE object and inject it into a browser global.TestUtils context, same as jest.setup
const TxCachePreprocessor = logger => (content, file, done) => {
const log = logger.create('preprocessor.TxCachePreprocessor');
log.info('Processing cache...');
done(
`const CACHE = ${JSON.stringify(CACHE)};
const TESTS_USE_TX_CACHE = ${process.env.TESTS_USE_TX_CACHE};
TestUtils.TX_CACHE = (txs, force = false) => { if (TESTS_USE_TX_CACHE === false && !force) return []; return txs.map(hash => CACHE[hash]); };`,
);
};
TxCachePreprocessor.$inject = ['logger'];
const WsCachePreprocessor = logger => (content, file, done) => {
if (process.env.TESTS_USE_WS_CACHE !== 'true') {
done(content);
return;
}
const log = logger.create('preprocessor.WsCachePreprocessor');
const json = transformCoinsJson(JSON.parse(content));
log.info('Processing coins.json...');
done(JSON.stringify(json));
};
WsCachePreprocessor.$inject = ['logger'];
const WebSocketServer = (args, config, logger) => {
if (process.env.TESTS_USE_WS_CACHE !== 'true') return;
const log = logger.create('framework.WebSocketServer');
log.info('Starting websocket server...');
createServer().then(() => {
log.info('Server started...');
});
};
module.exports = {
'preprocessor:TxCachePreprocessor': ['factory', TxCachePreprocessor],
'preprocessor:WsCachePreprocessor': ['factory', WsCachePreprocessor],
'reporter:CustomReporter': ['type', CustomReporter],
'framework:WebsocketServer': ['factory', WebSocketServer],
};