diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe1b47e8..669183a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/__tests__/cli.test.ts b/__tests__/cli.test.ts index cc6a4a7f..5875ecd4 100644 --- a/__tests__/cli.test.ts +++ b/__tests__/cli.test.ts @@ -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(); } diff --git a/__tests__/core/gatherer.test.ts b/__tests__/core/gatherer.test.ts index 6abd8d7f..9173a38f 100644 --- a/__tests__/core/gatherer.test.ts +++ b/__tests__/core/gatherer.test.ts @@ -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') @@ -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 }) diff --git a/__tests__/core/index.test.ts b/__tests__/core/index.test.ts index a07403d0..4ce53419 100644 --- a/__tests__/core/index.test.ts +++ b/__tests__/core/index.test.ts @@ -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', () => { @@ -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', () => { diff --git a/__tests__/core/mfa.test.ts b/__tests__/core/mfa.test.ts index 3aa46e20..fd57356d 100644 --- a/__tests__/core/mfa.test.ts +++ b/__tests__/core/mfa.test.ts @@ -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); }); }); - - - diff --git a/__tests__/core/runner.test.ts b/__tests__/core/runner.test.ts index 6a12009c..95f2394d 100644 --- a/__tests__/core/runner.test.ts +++ b/__tests__/core/runner.test.ts @@ -62,7 +62,7 @@ describe('runner', () => { try { fs.accessSync(dest); fs.unlinkSync(dest); - } catch (_) { } + } catch (_) {} }); afterAll(async () => await server.close()); @@ -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); @@ -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(); @@ -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(); @@ -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([ { @@ -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(); diff --git a/__tests__/dsl/journey.test.ts b/__tests__/dsl/journey.test.ts index 1464e800..322a0ba0 100644 --- a/__tests__/dsl/journey.test.ts +++ b/__tests__/dsl/journey.test.ts @@ -25,7 +25,7 @@ import { Journey, Step } from '../../src/dsl'; -const noop = () => { }; +const noop = () => {}; describe('Journey', () => { it('add journey details', () => { const name = 'j1'; diff --git a/__tests__/e2e/synthetics.config.ts b/__tests__/e2e/synthetics.config.ts index 6a8764ad..27fee1f6 100644 --- a/__tests__/e2e/synthetics.config.ts +++ b/__tests__/e2e/synthetics.config.ts @@ -26,7 +26,7 @@ export default () => { return { playwrightOptions: { - ignoreHTTPSErrors: true - } - } + ignoreHTTPSErrors: true, + }, + }; }; diff --git a/__tests__/e2e/synthetics.journey.ts b/__tests__/e2e/synthetics.journey.ts index 023de5d7..34909696 100644 --- a/__tests__/e2e/synthetics.journey.ts +++ b/__tests__/e2e/synthetics.journey.ts @@ -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'); } @@ -63,7 +71,9 @@ 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)"'); } @@ -71,32 +81,37 @@ async function selectAgentPolicy({ page }) { } 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 }) => { @@ -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 () => { @@ -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 () => { @@ -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 }); + }); + } + ); } diff --git a/__tests__/formatter/javascript.test.ts b/__tests__/formatter/javascript.test.ts index fdbdc9e5..63ebfef9 100644 --- a/__tests__/formatter/javascript.test.ts +++ b/__tests__/formatter/javascript.test.ts @@ -31,7 +31,7 @@ import { const recorderStep: Step = { actions: [ { - frame: { pageAlias: 'page', "framePath": [] }, + frame: { pageAlias: 'page', framePath: [] }, committed: true, action: { name: 'openPage', @@ -42,7 +42,7 @@ const recorderStep: Step = { { frame: { pageAlias: 'page', - "framePath": [], + framePath: [], }, committed: true, action: { diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index d04d04e0..c2cbb7f2 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -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 diff --git a/__tests__/reporters/base.test.ts b/__tests__/reporters/base.test.ts index ed181afa..0a5d7c63 100644 --- a/__tests__/reporters/base.test.ts +++ b/__tests__/reporters/base.test.ts @@ -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; @@ -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(); diff --git a/__tests__/reporters/buildkite-cli.test.ts b/__tests__/reporters/buildkite-cli.test.ts index d8941391..ae506892 100644 --- a/__tests__/reporters/buildkite-cli.test.ts +++ b/__tests__/reporters/buildkite-cli.test.ts @@ -32,7 +32,7 @@ import * as fs from 'fs'; import SonicBoom from 'sonic-boom'; import BuildKiteCLIReporter from '../../src/reporters/build_kite_cli'; import * as helpers from '../../src/helpers'; -import { tJourney, tStep } from "../utils/test-config" +import { tJourney, tStep } from '../utils/test-config'; describe('buildkite cli reporter', () => { let dest: string; @@ -106,7 +106,7 @@ describe('buildkite cli reporter', () => { it('writes multiple steps to the FD', async () => { const j1 = tJourney('succeeded', 2); const s1 = tStep('succeeded', 1, undefined, 'dummy'); - const s2 = tStep('succeeded', 4, undefined, 'http://localhost:8080',); + const s2 = tStep('succeeded', 4, undefined, 'http://localhost:8080'); reporter.onJourneyStart(j1, { timestamp }); reporter.onStepEnd(j1, s1, {}); reporter.onStepEnd(j1, s2, {}); diff --git a/__tests__/reporters/json.test.ts b/__tests__/reporters/json.test.ts index d51b0cb0..b126d384 100644 --- a/__tests__/reporters/json.test.ts +++ b/__tests__/reporters/json.test.ts @@ -37,7 +37,7 @@ import JSONReporter, { import * as helpers from '../../src/helpers'; import { NETWORK_INFO } from '../fixtures/networkinfo'; import { StatusValue } from '../../src/common_types'; -import { tJourney, tStep } from "../utils/test-config" +import { tJourney, tStep } from '../utils/test-config'; /** * Mock package version to avoid breaking JSON payload @@ -255,7 +255,7 @@ describe('json reporter', () => { it('writes full journey info if present', async () => { const journeyOpts = { name: 'name', id: 'id', tags: ['tag1', 'tag2'] }; - const jj = journey(journeyOpts, () => { }); + const jj = journey(journeyOpts, () => {}); jj.status = 'skipped'; jj.duration = 1; @@ -264,8 +264,7 @@ describe('json reporter', () => { browserDelay: 0, status: 'skipped', options: {}, - } - ); + }); const journeyEnd = (await readAndCloseStreamJson()).find( json => json.type == 'journey/end' diff --git a/__tests__/reporters/junit.test.ts b/__tests__/reporters/junit.test.ts index 39355fe8..f7e0439c 100644 --- a/__tests__/reporters/junit.test.ts +++ b/__tests__/reporters/junit.test.ts @@ -28,10 +28,10 @@ import { join } from 'path'; import SonicBoom from 'sonic-boom'; import JUnitReporter from '../../src/reporters/junit'; import * as helpers from '../../src/helpers'; -import { tJourney, tStep } from "../utils/test-config" +import { tJourney, tStep } from '../utils/test-config'; describe('junit reporter', () => { - beforeEach(() => { }); + beforeEach(() => {}); let dest: string; let stream: SonicBoom; let reporter: JUnitReporter; diff --git a/__tests__/utils/test-config.ts b/__tests__/utils/test-config.ts index 4a0ae448..08725120 100644 --- a/__tests__/utils/test-config.ts +++ b/__tests__/utils/test-config.ts @@ -53,21 +53,31 @@ export function createTestMonitor(filename: string, type = 'browser') { return monitor; } -export function tJourney(status: StatusValue = "succeeded", duration = 0, error?: Error) { - const jj = journey('j1', () => { }); +export function tJourney( + status: StatusValue = 'succeeded', + duration = 0, + error?: Error +) { + const jj = journey('j1', () => {}); jj.status = status; jj.duration = duration; jj.error = error; - return jj + return jj; } -export function tStep(status: StatusValue = "succeeded", duration = 0, error?: Error, url?: string, name?: string) { +export function tStep( + status: StatusValue = 'succeeded', + duration = 0, + error?: Error, + url?: string, + name?: string +) { const ss = step(name ?? 's1', noop); ss.status = status; ss.duration = duration; ss.error = error; ss.url = url; - return ss + return ss; } export class CLIMock { @@ -81,7 +91,7 @@ export class CLIMock { private stderrStr = ''; exitCode: Promise; - constructor(public debug: boolean = false) { } + constructor(public debug: boolean = false) {} args(a: string[]): CLIMock { this.cliArgs.push(...a); diff --git a/package.json b/package.json index a5e431da..f1b91f92 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "watch": "tsc -w", "lint": "eslint . --rulesdir utils/eslint-rules", "lint:fix": "npm run lint -- --fix", + "format": "prettier --check '**/*.ts'", + "format:fix": "prettier --write '**/*.ts'", "test": "npm run test:unit && npm run test:browser-service", "test:unit": "jest", "test:browser-service": "WSENDPOINT=ws://localhost:9322 npm run test:unit", @@ -30,7 +32,8 @@ "lint-staged": { "*.{js,ts}": [ "npm run lint:fix", - "prettier --write" + "npm run format:fix", + "git add" ] }, "husky": { diff --git a/src/cli.ts b/src/cli.ts index 0d03194a..8115b31d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -278,12 +278,17 @@ program // TOTP command program .command('totp ') - .description('Generate a Time-based One-Time token using the provided secret.') - .option('--issuer ', 'Provider or Service the secret is associated with.') + .description( + 'Generate a Time-based One-Time token using the provided secret.' + ) + .option( + '--issuer ', + 'Provider or Service the secret is associated with.' + ) .option('--label