Skip to content

Commit 5456cd9

Browse files
committed
Merge remote-tracking branch 'upstream/main' into synthetics-cli-proxy
2 parents 24ba9fa + 9f7f6fc commit 5456cd9

File tree

13 files changed

+1387
-1183
lines changed

13 files changed

+1387
-1183
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18.20.3
1+
20.19.4

__tests__/core/runner.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ describe('runner', () => {
767767
locations: ['united_kingdom'],
768768
schedule: 3,
769769
throttling: { download: 5, latency: 20, upload: 3 },
770+
spaces: [],
770771
});
771772
expect(monitors[1].config).toMatchObject({
772773
throttling: { latency: 1000 },
@@ -824,6 +825,7 @@ describe('runner', () => {
824825
alert: { tls: { enabled: true } },
825826
retestOnFailure: true,
826827
fields: { area: 'website' },
828+
spaces: [],
827829
});
828830
expect(monitors[1].config).toMatchObject({
829831
locations: ['us_east'],

__tests__/options.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('options', () => {
6666
ignoreHTTPSErrors: undefined,
6767
isMobile: true,
6868
userAgent:
69-
'Mozilla/5.0 (Linux; Android 8.0.0; SM-G965U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.16 Mobile Safari/537.36',
69+
'Mozilla/5.0 (Linux; Android 8.0.0; SM-G965U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.7204.23 Mobile Safari/537.36',
7070
viewport: {
7171
height: 658,
7272
width: 320,

__tests__/push/monitor.test.ts

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
parseAlertConfig,
3434
parseFields,
3535
parseSchedule,
36+
parseSpaces,
3637
} from '../../src/push/monitor';
3738
import { Server } from '../utils/server';
3839
import { createTestMonitor } from '../utils/test-config';
@@ -85,6 +86,7 @@ describe('Monitors', () => {
8586
locations: ['europe-west2-a', 'australia-southeast1-a'],
8687
privateLocations: ['germany'],
8788
fields: { area: 'website' },
89+
spaces: ['test'],
8890
});
8991
});
9092

@@ -105,8 +107,12 @@ describe('Monitors', () => {
105107
match: 'test',
106108
},
107109
fields: { area: 'website' },
110+
spaces: ['test'],
111+
});
112+
monitor.update({
113+
locations: ['brazil'],
114+
fields: { env: 'dev' },
108115
});
109-
monitor.update({ locations: ['brazil'], fields: { env: 'dev' } });
110116
const { schemas: schemas1 } = await buildMonitorSchema([monitor], true);
111117
expect(schemas1[0].hash).not.toEqual(schemas[0].hash);
112118
expect(schemas1[0].fields).toEqual({
@@ -497,6 +503,57 @@ heartbeat.monitors:
497503
`);
498504

499505
const [mon] = await createLightweightMonitors(PROJECT_DIR, {
506+
space: 'default',
507+
auth: 'foo',
508+
params: { foo: 'bar' },
509+
kibanaVersion: '8.8.0',
510+
locations: ['australia_east'],
511+
tags: ['gtag1', 'gtag2'],
512+
privateLocations: ['gbaz'],
513+
schedule: 10,
514+
retestOnFailure: false,
515+
spaces: ['default'],
516+
});
517+
518+
expect(mon.config).toEqual({
519+
id: 'test-icmp',
520+
name: 'test-icmp',
521+
locations: ['australia_east'],
522+
privateLocations: ['baz'],
523+
type: 'icmp',
524+
params: { foo: 'bar' },
525+
schedule: 5,
526+
tags: ['ltag1', 'ltag2'],
527+
retestOnFailure: false,
528+
fields: {
529+
baz: 'qux',
530+
foo: 'bar',
531+
},
532+
spaces: ['default'],
533+
});
534+
});
535+
536+
it('supports spaces in config', async () => {
537+
await writeHBFile(`
538+
heartbeat.monitors:
539+
- type: icmp
540+
schedule: @every 5m
541+
id: "test-icmp"
542+
name: "test-icmp"
543+
privateLocations:
544+
- baz
545+
tags:
546+
- ltag1
547+
- ltag2
548+
fields.foo: bar
549+
fields.baz: qux
550+
spaces:
551+
- space1
552+
- space2
553+
`);
554+
555+
const [mon] = await createLightweightMonitors(PROJECT_DIR, {
556+
space: 'default',
500557
auth: 'foo',
501558
params: { foo: 'bar' },
502559
kibanaVersion: '8.8.0',
@@ -521,6 +578,7 @@ heartbeat.monitors:
521578
baz: 'qux',
522579
foo: 'bar',
523580
},
581+
spaces: ['default', 'space1', 'space2'],
524582
});
525583
});
526584
});
@@ -677,4 +735,58 @@ heartbeat.monitors:
677735
expect(result).toBeUndefined();
678736
});
679737
});
738+
739+
describe('parseSpaces', () => {
740+
it('returns empty object if no spaces are defined', () => {
741+
expect(parseSpaces({}, {} as any)).toEqual({});
742+
expect(parseSpaces({ spaces: undefined }, {} as any)).toEqual({});
743+
expect(parseSpaces({}, { spaces: undefined } as any)).toEqual({});
744+
});
745+
746+
it('merges config and options spaces, including global space', () => {
747+
const config = { spaces: ['space1'] };
748+
const options = { spaces: ['space2'], space: 'global' };
749+
expect(parseSpaces(config, options as any)).toEqual({
750+
spaces: ['global', 'space1', 'space2'],
751+
});
752+
});
753+
754+
it('handles only config spaces', () => {
755+
expect(parseSpaces({ spaces: ['foo'] }, {} as any)).toEqual({
756+
spaces: ['foo'],
757+
});
758+
});
759+
760+
it('handles only options spaces', () => {
761+
expect(parseSpaces({}, { spaces: ['bar'] } as any)).toEqual({
762+
spaces: ['bar'],
763+
});
764+
});
765+
766+
it('handles global space only', () => {
767+
expect(parseSpaces({}, { space: 'default' } as any)).toEqual({});
768+
});
769+
770+
it('deduplicates spaces', () => {
771+
const config = { spaces: ['space1', 'space2'] };
772+
const options = { spaces: ['space2', 'space3'], space: 'space1' };
773+
expect(parseSpaces(config, options as any)).toEqual({
774+
spaces: ['space1', 'space2', 'space3'],
775+
});
776+
});
777+
778+
it('returns wildcard if present', () => {
779+
expect(
780+
parseSpaces({ spaces: ['*'] }, {
781+
space: 'default',
782+
spaces: ['foo'],
783+
} as any)
784+
).toEqual({
785+
spaces: ['*'],
786+
});
787+
expect(parseSpaces({}, { spaces: ['*'] } as any)).toEqual({
788+
spaces: ['*'],
789+
});
790+
});
791+
});
680792
});

__tests__/utils/jest-global-setup.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ import { spawn } from 'child_process';
2727
import { wsEndpoint } from './test-config';
2828

2929
module.exports = async () => {
30+
// Unset the SYNTHETICS_API_KEY to ensure it doesn't affect tests
31+
if (process.env.SYNTHETICS_API_KEY) {
32+
console.log('Unsetting SYNTHETICS_API_KEY environment variable for tests');
33+
delete process.env.SYNTHETICS_API_KEY;
34+
}
35+
3036
if (wsEndpoint) {
3137
return new Promise((resolve, reject) => {
3238
console.log(`\nRunning BrowserService ${wsEndpoint}`);

__tests__/utils/test-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function createTestMonitor(filename: string, type = 'browser') {
4343
locations: ['united_kingdom', 'australia_east'],
4444
privateLocations: ['germany'],
4545
fields: { area: 'website' },
46+
spaces: ['test'],
4647
});
4748
monitor.setSource({
4849
file: join(FIXTURES_DIR, filename),

0 commit comments

Comments
 (0)