Skip to content

Commit a1ec69c

Browse files
chore: fix formatting and run check (#990)
* chore: fix formatting and run check * add ignore file * apply suggestions from code review Co-authored-by: Emilio Alvarez Piñeiro <[email protected]> --------- Co-authored-by: Emilio Alvarez Piñeiro <[email protected]>
1 parent 8a73648 commit a1ec69c

32 files changed

+201
-151
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
node-version-file: .nvmrc
2222
- run: npm ci
2323
- run: npm run-script lint
24+
- run: npm run-script format:check
2425

2526
build:
2627
runs-on: ubuntu-latest

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
examples
3+
templates
4+
__tests__/e2e/tmp/

__tests__/cli.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,7 @@ describe('CLI', () => {
494494

495495
describe('TOTP token', () => {
496496
async function runTotp(args) {
497-
const cli = new CLIMock()
498-
.args(['totp', ...args])
499-
.run({});
497+
const cli = new CLIMock().args(['totp', ...args]).run({});
500498
await cli.exitCode;
501499
return cli.stderr();
502500
}

__tests__/core/gatherer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ describe('Gatherer', () => {
272272
wsEndpoint,
273273
playwrightOptions: { navigationTimeout: 1, actionTimeout: 2 },
274274
});
275-
server.route('/hang.html', () => { });
275+
server.route('/hang.html', () => {});
276276
let error: any = null;
277277
await driver.page
278278
.goto(server.PREFIX + '/hang.html')
@@ -287,7 +287,7 @@ describe('Gatherer', () => {
287287
wsEndpoint,
288288
playwrightOptions: { navigationTimeout: 3 },
289289
});
290-
server.route('/hang.html', () => { });
290+
server.route('/hang.html', () => {});
291291
let error: any = null;
292292
await driver.page
293293
.goto(server.PREFIX + '/hang.html', { timeout: 1 })

__tests__/core/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { runner } from '../../src/core/globals';
3535

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

38-
const noop = () => { };
38+
const noop = () => {};
3939
const name = 'journey';
4040

4141
it('add global hooks to runner', () => {
@@ -77,8 +77,8 @@ it('add hooks to journeys', () => {
7777
expect(runner.currentJourney).toEqual(j);
7878
expect(runner.journeys.length).toBe(1);
7979
expect(runner.currentJourney?.steps.length).toBe(0);
80-
expect(runner.currentJourney?._getHook("before")).toEqual([noop]);
81-
expect(runner.currentJourney?._getHook("after")).toEqual([noop]);
80+
expect(runner.currentJourney?._getHook('before')).toEqual([noop]);
81+
expect(runner.currentJourney?._getHook('after')).toEqual([noop]);
8282
});
8383

8484
it('add hooks - error on before/after outside journey context', () => {

__tests__/core/mfa.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ import { totp } from '../../src/core/mfa';
2727

2828
describe('MFA', () => {
2929
it('generate TOTP', () => {
30-
const token = totp("FLIIOLP3IR3W");
30+
const token = totp('FLIIOLP3IR3W');
3131
expect(token.length).toBe(6);
3232
});
3333
});
34-
35-
36-

__tests__/core/runner.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('runner', () => {
6262
try {
6363
fs.accessSync(dest);
6464
fs.unlinkSync(dest);
65-
} catch (_) { }
65+
} catch (_) {}
6666
});
6767
afterAll(async () => await server.close());
6868

@@ -167,7 +167,9 @@ describe('runner', () => {
167167

168168
it('run journey - failed on beforeAll', async () => {
169169
const error = new Error('Broken beforeAll hook');
170-
runner._addHook('beforeAll', () => { throw error });
170+
runner._addHook('beforeAll', () => {
171+
throw error;
172+
});
171173
runner._addJourney(new Journey({ name: 'j1' }, () => step('step1', noop)));
172174
runner._addJourney(new Journey({ name: 'j2' }, () => step('step1', noop)));
173175
const result = await runner._run(defaultRunOptions);
@@ -188,7 +190,9 @@ describe('runner', () => {
188190
expect(info.currentJourney?.error).toBe(error);
189191
expect(info.currentJourney?.duration).toBeGreaterThan(0);
190192
});
191-
step('step1', () => { throw error });
193+
step('step1', () => {
194+
throw error;
195+
});
192196
});
193197
const result = await runner._runJourney(j1, defaultRunOptions);
194198
await Gatherer.stop();
@@ -206,7 +210,7 @@ describe('runner', () => {
206210
after(({ info }) => {
207211
expect(info.currentJourney?.status).toBe('succeeded');
208212
expect(info.currentJourney?.duration).toBeGreaterThan(0);
209-
})
213+
});
210214
});
211215
const result = await runner._runJourney(j1, defaultRunOptions);
212216
await Gatherer.stop();
@@ -223,7 +227,7 @@ describe('runner', () => {
223227
});
224228
const runOptions = { ...defaultRunOptions, metrics: true };
225229
const result = await runner._runJourney(j1, runOptions);
226-
await Gatherer.stop()
230+
await Gatherer.stop();
227231
expect(result.stepsresults?.[0].pagemetrics).toBeDefined();
228232
expect(result.steps).toMatchObject([
229233
{
@@ -659,7 +663,7 @@ describe('runner', () => {
659663
});
660664
runner._addJourney(j1);
661665
const runOptions = { ...defaultRunOptions, trace: true };
662-
const results = await runner._run(runOptions)
666+
const results = await runner._run(runOptions);
663667
const steps = results[j1.name].stepsresults;
664668
expect(steps?.length).toBe(2);
665669
expect(steps?.[0].metrics).toBeUndefined();

__tests__/dsl/journey.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

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

28-
const noop = () => { };
28+
const noop = () => {};
2929
describe('Journey', () => {
3030
it('add journey details', () => {
3131
const name = 'j1';

__tests__/e2e/synthetics.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
export default () => {
2727
return {
2828
playwrightOptions: {
29-
ignoreHTTPSErrors: true
30-
}
31-
}
29+
ignoreHTTPSErrors: true,
30+
},
31+
};
3232
};

__tests__/e2e/synthetics.journey.ts

Lines changed: 77 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,31 @@ async function logIn(page) {
3535
}
3636

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

5361
async function goToUptime(page) {
54-
console.info('Navigating to Uptime overview page')
62+
console.info('Navigating to Uptime overview page');
5563
await page.goto('https://localhost:5601/app/uptime');
5664
}
5765

@@ -63,40 +71,47 @@ async function selectAgentPolicy({ page }) {
6371
await page.click('[data-test-subj="agentPolicySelect"]');
6472
await page.click('text="Elastic-Agent (elastic-package)"');
6573
} else {
66-
await page.selectOption('[data-test-subj="agentPolicySelect"]', { label: 'Elastic-Agent (elastic-package)' });
74+
await page.selectOption('[data-test-subj="agentPolicySelect"]', {
75+
label: 'Elastic-Agent (elastic-package)',
76+
});
6777
}
6878
await page.waitForSelector('text="Elastic-Agent (elastic-package)"');
6979
}
7080
await page.click('[data-test-subj="packagePolicyNameInput"]');
7181
}
7282

7383
async function createIntegrationPolicyName({ page, policyName }) {
74-
await page.waitForSelector('[data-test-subj="packagePolicyNameInput"]', { timeout: 10000 });
84+
await page.waitForSelector('[data-test-subj="packagePolicyNameInput"]', {
85+
timeout: 10000,
86+
});
7587
await page.fill('[data-test-subj="packagePolicyNameInput"]', policyName);
7688
}
7789

7890
async function confirmAndSavePolicy(page) {
7991
await page.click('[data-test-subj="createPackagePolicySaveButton"]');
80-
await Promise.all([page.waitForNavigation(), page.click('[data-test-subj="confirmModalConfirmButton"]')]);
92+
await Promise.all([
93+
page.waitForNavigation(),
94+
page.click('[data-test-subj="confirmModalConfirmButton"]'),
95+
]);
8196
}
8297

8398
async function checkForSyntheticsData({ page, journeyName }) {
84-
const checkForTable = async () => {
99+
const checkForTable = async () => {
85100
try {
86101
return await page.waitForSelector('.euiTableRow', { timeout: 5000 });
87102
} catch (e) {
88103
console.error(e);
89104
}
90-
}
105+
};
91106
let isTableVisible = await checkForTable();
92107
while (!isTableVisible) {
93-
console.info('Reloading Uptime...')
108+
console.info('Reloading Uptime...');
94109
await page.reload();
95110
isTableVisible = await checkForTable();
96111
}
97112
await page.fill('[data-test-subj="queryInput"]', journeyName);
98113
await page.click(`a:has-text("${journeyName}")`, { timeout: 300 * 1000 });
99-
console.info(`Data for ${journeyName} indexed successfully`)
114+
console.info(`Data for ${journeyName} indexed successfully`);
100115
}
101116

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

109124
step('create an http monitor', async () => {
110125
await createIntegrationPolicyName({ page, policyName: journeyName });
111-
await page.fill('[data-test-subj="syntheticsUrlField"]', 'https://elastic.co');
126+
await page.fill(
127+
'[data-test-subj="syntheticsUrlField"]',
128+
'https://elastic.co'
129+
);
112130
await selectAgentPolicy({ page });
113131
await page.click('[data-test-subj="syntheticsUrlField"]');
114132
await confirmAndSavePolicy(page);
115-
console.info(`Monitor for ${journeyName} created successfully`)
133+
console.info(`Monitor for ${journeyName} created successfully`);
116134
});
117135

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

134152
step('create an tcp monitor', async () => {
135153
await createIntegrationPolicyName({ page, policyName: journeyName });
136-
await page.selectOption('[data-test-subj="syntheticsMonitorTypeField"]', 'tcp');
137-
await page.fill('[data-test-subj="syntheticsTCPHostField"]', 'smtp.gmail.com:587');
154+
await page.selectOption(
155+
'[data-test-subj="syntheticsMonitorTypeField"]',
156+
'tcp'
157+
);
158+
await page.fill(
159+
'[data-test-subj="syntheticsTCPHostField"]',
160+
'smtp.gmail.com:587'
161+
);
138162
await selectAgentPolicy({ page });
139163
await confirmAndSavePolicy(page);
140-
console.info(`Monitor for ${journeyName} created successfully`)
164+
console.info(`Monitor for ${journeyName} created successfully`);
141165
});
142166

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

175199
if (semver.satisfies(stackVersion, '>=8.0.1')) {
176-
journey(`${stackVersion} e2e test synthetics - browser - inline`, async ({ page }) => {
177-
const journeyName = 'Sample browser inline integration policy';
178-
179-
step('Go to synthetics integration page', async () => {
180-
await goToSyntheticsIntegrationPage(page);
181-
});
182-
183-
step('create an browser monitor', async () => {
184-
await createIntegrationPolicyName({ page, policyName: journeyName });
185-
await page.selectOption('[data-test-subj="syntheticsMonitorTypeField"]', 'browser');
186-
await page.click('[data-test-subj="syntheticsSourceTab__inline"]');
187-
await page.fill('[data-test-subj=codeEditorContainer] textarea', `
200+
journey(
201+
`${stackVersion} e2e test synthetics - browser - inline`,
202+
async ({ page }) => {
203+
const journeyName = 'Sample browser inline integration policy';
204+
205+
step('Go to synthetics integration page', async () => {
206+
await goToSyntheticsIntegrationPage(page);
207+
});
208+
209+
step('create an browser monitor', async () => {
210+
await createIntegrationPolicyName({ page, policyName: journeyName });
211+
await page.selectOption(
212+
'[data-test-subj="syntheticsMonitorTypeField"]',
213+
'browser'
214+
);
215+
await page.click('[data-test-subj="syntheticsSourceTab__inline"]');
216+
await page.fill(
217+
'[data-test-subj=codeEditorContainer] textarea',
218+
`
188219
step('load homepage', async () => {
189220
await page.goto('https://www.elastic.co');
190221
});
191-
`);
192-
await selectAgentPolicy({ page });
193-
await confirmAndSavePolicy(page);
194-
});
195-
196-
step('go to uptime', async () => {
197-
await goToUptime(page);
198-
});
199-
200-
step('wait for synthetics data', async () => {
201-
await checkForSyntheticsData({ page, journeyName });
202-
});
203-
});
222+
`
223+
);
224+
await selectAgentPolicy({ page });
225+
await confirmAndSavePolicy(page);
226+
});
227+
228+
step('go to uptime', async () => {
229+
await goToUptime(page);
230+
});
231+
232+
step('wait for synthetics data', async () => {
233+
await checkForSyntheticsData({ page, journeyName });
234+
});
235+
}
236+
);
204237
}

0 commit comments

Comments
 (0)