Skip to content

Commit 65b9553

Browse files
authored
fix: add fields for browser monitors via config !! (#1000)
* fix fields bugs * update
1 parent 36a050e commit 65b9553

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

__tests__/core/runner.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ describe('runner', () => {
787787
tags: ['g1', 'g2'],
788788
alert: { tls: { enabled: true } },
789789
playwrightOptions: { ignoreHTTPSErrors: true },
790+
fields: { area: 'website' },
790791
});
791792

792793
const j1 = new Journey({ name: 'j1', tags: ['foo*'] }, noop);
@@ -822,6 +823,7 @@ describe('runner', () => {
822823
throttling: { download: 100, latency: 20, upload: 50 },
823824
alert: { tls: { enabled: true } },
824825
retestOnFailure: true,
826+
fields: { area: 'website' },
825827
});
826828
expect(monitors[1].config).toMatchObject({
827829
locations: ['us_east'],

__tests__/fixtures/synthetics.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = env => {
4949
},
5050
},
5151
fields: {
52-
area: 'website',
52+
fromConfig: 'website',
5353
},
5454
},
5555
};

__tests__/options.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('options', () => {
9292
},
9393
},
9494
fields: {
95-
area: 'website',
95+
fromConfig: 'website',
9696
},
9797
});
9898

@@ -126,7 +126,6 @@ describe('options', () => {
126126
},
127127
fields: {
128128
env: 'dev',
129-
area: 'website',
130129
},
131130
});
132131
});

__tests__/push/monitor.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
createLightweightMonitors,
3232
diffMonitors,
3333
parseAlertConfig,
34+
parseFields,
3435
parseSchedule,
3536
} from '../../src/push/monitor';
3637
import { Server } from '../utils/server';
@@ -621,4 +622,59 @@ heartbeat.monitors:
621622
expect(config).toEqual({});
622623
});
623624
});
625+
626+
describe('parseFields', () => {
627+
it('extracts fields from config and removes them', () => {
628+
const config = {
629+
'fields.label1': 'value1',
630+
'fields.label2': 'value2',
631+
otherKey: 'otherValue',
632+
};
633+
634+
const result = parseFields(config as any);
635+
636+
expect(result).toEqual({ label1: 'value1', label2: 'value2' });
637+
expect(config).toEqual({ otherKey: 'otherValue' }); // Ensure fields were deleted
638+
});
639+
640+
it('merges global fields into parsed fields', () => {
641+
const config = {
642+
'fields.label1': 'value1',
643+
};
644+
const gFields = {
645+
label2: 'globalValue',
646+
label3: 'anotherGlobalValue',
647+
};
648+
649+
const result = parseFields(config as any, gFields);
650+
651+
expect(result).toEqual({
652+
label1: 'value1',
653+
label2: 'globalValue',
654+
label3: 'anotherGlobalValue',
655+
});
656+
});
657+
658+
it('returns only global fields if no config fields exist', () => {
659+
const config = {
660+
otherKey: 'otherValue',
661+
};
662+
const gFields = {
663+
label1: 'globalValue',
664+
};
665+
666+
const result = parseFields(config as any, gFields);
667+
668+
expect(result).toEqual({ label1: 'globalValue' });
669+
});
670+
671+
it('returns undefined if no fields exist', () => {
672+
const config = {
673+
otherKey: 'otherValue',
674+
};
675+
const result = parseFields(config as any);
676+
677+
expect(result).toBeUndefined();
678+
});
679+
});
624680
});

src/core/runner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ export default class Runner implements RunnerInfo {
442442
alert: options.alert,
443443
retestOnFailure: options.retestOnFailure,
444444
enabled: options.enabled,
445+
fields: options.fields,
445446
});
446447

447448
const monitors: Monitor[] = [];

0 commit comments

Comments
 (0)