Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils_spec.js « store « jobs « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7b484ccfa073d82913207112fa2612b4a3f6b0dd (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import { logLinesParser, updateIncrementalTrace } from '~/jobs/store/utils';

describe('Jobs Store Utils', () => {
  describe('logLinesParser', () => {
    const mockData = [
      {
        offset: 1001,
        content: [{ text: ' on docker-auto-scale-com 8a6210b8' }],
      },
      {
        offset: 1002,
        content: [
          {
            text:
              'Using Docker executor with image dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.6.3-golang-1.11-git-2.22-chrome-73.0-node-12.x-yarn-1.16-postgresql-9.6-graphicsmagick-1.3.33',
          },
        ],
        sections: ['prepare-executor'],
        section_header: true,
      },
      {
        offset: 1003,
        content: [{ text: 'Starting service postgres:9.6.14 ...' }],
        sections: ['prepare-executor'],
      },
      {
        offset: 1004,
        content: [{ text: 'Pulling docker image postgres:9.6.14 ...', style: 'term-fg-l-green' }],
        sections: ['prepare-executor'],
      },
      {
        offset: 1005,
        content: [],
        sections: ['prepare-executor'],
        section_duration: '10:00',
      },
    ];

    let result;

    beforeEach(() => {
      result = logLinesParser(mockData);
    });

    describe('regular line', () => {
      it('adds a lineNumber property with correct index', () => {
        expect(result[0].lineNumber).toEqual(0);
        expect(result[1].line.lineNumber).toEqual(1);
      });
    });

    describe('collpasible section', () => {
      it('adds a `isClosed` property', () => {
        expect(result[1].isClosed).toEqual(true);
      });

      it('adds a `isHeader` property', () => {
        expect(result[1].isHeader).toEqual(true);
      });

      it('creates a lines array property with the content of the collpasible section', () => {
        expect(result[1].lines.length).toEqual(2);
        expect(result[1].lines[0].content).toEqual(mockData[2].content);
        expect(result[1].lines[1].content).toEqual(mockData[3].content);
      });
    });

    describe('section duration', () => {
      it('adds the section information to the header section', () => {
        expect(result[1].section_duration).toEqual(mockData[4].section_duration);
      });

      it('does not add section duration as a line', () => {
        expect(result[1].lines.includes(mockData[4])).toEqual(false);
      });
    });
  });

  describe('updateIncrementalTrace', () => {
    const originalTrace = [
      {
        offset: 1,
        content: [
          {
            text: 'Downloading',
          },
        ],
      },
    ];

    describe('without repeated section', () => {
      it('concats and parses both arrays', () => {
        const oldLog = logLinesParser(originalTrace);
        const newLog = [
          {
            offset: 2,
            content: [
              {
                text: 'log line',
              },
            ],
          },
        ];
        const result = updateIncrementalTrace(originalTrace, oldLog, newLog);

        expect(result).toEqual([
          {
            offset: 1,
            content: [
              {
                text: 'Downloading',
              },
            ],
            lineNumber: 0,
          },
          {
            offset: 2,
            content: [
              {
                text: 'log line',
              },
            ],
            lineNumber: 1,
          },
        ]);
      });
    });

    describe('with regular line repeated offset', () => {
      it('updates the last line and formats with the incremental part', () => {
        const oldLog = logLinesParser(originalTrace);
        const newLog = [
          {
            offset: 1,
            content: [
              {
                text: 'log line',
              },
            ],
          },
        ];
        const result = updateIncrementalTrace(originalTrace, oldLog, newLog);

        expect(result).toEqual([
          {
            offset: 1,
            content: [
              {
                text: 'log line',
              },
            ],
            lineNumber: 0,
          },
        ]);
      });
    });

    describe('with header line repeated', () => {
      it('updates the header line and formats with the incremental part', () => {
        const headerTrace = [
          {
            offset: 1,
            section_header: true,
            content: [
              {
                text: 'log line',
              },
            ],
            sections: ['section'],
          },
        ];
        const oldLog = logLinesParser(headerTrace);
        const newLog = [
          {
            offset: 1,
            section_header: true,
            content: [
              {
                text: 'updated log line',
              },
            ],
            sections: ['section'],
          },
        ];
        const result = updateIncrementalTrace(headerTrace, oldLog, newLog);

        expect(result).toEqual([
          {
            isClosed: true,
            isHeader: true,
            line: {
              offset: 1,
              section_header: true,
              content: [
                {
                  text: 'updated log line',
                },
              ],
              sections: ['section'],
              lineNumber: 0,
            },
            lines: [],
          },
        ]);
      });
    });

    describe('with collapsible line repeated', () => {
      it('updates the collapsible line and formats with the incremental part', () => {
        const collapsibleTrace = [
          {
            offset: 1,
            section_header: true,
            content: [
              {
                text: 'log line',
              },
            ],
            sections: ['section'],
          },
          {
            offset: 2,
            content: [
              {
                text: 'log line',
              },
            ],
            sections: ['section'],
          },
        ];
        const oldLog = logLinesParser(collapsibleTrace);
        const newLog = [
          {
            offset: 2,
            content: [
              {
                text: 'updated log line',
              },
            ],
            sections: ['section'],
          },
        ];
        const result = updateIncrementalTrace(collapsibleTrace, oldLog, newLog);

        expect(result).toEqual([
          {
            isClosed: true,
            isHeader: true,
            line: {
              offset: 1,
              section_header: true,
              content: [
                {
                  text: 'log line',
                },
              ],
              sections: ['section'],
              lineNumber: 0,
            },
            lines: [
              {
                offset: 2,
                content: [
                  {
                    text: 'updated log line',
                  },
                ],
                sections: ['section'],
                lineNumber: 1,
              },
            ],
          },
        ]);
      });
    });
  });
});