fix(client): pass logs incrementally from test worker
This commit is contained in:
committed by
mrugesh mohapatra
parent
38c5039e00
commit
e8f5b54d63
@ -2,14 +2,38 @@ import chai from 'chai';
|
|||||||
import '@babel/polyfill';
|
import '@babel/polyfill';
|
||||||
import __toString from 'lodash/toString';
|
import __toString from 'lodash/toString';
|
||||||
|
|
||||||
const oldLog = self.console.log.bind(self.console);
|
const __utils = (() => {
|
||||||
self.console.log = function proxyConsole(...args) {
|
const MAX_LOGS_SIZE = 64 * 1024;
|
||||||
self.postMessage({
|
|
||||||
type: 'LOG',
|
let logs = [];
|
||||||
data: args.map(arg => JSON.stringify(arg)).join(' ')
|
function flushLogs() {
|
||||||
});
|
if (logs.length) {
|
||||||
return oldLog(...args);
|
self.postMessage({
|
||||||
};
|
type: 'LOG',
|
||||||
|
data: logs.join('\n')
|
||||||
|
});
|
||||||
|
logs = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const oldLog = self.console.log.bind(self.console);
|
||||||
|
self.console.log = function proxyConsole(...args) {
|
||||||
|
logs.push(args.map(arg => JSON.stringify(arg)).join(' '));
|
||||||
|
if (logs.join('\n').length > MAX_LOGS_SIZE) {
|
||||||
|
flushLogs();
|
||||||
|
}
|
||||||
|
return oldLog(...args);
|
||||||
|
};
|
||||||
|
|
||||||
|
function postResult(data) {
|
||||||
|
flushLogs();
|
||||||
|
self.postMessage(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
postResult
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
self.onmessage = async e => {
|
self.onmessage = async e => {
|
||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
@ -38,11 +62,11 @@ self.onmessage = async e => {
|
|||||||
if (typeof testResult === 'function') {
|
if (typeof testResult === 'function') {
|
||||||
await testResult(fileName => __toString(e.data.sources[fileName]));
|
await testResult(fileName => __toString(e.data.sources[fileName]));
|
||||||
}
|
}
|
||||||
self.postMessage({
|
__utils.postResult({
|
||||||
pass: true
|
pass: true
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
self.postMessage({
|
__utils.postResult({
|
||||||
err: {
|
err: {
|
||||||
message: err.message,
|
message: err.message,
|
||||||
stack: err.stack
|
stack: err.stack
|
||||||
|
@ -215,6 +215,8 @@ export const challengeDataSelector = state => {
|
|||||||
return challengeData;
|
return challengeData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MAX_LOGS_SIZE = 64 * 1024;
|
||||||
|
|
||||||
export const reducer = handleActions(
|
export const reducer = handleActions(
|
||||||
{
|
{
|
||||||
[types.fetchIdToNameMapComplete]: (state, { payload }) => ({
|
[types.fetchIdToNameMapComplete]: (state, { payload }) => ({
|
||||||
@ -259,19 +261,17 @@ export const reducer = handleActions(
|
|||||||
}),
|
}),
|
||||||
[types.initLogs]: state => ({
|
[types.initLogs]: state => ({
|
||||||
...state,
|
...state,
|
||||||
logsOut: []
|
logsOut: ''
|
||||||
}),
|
}),
|
||||||
[types.updateLogs]: (state, { payload }) => ({
|
[types.updateLogs]: (state, { payload }) => ({
|
||||||
...state,
|
...state,
|
||||||
logsOut: [...state.logsOut, payload]
|
logsOut: (state.logsOut + '\n' + payload).slice(-MAX_LOGS_SIZE)
|
||||||
}),
|
}),
|
||||||
[types.logsToConsole]: (state, { payload }) => ({
|
[types.logsToConsole]: (state, { payload }) => ({
|
||||||
...state,
|
...state,
|
||||||
consoleOut:
|
consoleOut:
|
||||||
state.consoleOut +
|
state.consoleOut +
|
||||||
(state.logsOut.length
|
(state.logsOut ? '\n' + payload + '\n' + state.logsOut : '')
|
||||||
? '\n' + payload + '\n' + state.logsOut.join('\n')
|
|
||||||
: '')
|
|
||||||
}),
|
}),
|
||||||
[types.updateChallengeMeta]: (state, { payload }) => ({
|
[types.updateChallengeMeta]: (state, { payload }) => ({
|
||||||
...state,
|
...state,
|
||||||
|
Reference in New Issue
Block a user