Commit be77ac8f authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '34100-job-log-retry' into 'master'

Adds checks for null

Closes #34100

See merge request gitlab-org/gitlab!18597
parents 92c346f6 eaec5360
......@@ -26,7 +26,7 @@ export default {
if (log.append) {
if (isNewJobLogActive()) {
state.trace = updateIncrementalTrace(log.lines, state.trace);
state.trace = log.lines ? updateIncrementalTrace(log.lines, state.trace) : state.trace;
} else {
state.trace += log.html;
}
......@@ -35,9 +35,9 @@ export default {
// When the job still does not have a trace
// the trace response will not have a defined
// html or size. We keep the old value otherwise these
// will be set to `undefined`
// will be set to `null`
if (isNewJobLogActive()) {
state.trace = logLinesParser(log.lines) || state.trace;
state.trace = log.lines ? logLinesParser(log.lines) : state.trace;
} else {
state.trace = log.html || state.trace;
}
......
......@@ -147,6 +147,7 @@ export const findOffsetAndRemove = (newLog = [], oldParsed = []) => {
const firstNew = newLog[0];
if (last && firstNew) {
if (last.offset === firstNew.offset || (last.line && last.line.offset === firstNew.offset)) {
cloneOldLog.splice(lastIndex);
} else if (last.lines && last.lines.length) {
......@@ -156,6 +157,7 @@ export const findOffsetAndRemove = (newLog = [], oldParsed = []) => {
last.lines.splice(lastNestedIndex);
}
}
}
return cloneOldLog;
};
......@@ -170,7 +172,7 @@ export const findOffsetAndRemove = (newLog = [], oldParsed = []) => {
* @param array oldLog
* @param array newLog
*/
export const updateIncrementalTrace = (newLog, oldParsed = []) => {
export const updateIncrementalTrace = (newLog = [], oldParsed = []) => {
const parsedLog = findOffsetAndRemove(newLog, oldParsed);
return logLinesParser(newLog, parsedLog);
......
......@@ -80,6 +80,81 @@ describe('Jobs Store Mutations', () => {
expect(stateCopy.traceSize).toEqual(511846);
expect(stateCopy.isTraceComplete).toEqual(true);
});
describe('with new job log', () => {
let stateWithNewLog;
beforeEach(() => {
gon.features = gon.features || {};
gon.features.jobLogJson = true;
stateWithNewLog = state();
});
afterEach(() => {
gon.features.jobLogJson = false;
});
describe('log.lines', () => {
describe('when append is true', () => {
it('sets the parsed log ', () => {
mutations[types.RECEIVE_TRACE_SUCCESS](stateWithNewLog, {
append: true,
size: 511846,
complete: true,
lines: [
{
offset: 1,
content: [{ text: 'Running with gitlab-runner 11.12.1 (5a147c92)' }],
},
],
});
expect(stateWithNewLog.trace).toEqual([
{
offset: 1,
content: [{ text: 'Running with gitlab-runner 11.12.1 (5a147c92)' }],
lineNumber: 0,
},
]);
});
});
describe('when it is defined', () => {
it('sets the parsed log ', () => {
mutations[types.RECEIVE_TRACE_SUCCESS](stateWithNewLog, {
append: false,
size: 511846,
complete: true,
lines: [
{ offset: 0, content: [{ text: 'Running with gitlab-runner 11.11.1 (5a147c92)' }] },
],
});
expect(stateWithNewLog.trace).toEqual([
{
offset: 0,
content: [{ text: 'Running with gitlab-runner 11.11.1 (5a147c92)' }],
lineNumber: 0,
},
]);
});
});
describe('when it is null', () => {
it('sets the default value', () => {
mutations[types.RECEIVE_TRACE_SUCCESS](stateWithNewLog, {
append: true,
html,
size: 511846,
complete: false,
lines: null,
});
expect(stateWithNewLog.trace).toEqual([]);
});
});
});
});
});
describe('STOP_POLLING_TRACE', () => {
......
......@@ -291,6 +291,13 @@ describe('Jobs Store Utils', () => {
});
});
});
describe('when no data is provided', () => {
it('returns an empty array', () => {
const result = findOffsetAndRemove();
expect(result).toEqual([]);
});
});
});
describe('getIncrementalLineNumber', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment