Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FTR] enable recommended mocha + no-floating-promises ESLint rules #190690

Merged
merged 44 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
913b20e
enable await rules for functional tests
dmlemeshko Aug 19, 2024
1443207
Merge branch 'main' into add-mocha-rules-for-ftr
mistic Aug 19, 2024
bc0ec57
update rules and fix tests
dmlemeshko Aug 19, 2024
e031756
Merge branch 'add-mocha-rules-for-ftr' of github.com:dmlemeshko/kiban…
dmlemeshko Aug 19, 2024
4f9b03a
update serverless ftr tests
dmlemeshko Aug 19, 2024
3741932
Merge branch 'main' into add-mocha-rules-for-ftr
dmlemeshko Aug 19, 2024
fa1fa36
unskip test
dmlemeshko Aug 19, 2024
2d27bc8
Merge remote-tracking branch 'upstream/main' into add-mocha-rules-for…
dmlemeshko Aug 20, 2024
2b65033
fix tests
dmlemeshko Aug 20, 2024
770e448
add tests files to eslint config template
dmlemeshko Aug 20, 2024
9f87d5a
fix x-pack/test_serverless
dmlemeshko Aug 20, 2024
408cb77
reset tsconfig
dmlemeshko Aug 21, 2024
a1ed8d2
Merge branch 'main' into debug-build-failure
dmlemeshko Aug 21, 2024
ac4e998
fix errors: x-pack/test/security_solution_api_integration
dmlemeshko Aug 21, 2024
c973dee
Merge remote-tracking branch 'upstream/main' into debug-build-failure
dmlemeshko Aug 21, 2024
7d5b1e0
Merge branch 'debug-build-failure' of github.com:dmlemeshko/kibana in…
dmlemeshko Aug 21, 2024
34df892
fix errors: packages/core/application/core-application-browser-internal
dmlemeshko Aug 21, 2024
60edf38
limit rule to ftr functional/api_integration only
dmlemeshko Aug 21, 2024
8b34097
fix errors: test/
dmlemeshko Aug 21, 2024
f0eda8b
Merge branch 'main' into debug-build-failure
dmlemeshko Aug 21, 2024
a35e161
fix errors: x-pack/test/
dmlemeshko Aug 21, 2024
6795834
Merge branch 'debug-build-failure' of github.com:dmlemeshko/kibana in…
dmlemeshko Aug 21, 2024
78efd54
fix more errors: x-pack/test/
dmlemeshko Aug 22, 2024
6487de1
Merge remote-tracking branch 'upstream/main' into debug-build-failure
dmlemeshko Aug 22, 2024
2d46106
fix more errors: x-pack/test/
dmlemeshko Aug 22, 2024
c9a74e2
fix more errors: test/
dmlemeshko Aug 22, 2024
8fdfd30
Merge branch 'main' into debug-build-failure
dmlemeshko Aug 22, 2024
6c641b7
fix duplicate beforeEach hook and duplicate title
dmlemeshko Aug 22, 2024
cb7c503
Merge branch 'debug-build-failure' of github.com:dmlemeshko/kibana in…
dmlemeshko Aug 22, 2024
9b920c0
Merge branch 'main' into add-mocha-rules-for-ftr
dmlemeshko Aug 22, 2024
db84f66
fix eslint errors
dmlemeshko Aug 22, 2024
819f66b
skip failing tests
dmlemeshko Aug 22, 2024
a1b7313
Merge branch 'add-mocha-rules-for-ftr' of github.com:dmlemeshko/kiban…
dmlemeshko Aug 22, 2024
0c2075c
skip failing test
dmlemeshko Aug 22, 2024
5aeffc7
Merge branch 'main' into add-mocha-rules-for-ftr
dmlemeshko Aug 22, 2024
c14eadf
update _autocomplete console test
dmlemeshko Aug 22, 2024
820cc51
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 22, 2024
c60984a
rewrite tests to match mocha rules
dmlemeshko Aug 23, 2024
40dce15
Merge branch 'add-mocha-rules-for-ftr' of github.com:dmlemeshko/kiban…
dmlemeshko Aug 23, 2024
d70c48f
merge main
dmlemeshko Aug 23, 2024
5888502
apply recommended mocha rules for api_integration path
dmlemeshko Aug 23, 2024
8a3da51
Update .eslintrc.js
dmlemeshko Aug 23, 2024
7b32863
Merge branch 'main' into add-mocha-rules-for-ftr
dmlemeshko Aug 23, 2024
28e408e
Merge branch 'main' into add-mocha-rules-for-ftr
dmlemeshko Aug 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,25 @@ module.exports = {
'react/jsx-fragments': 'error',
},
},
{
files: [
'test/{accessibility,*functional*,*api_integration*}/apps/**/*.{js,ts}',
'x-pack/test/{accessibility,*functional*,*api_integration*}/apps/**/*.{js,ts}',
'x-pack/test_serverless/{functional,api_integration}/test_suites/**/*.{js,ts}',
],
extends: ['plugin:mocha/recommended'],
plugins: ['mocha'],
env: {
mocha: true,
},
rules: {
'mocha/no-mocha-arrows': 'off',
'mocha/no-exports': 'off',
'mocha/no-setup-in-describe': 'off',
'mocha/no-nested-tests': 'off',
'mocha/no-skipped-tests': 'off',
},
},
{
files: ['x-pack/plugins/lists/public/**/!(*.test).{js,mjs,ts,tsx}'],
plugins: ['react-perf'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('ApplicationService', () => {

await act(async () => {
await navigateToApp('app1');
update();
await update();
});

expect(currentAppIds).toEqual(['app1']);
Expand Down Expand Up @@ -195,15 +195,15 @@ describe('ApplicationService', () => {

await act(async () => {
await navigateToApp('app1');
update();
await update();
});
await act(async () => {
await navigateToApp('app2', { path: '/nested' });
update();
await update();
});
await act(async () => {
await navigateToApp('app2', { path: '/another-path' });
update();
await update();
});

expect(locations).toEqual(['/', '/app/app1', '/app/app2/nested', '/app/app2/another-path']);
Expand Down Expand Up @@ -625,9 +625,14 @@ describe('ApplicationService', () => {
title: 'App1',
mount: async ({ setHeaderActionMenu }: AppMountParameters) => {
setHeaderActionMenu(mounter1);
promise.then(() => {
setHeaderActionMenu(mounter2);
});
promise
.then(() => {
setHeaderActionMenu(mounter2);
})
.catch((error) => {
// eslint-disable-next-line no-console
console.error('Error:', error);
});
return () => undefined;
},
});
Expand Down Expand Up @@ -663,9 +668,14 @@ describe('ApplicationService', () => {
title: 'App1',
mount: async ({ setHeaderActionMenu }: AppMountParameters) => {
setHeaderActionMenu(mounter1);
promise.then(() => {
setHeaderActionMenu(undefined);
});
promise
.then(() => {
setHeaderActionMenu(undefined);
})
.catch((error) => {
// eslint-disable-next-line no-console
console.error('Error:', error);
});
return () => undefined;
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/dev/eslint/types.eslint.config.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
},
overrides: [
{
files: ['server/**/*'],
files: ['server/**/*', '*functional*/**/*', '*api_integration*/**/*'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a good start, PR has quite many changes. We have more tests, but I think it is better to handle separately

rules: {
// Let's focus on server-side errors first to avoid server crashes.
// We'll tackle /public eventually.
Expand Down
6 changes: 3 additions & 3 deletions test/accessibility/apps/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const dashboardName = 'Dashboard Listing A11y';
const clonedDashboardName = 'Dashboard Listing A11y (1)';

it('dashboard', async () => {
it('navitate to dashboard app', async () => {
await PageObjects.common.navigateToApp('dashboard');
await a11y.testAppSnapshot();
});
Expand Down Expand Up @@ -61,7 +61,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await a11y.testAppSnapshot();
});

it('Open Edit mode', async () => {
it('Open Edit mode again', async () => {
await PageObjects.dashboard.switchToEditMode();
await a11y.testAppSnapshot();
});
Expand All @@ -86,7 +86,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await a11y.testAppSnapshot();
});

it('Open add panel', async () => {
it('Open add panel again', async () => {
await dashboardAddPanel.clickOpenAddPanel();
await a11y.testAppSnapshot();
});
Expand Down
2 changes: 1 addition & 1 deletion test/accessibility/apps/management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await a11y.testAppSnapshot();
});

describe('data views', async () => {
describe('data views', () => {
before(async () => {
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function ({ getService }: FtrProviderContext) {
expect(response.get('vary')).to.equal('accept-encoding, user-hash');
expect(response.get('etag')).to.not.be.empty();

kibanaServer.uiSettings.replace({ 'data_views:cache_max_age': 5 });
await kibanaServer.uiSettings.replace({ 'data_views:cache_max_age': 5 });
});

it('returns 304 on matching etag', async () => {
Expand Down
67 changes: 32 additions & 35 deletions test/functional/apps/console/ace/_autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import _ from 'lodash';
import expect from '@kbn/expect';
import { asyncForEach } from '@kbn/std';
import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
Expand All @@ -17,6 +16,24 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['common', 'console', 'header']);
const find = getService('find');

async function runTemplateTest(type: string, template: string) {
await PageObjects.console.enterText(`{\n\t"type": "${type}"`);
await PageObjects.console.pressEnter();
await PageObjects.console.sleepForDebouncePeriod();
// Prompt autocomplete for 'settings'
await PageObjects.console.promptAutocomplete('s');

await retry.waitFor('autocomplete to be visible', () =>
PageObjects.console.isAutocompleteVisible()
);
await PageObjects.console.pressEnter();
await retry.try(async () => {
const request = await PageObjects.console.getRequest();
log.debug(request);
expect(request).to.contain(`${template}`);
});
}

describe('console autocomplete feature', function describeIndexTests() {
this.tags('includeFirefox');
before(async () => {
Expand Down Expand Up @@ -365,47 +382,27 @@ GET _search
});
});

describe('with conditional templates', async () => {
const CONDITIONAL_TEMPLATES = [
{
type: 'fs',
template: `"location": "path"`,
},
{
type: 'url',
template: `"url": ""`,
},
{ type: 's3', template: `"bucket": ""` },
{
type: 'azure',
template: `"path": ""`,
},
];

describe('with conditional templates', () => {
beforeEach(async () => {
await PageObjects.console.clearTextArea();
await PageObjects.console.enterRequest('\n POST _snapshot/test_repo');
await PageObjects.console.pressEnter();
});

await asyncForEach(CONDITIONAL_TEMPLATES, async ({ type, template }) => {
it('should insert different templates depending on the value of type', async () => {
await PageObjects.console.enterText(`{\n\t"type": "${type}"`);
await PageObjects.console.pressEnter();
await PageObjects.console.sleepForDebouncePeriod();
// Prompt autocomplete for 'settings'
await PageObjects.console.promptAutocomplete('s');
it('should insert fs template', async () => {
await runTemplateTest('fs', `"location": "path"`);
});

await retry.waitFor('autocomplete to be visible', () =>
PageObjects.console.isAutocompleteVisible()
);
await PageObjects.console.pressEnter();
await retry.try(async () => {
const request = await PageObjects.console.getRequest();
log.debug(request);
expect(request).to.contain(`${template}`);
});
});
it('should insert url template', async () => {
await runTemplateTest('url', `"url": ""`);
});

it('should insert s3 template', async () => {
await runTemplateTest('s3', `"bucket": ""`);
});

it('should insert azure template', async () => {
await runTemplateTest('azure', `"path": ""`);
});
});
});
Expand Down
Loading
Loading