Skip to content

Commit

Permalink
chore: fix formatting and run check
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam committed Dec 19, 2024
1 parent 8a73648 commit 02637ad
Show file tree
Hide file tree
Showing 31 changed files with 197 additions and 151 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
node-version-file: .nvmrc
- run: npm ci
- run: npm run-script lint
- run: npm run-script format

build:
runs-on: ubuntu-latest
Expand Down
4 changes: 1 addition & 3 deletions __tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,7 @@ describe('CLI', () => {

describe('TOTP token', () => {
async function runTotp(args) {
const cli = new CLIMock()
.args(['totp', ...args])
.run({});
const cli = new CLIMock().args(['totp', ...args]).run({});
await cli.exitCode;
return cli.stderr();
}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/core/gatherer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe('Gatherer', () => {
wsEndpoint,
playwrightOptions: { navigationTimeout: 1, actionTimeout: 2 },
});
server.route('/hang.html', () => { });
server.route('/hang.html', () => {});
let error: any = null;
await driver.page
.goto(server.PREFIX + '/hang.html')
Expand All @@ -287,7 +287,7 @@ describe('Gatherer', () => {
wsEndpoint,
playwrightOptions: { navigationTimeout: 3 },
});
server.route('/hang.html', () => { });
server.route('/hang.html', () => {});
let error: any = null;
await driver.page
.goto(server.PREFIX + '/hang.html', { timeout: 1 })
Expand Down
6 changes: 3 additions & 3 deletions __tests__/core/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { runner } from '../../src/core/globals';

beforeEach(async () => await runner._reset());

const noop = () => { };
const noop = () => {};
const name = 'journey';

it('add global hooks to runner', () => {
Expand Down Expand Up @@ -77,8 +77,8 @@ it('add hooks to journeys', () => {
expect(runner.currentJourney).toEqual(j);
expect(runner.journeys.length).toBe(1);
expect(runner.currentJourney?.steps.length).toBe(0);
expect(runner.currentJourney?._getHook("before")).toEqual([noop]);
expect(runner.currentJourney?._getHook("after")).toEqual([noop]);
expect(runner.currentJourney?._getHook('before')).toEqual([noop]);
expect(runner.currentJourney?._getHook('after')).toEqual([noop]);
});

it('add hooks - error on before/after outside journey context', () => {
Expand Down
5 changes: 1 addition & 4 deletions __tests__/core/mfa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ import { totp } from '../../src/core/mfa';

describe('MFA', () => {
it('generate TOTP', () => {
const token = totp("FLIIOLP3IR3W");
const token = totp('FLIIOLP3IR3W');
expect(token.length).toBe(6);
});
});



16 changes: 10 additions & 6 deletions __tests__/core/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('runner', () => {
try {
fs.accessSync(dest);
fs.unlinkSync(dest);
} catch (_) { }
} catch (_) {}
});
afterAll(async () => await server.close());

Expand Down Expand Up @@ -167,7 +167,9 @@ describe('runner', () => {

it('run journey - failed on beforeAll', async () => {
const error = new Error('Broken beforeAll hook');
runner._addHook('beforeAll', () => { throw error });
runner._addHook('beforeAll', () => {
throw error;
});
runner._addJourney(new Journey({ name: 'j1' }, () => step('step1', noop)));
runner._addJourney(new Journey({ name: 'j2' }, () => step('step1', noop)));
const result = await runner._run(defaultRunOptions);
Expand All @@ -188,7 +190,9 @@ describe('runner', () => {
expect(info.currentJourney?.error).toBe(error);
expect(info.currentJourney?.duration).toBeGreaterThan(0);
});
step('step1', () => { throw error });
step('step1', () => {
throw error;
});
});
const result = await runner._runJourney(j1, defaultRunOptions);
await Gatherer.stop();
Expand All @@ -206,7 +210,7 @@ describe('runner', () => {
after(({ info }) => {
expect(info.currentJourney?.status).toBe('succeeded');
expect(info.currentJourney?.duration).toBeGreaterThan(0);
})
});
});
const result = await runner._runJourney(j1, defaultRunOptions);
await Gatherer.stop();
Expand All @@ -223,7 +227,7 @@ describe('runner', () => {
});
const runOptions = { ...defaultRunOptions, metrics: true };
const result = await runner._runJourney(j1, runOptions);
await Gatherer.stop()
await Gatherer.stop();
expect(result.stepsresults?.[0].pagemetrics).toBeDefined();
expect(result.steps).toMatchObject([
{
Expand Down Expand Up @@ -659,7 +663,7 @@ describe('runner', () => {
});
runner._addJourney(j1);
const runOptions = { ...defaultRunOptions, trace: true };
const results = await runner._run(runOptions)
const results = await runner._run(runOptions);
const steps = results[j1.name].stepsresults;
expect(steps?.length).toBe(2);
expect(steps?.[0].metrics).toBeUndefined();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/dsl/journey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import { Journey, Step } from '../../src/dsl';

const noop = () => { };
const noop = () => {};
describe('Journey', () => {
it('add journey details', () => {
const name = 'j1';
Expand Down
6 changes: 3 additions & 3 deletions __tests__/e2e/synthetics.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
export default () => {
return {
playwrightOptions: {
ignoreHTTPSErrors: true
}
}
ignoreHTTPSErrors: true,
},
};
};
121 changes: 77 additions & 44 deletions __tests__/e2e/synthetics.journey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,31 @@ async function logIn(page) {
}

async function goToSyntheticsIntegrationPage(page) {
console.info('Navigating to Elastic Synthetics Integration page')
await page.goto('https://localhost:5601/app/integrations/detail/synthetics/overview');
await page.waitForSelector('[data-test-subj="loginUsername"]', { timeout: 30000 });
const isUnauthenticated = await page.isVisible('[data-test-subj="loginUsername"]');
console.info('Navigating to Elastic Synthetics Integration page');
await page.goto(
'https://localhost:5601/app/integrations/detail/synthetics/overview'
);
await page.waitForSelector('[data-test-subj="loginUsername"]', {
timeout: 30000,
});
const isUnauthenticated = await page.isVisible(
'[data-test-subj="loginUsername"]'
);
if (isUnauthenticated) {
await logIn(page);
}
await page.click('[data-test-subj="addIntegrationPolicyButton"]', { timeout: 10 * 1500 });
await page.click('[data-test-subj="addIntegrationPolicyButton"]', {
timeout: 10 * 1500,
});
/* We need to ensure that Elastic Synthetics integration page is fully loaded, including the UI logic.
* Our UI logic clears out the name input when the page is first loaded. If we don't wait, we run the risk
* Our UI logic clears out the name input when the page is first loaded. If we don't wait, we run the risk
* of playwright input being overwritten by Kibana logic clearing out the field. Playwright doesn't have
* a mechanism to wait for the value of input to be empty, so for now, we are using a simple timeout */
await page.waitForTimeout(10 * 1000);
}

async function goToUptime(page) {
console.info('Navigating to Uptime overview page')
console.info('Navigating to Uptime overview page');
await page.goto('https://localhost:5601/app/uptime');
}

Expand All @@ -63,40 +71,47 @@ async function selectAgentPolicy({ page }) {
await page.click('[data-test-subj="agentPolicySelect"]');
await page.click('text="Elastic-Agent (elastic-package)"');
} else {
await page.selectOption('[data-test-subj="agentPolicySelect"]', { label: 'Elastic-Agent (elastic-package)' });
await page.selectOption('[data-test-subj="agentPolicySelect"]', {
label: 'Elastic-Agent (elastic-package)',
});
}
await page.waitForSelector('text="Elastic-Agent (elastic-package)"');
}
await page.click('[data-test-subj="packagePolicyNameInput"]');
}

async function createIntegrationPolicyName({ page, policyName }) {
await page.waitForSelector('[data-test-subj="packagePolicyNameInput"]', { timeout: 10000 });
await page.waitForSelector('[data-test-subj="packagePolicyNameInput"]', {
timeout: 10000,
});
await page.fill('[data-test-subj="packagePolicyNameInput"]', policyName);
}

async function confirmAndSavePolicy(page) {
await page.click('[data-test-subj="createPackagePolicySaveButton"]');
await Promise.all([page.waitForNavigation(), page.click('[data-test-subj="confirmModalConfirmButton"]')]);
await Promise.all([
page.waitForNavigation(),
page.click('[data-test-subj="confirmModalConfirmButton"]'),
]);
}

async function checkForSyntheticsData({ page, journeyName }) {
const checkForTable = async () => {
const checkForTable = async () => {
try {
return await page.waitForSelector('.euiTableRow', { timeout: 5000 });
} catch (e) {
console.error(e);
}
}
};
let isTableVisible = await checkForTable();
while (!isTableVisible) {
console.info('Reloading Uptime...')
console.info('Reloading Uptime...');
await page.reload();
isTableVisible = await checkForTable();
}
await page.fill('[data-test-subj="queryInput"]', journeyName);
await page.click(`a:has-text("${journeyName}")`, { timeout: 300 * 1000 });
console.info(`Data for ${journeyName} indexed successfully`)
console.info(`Data for ${journeyName} indexed successfully`);
}

journey(`${stackVersion} e2e test synthetics - http`, async ({ page }) => {
Expand All @@ -108,11 +123,14 @@ journey(`${stackVersion} e2e test synthetics - http`, async ({ page }) => {

step('create an http monitor', async () => {
await createIntegrationPolicyName({ page, policyName: journeyName });
await page.fill('[data-test-subj="syntheticsUrlField"]', 'https://elastic.co');
await page.fill(
'[data-test-subj="syntheticsUrlField"]',
'https://elastic.co'
);
await selectAgentPolicy({ page });
await page.click('[data-test-subj="syntheticsUrlField"]');
await confirmAndSavePolicy(page);
console.info(`Monitor for ${journeyName} created successfully`)
console.info(`Monitor for ${journeyName} created successfully`);
});

step('go to uptime', async () => {
Expand All @@ -133,11 +151,17 @@ journey(`${stackVersion} e2e test synthetics - tcp`, async ({ page }) => {

step('create an tcp monitor', async () => {
await createIntegrationPolicyName({ page, policyName: journeyName });
await page.selectOption('[data-test-subj="syntheticsMonitorTypeField"]', 'tcp');
await page.fill('[data-test-subj="syntheticsTCPHostField"]', 'smtp.gmail.com:587');
await page.selectOption(
'[data-test-subj="syntheticsMonitorTypeField"]',
'tcp'
);
await page.fill(
'[data-test-subj="syntheticsTCPHostField"]',
'smtp.gmail.com:587'
);
await selectAgentPolicy({ page });
await confirmAndSavePolicy(page);
console.info(`Monitor for ${journeyName} created successfully`)
console.info(`Monitor for ${journeyName} created successfully`);
});

step('go to uptime', async () => {
Expand Down Expand Up @@ -173,32 +197,41 @@ journey(`${stackVersion} e2e test synthetics - tcp`, async ({ page }) => {
// });

if (semver.satisfies(stackVersion, '>=8.0.1')) {
journey(`${stackVersion} e2e test synthetics - browser - inline`, async ({ page }) => {
const journeyName = 'Sample browser inline integration policy';

step('Go to synthetics integration page', async () => {
await goToSyntheticsIntegrationPage(page);
});

step('create an browser monitor', async () => {
await createIntegrationPolicyName({ page, policyName: journeyName });
await page.selectOption('[data-test-subj="syntheticsMonitorTypeField"]', 'browser');
await page.click('[data-test-subj="syntheticsSourceTab__inline"]');
await page.fill('[data-test-subj=codeEditorContainer] textarea', `
journey(
`${stackVersion} e2e test synthetics - browser - inline`,
async ({ page }) => {
const journeyName = 'Sample browser inline integration policy';

step('Go to synthetics integration page', async () => {
await goToSyntheticsIntegrationPage(page);
});

step('create an browser monitor', async () => {
await createIntegrationPolicyName({ page, policyName: journeyName });
await page.selectOption(
'[data-test-subj="syntheticsMonitorTypeField"]',
'browser'
);
await page.click('[data-test-subj="syntheticsSourceTab__inline"]');
await page.fill(
'[data-test-subj=codeEditorContainer] textarea',
`
step('load homepage', async () => {
await page.goto('https://www.elastic.co');
});
`);
await selectAgentPolicy({ page });
await confirmAndSavePolicy(page);
});

step('go to uptime', async () => {
await goToUptime(page);
});

step('wait for synthetics data', async () => {
await checkForSyntheticsData({ page, journeyName });
});
});
`
);
await selectAgentPolicy({ page });
await confirmAndSavePolicy(page);
});

step('go to uptime', async () => {
await goToUptime(page);
});

step('wait for synthetics data', async () => {
await checkForSyntheticsData({ page, journeyName });
});
}
);
}
4 changes: 2 additions & 2 deletions __tests__/formatter/javascript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
const recorderStep: Step = {
actions: [
{
frame: { pageAlias: 'page', "framePath": [] },
frame: { pageAlias: 'page', framePath: [] },
committed: true,
action: {
name: 'openPage',
Expand All @@ -42,7 +42,7 @@ const recorderStep: Step = {
{
frame: {
pageAlias: 'page',
"framePath": [],
framePath: [],
},
committed: true,
action: {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe('Run', () => {
});

it('multiple run invokes runner only once', async () => {
journey('j1', () => { });
journey('j2', () => { });
journey('j1', () => {});
journey('j2', () => {});
/**
* call multiple runs in parallel simulating
* CLI and programmatic API runs
Expand Down
4 changes: 2 additions & 2 deletions __tests__/reporters/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import fs from 'fs';
import SonicBoom from 'sonic-boom';
import BaseReporter from '../../src/reporters/base';
import * as helpers from '../../src/helpers';
import { tJourney, tStep } from "../utils/test-config"
import { tJourney, tStep } from '../utils/test-config';

describe('base reporter', () => {
let dest: string;
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('base reporter', () => {

it('writes each step to the FD', async () => {
const j1 = tJourney();
const s1 = tStep("failed", 1, new Error('step failed'), 'dummy');
const s1 = tStep('failed', 1, new Error('step failed'), 'dummy');
reporter.onJourneyStart(j1, { timestamp });
reporter.onStepEnd(j1, s1, {});
reporter.onEnd();
Expand Down
Loading

0 comments on commit 02637ad

Please sign in to comment.