Skip to content

Commit

Permalink
Upgrades TypeScript to 4.1, simplifies jest config
Browse files Browse the repository at this point in the history
* Addressing the `nth-check` CVE required bumping `css-select`, which
is a dependency of `cheerio`. Bumping `cheerio` requires upgrading from
TypeScript 4.0 to 4.1.
* TypeScript 4.1 introduces a set of [breaking changes](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#breaking-changes).
The main changes that impact Dashboards is that `resolve`'s parameters
are no longer optional in `Promise`s, and that potentially undefined
indexes must use the `!` non-null assertion operator.
* The upgrades to TypeScript and `cheerio` triggered some jest errors
which prompted the upgrade to the `enzyme` dependencies.
* Merges files under `/src/test_utils` and `/src/dev/jest` into the
`@osd/test` package to simplify.

Resolves opensearch-project#1081

Signed-off-by: Tommy Markley <markleyt@amazon.com>
  • Loading branch information
Tommy Markley committed Mar 3, 2022
1 parent 082f44a commit 5027633
Show file tree
Hide file tree
Showing 375 changed files with 1,593 additions and 1,434 deletions.
2 changes: 1 addition & 1 deletion examples/bfetch_explorer/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class BfetchExplorerPlugin implements Plugin {
// Validate inputs.
if (num < 0) throw new Error('Invalid number');
// Wait number of specified milliseconds.
await new Promise((r) => setTimeout(r, num));
await new Promise<void>((r) => setTimeout(r, num));
// Double the number and send it back.
return { num: 2 * num };
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const createEditBookAction = (getStartServices: () => Promise<StartServic
return savedObjectsClient.create(BOOK_EMBEDDABLE, attributes);
},
checkForDuplicateTitle: (props: OnSaveProps) => {
return new Promise(() => {
return new Promise<true>(() => {
return true;
});
},
Expand Down
2 changes: 1 addition & 1 deletion examples/state_containers_examples/public/todo/todo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export const TodoAppPage: React.FC<{

function withDefaultState<State extends BaseState>(
stateContainer: BaseStateContainer<State>,
// eslint-disable-next-line no-shadow
// eslint-disable-next-line @typescript-eslint/no-shadow
defaultState: State
): INullableBaseStateContainer<State> {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ function useGlobalStateSyncing(
}, [query, osdUrlStateStorage]);
}

// eslint-disable-next-line @typescript-eslint/no-shadow
function useAppStateSyncing<AppState extends QueryState>(
appStateContainer: BaseStateContainer<AppState>,
query: DataPublicPluginStart['query'],
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"**/minimist": "^1.2.5",
"**/node-jose": "^2.1.0",
"**/trim": "^0.0.3",
"**/typescript": "4.0.2"
"**/typescript": "4.1.6"
},
"workspaces": {
"packages": [
Expand Down Expand Up @@ -243,7 +243,7 @@
"@types/babel__core": "^7.1.17",
"@types/bluebird": "^3.1.1",
"@types/chance": "^1.0.0",
"@types/cheerio": "^0.22.10",
"@types/cheerio": "^0.22.30",
"@types/chromedriver": "^81.0.0",
"@types/classnames": "^2.2.9",
"@types/color": "^3.0.0",
Expand All @@ -252,7 +252,7 @@
"@types/deep-freeze-strict": "^1.1.0",
"@types/delete-empty": "^2.0.0",
"@types/elasticsearch": "^5.0.33",
"@types/enzyme": "^3.10.5",
"@types/enzyme": "^3.10.11",
"@types/eslint": "^6.1.3",
"@types/fetch-mock": "^7.3.1",
"@types/flot": "^0.0.31",
Expand Down Expand Up @@ -317,8 +317,8 @@
"@types/webpack": "^4.41.31",
"@types/webpack-env": "^1.16.3",
"@types/zen-observable": "^0.8.0",
"@typescript-eslint/eslint-plugin": "^3.10.0",
"@typescript-eslint/parser": "^3.10.0",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"angular-aria": "^1.8.0",
"angular-mocks": "^1.8.2",
"angular-recursion": "^1.0.5",
Expand All @@ -331,7 +331,7 @@
"brace": "0.11.1",
"chai": "3.5.0",
"chance": "1.0.18",
"cheerio": "0.22.0",
"cheerio": "^1.0.0-rc.10",
"chromedriver": "^91.0.1",
"classnames": "2.2.6",
"compare-versions": "3.5.1",
Expand All @@ -340,8 +340,8 @@
"dedent": "^0.7.0",
"delete-empty": "^2.0.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"enzyme-to-json": "^3.4.4",
"enzyme-adapter-react-16": "^1.15.6",
"enzyme-to-json": "^3.6.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-babel": "^5.3.1",
Expand All @@ -357,7 +357,7 @@
"eslint-plugin-prefer-object-spread": "^1.2.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.4",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-react-perf": "^3.2.3",
"exit-hook": "^2.2.0",
"fetch-mock": "^7.3.9",
Expand Down Expand Up @@ -434,7 +434,7 @@
"topojson-client": "3.0.0",
"tough-cookie": "^4.0.0",
"tree-kill": "^1.2.2",
"typescript": "4.0.2",
"typescript": "4.1.6",
"ui-select": "0.19.8",
"vega": "^5.17.3",
"vega-lite": "^4.16.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
},
"homepage": "https://github.com/opensearch-project/OpenSearch-Dashboards/tree/main/packages/opensearch-eslint-config-opensearch-dashboards",
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^3.10.0",
"@typescript-eslint/parser": "^3.10.0",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"babel-eslint": "^10.0.3",
"eslint": "^6.8.0",
"eslint-plugin-babel": "^5.3.1",
Expand All @@ -32,6 +32,6 @@
"eslint-plugin-no-unsanitized": "^3.0.2",
"eslint-plugin-prefer-object-spread": "^1.2.1",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-react-hooks": "^4.0.4"
"eslint-plugin-react-hooks": "^4.2.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ module.exports = {
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-undef': 'off',
'@typescript-eslint/triple-slash-reference': [
'error',
{
Expand Down Expand Up @@ -255,7 +257,6 @@ module.exports = {
'no-eval': 'error',
'no-new-wrappers': 'error',
'no-script-url': 'error',
'no-shadow': 'error',
'no-throw-literal': 'error',
'no-undef-init': 'error',
'no-unsafe-finally': 'error',
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-ace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@osd/dev-utils": "1.0.0",
"@osd/babel-preset": "1.0.0",
"raw-loader": "^4.0.2",
"typescript": "4.0.2",
"typescript": "4.1.6",
"webpack": "^4.41.5"
}
}
2 changes: 1 addition & 1 deletion packages/osd-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"@babel/cli": "^7.16.0",
"@osd/dev-utils": "1.0.0",
"@osd/babel-preset": "1.0.0",
"typescript": "4.0.2"
"typescript": "4.1.6"
}
}
2 changes: 1 addition & 1 deletion packages/osd-apm-config-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"typescript": "4.0.2",
"typescript": "4.1.6",
"tsd": "^0.16.0"
}
}
2 changes: 1 addition & 1 deletion packages/osd-config-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"osd:bootstrap": "yarn build"
},
"devDependencies": {
"typescript": "4.0.2",
"typescript": "4.1.6",
"tsd": "^0.16.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"@osd/dev-utils": "1.0.0",
"@osd/utility-types": "1.0.0",
"typescript": "4.0.2",
"typescript": "4.1.6",
"tsd": "^0.16.0"
}
}
4 changes: 2 additions & 2 deletions packages/osd-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@osd/utils": "1.0.0",
"axios": "^0.21.4",
"chalk": "^4.1.0",
"cheerio": "0.22.0",
"dedent": "^0.7.0",
"execa": "^4.0.2",
"exit-hook": "^2.2.0",
Expand All @@ -37,6 +36,7 @@
"@osd/expect": "1.0.0",
"@types/vinyl": "^2.0.4",
"chance": "1.0.18",
"typescript": "4.0.2"
"cheerio": "^1.0.0-rc.10",
"typescript": "4.1.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class CiStatsReporter {
`failed to reach opensearch-dashboards-ci-stats service [reason=${reason}], retrying in ${attempt} seconds`
);

await new Promise((resolve) => setTimeout(resolve, attempt * 1000));
await new Promise<void>((resolve) => setTimeout(resolve, attempt * 1000));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface ReqOptions {
}

const delay = (ms: number) =>
new Promise((resolve) => {
new Promise<void>((resolve) => {
setTimeout(resolve, ms);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/osd-dev-utils/src/proc_runner/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function withTimeout(
try {
await Promise.race([
attempt(),
new Promise((_, reject) => setTimeout(() => reject(TIMEOUT), ms)),
new Promise<void>((_, reject) => setTimeout(() => reject(TIMEOUT), ms)),
]);
} catch (error) {
if (error === TIMEOUT) {
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-dev-utils/src/proc_runner/proc_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class ProcRunner {
// processes and stopping, but consumers of run() shouldn't have to
// prepare for that, so just return a never-resolving promise
if (this.closing) {
await new Promise(noop);
await new Promise<void>(noop);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ it('waits for promise to resolve before tearing down proc', async () => {
let teardownSpy;

await withProcRunner(new ToolingLog(), async (proc) => {
await new Promise((resolve) => setTimeout(resolve, 500));
await new Promise<void>((resolve) => setTimeout(resolve, 500));
teardownSpy = jest.spyOn(proc, 'teardown');
});

Expand All @@ -81,7 +81,7 @@ it('waits for promise to reject before tearing down proc and rejecting with the

await expect(
withProcRunner(new ToolingLog(), async (proc) => {
await new Promise((resolve) => setTimeout(resolve, 500));
await new Promise<void>((resolve) => setTimeout(resolve, 500));
teardownSpy = jest.spyOn(proc, 'teardown');
throw error;
})
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-dev-utils/src/run/run_with_commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ beforeEach(() => {
});

it('extends the context using extendContext()', async () => {
const context: any = await new Promise((resolve) => {
const context: any = await new Promise<any>((resolve) => {
testCli.command({ name: 'foo', description: 'some command', run: resolve }).execute();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ exports.getWebpackConfig = function (opensearchDashboardsPath) {
alias: {
// Dev defaults for test bundle https://github.com/opensearch-project/OpenSearch-Dashboards/blob/6998f074542e8c7b32955db159d15661aca253d7/src/core_plugins/tests_bundle/index.js#L73-L78
fixtures: resolve(opensearchDashboardsPath, 'src/fixtures'),
test_utils: resolve(opensearchDashboardsPath, 'src/test_utils/public'),
},
unsafeCache: true,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-i18n/GUIDELINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Testing React component that uses the `injectI18n` higher-order component is mor

With shallow rendering only top level component is rendered, that is a wrapper itself, not the original component. Since we want to test the rendering of the original component, we need to access it via the wrapper's `WrappedComponent` property. Its value will be the component we passed into `injectI18n()`.

When testing such component, use the `shallowWithIntl` helper function defined in `test_utils/enzyme_helpers` and pass the component's `WrappedComponent` property to render the wrapped component. This will shallow render the component with Enzyme and inject the necessary context and props to use the `intl` mock defined in `test_utils/mocks/intl`.
When testing such component, use the `shallowWithIntl` helper function defined in `@osd/test/jest` and pass the component's `WrappedComponent` property to render the wrapped component. This will shallow render the component with Enzyme and inject the necessary context and props to use the `intl` mock defined in `test_utils/mocks/intl`.

Use the `mountWithIntl` helper function to mount render the component.

Expand Down
2 changes: 1 addition & 1 deletion packages/osd-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"del": "^5.1.0",
"getopts": "^2.2.5",
"supports-color": "^7.0.0",
"typescript": "4.0.2"
"typescript": "4.1.6"
},
"dependencies": {
"intl-format-cache": "^2.1.0",
Expand Down
4 changes: 1 addition & 3 deletions packages/osd-i18n/src/react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
*/

import { InjectedIntl as _InjectedIntl, InjectedIntlProps as _InjectedIntlProps } from 'react-intl';

export type InjectedIntl = _InjectedIntl;
export type InjectedIntlProps = _InjectedIntlProps;
export type { InjectedIntl, InjectedIntlProps } from 'react-intl';

export {
intlShape,
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-logging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"@osd/std": "1.0.0"
},
"devDependencies": {
"typescript": "4.0.2"
"typescript": "4.1.6"
}
}
2 changes: 1 addition & 1 deletion packages/osd-monaco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"del": "^5.1.0",
"raw-loader": "^4.0.2",
"supports-color": "^7.0.0",
"typescript": "4.0.2",
"typescript": "4.1.6",
"webpack": "^4.41.5",
"webpack-cli": "^4.9.2"
}
Expand Down
1 change: 1 addition & 0 deletions packages/osd-opensearch-archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"@osd/dev-utils": "1.0.0",
"@osd/test": "1.0.0",
"elasticsearch": "^16.7.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-opensearch-archiver/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export function runCli() {
output: process.stdout,
});

await new Promise((resolveInput) => {
await new Promise<void>((resolveInput) => {
rl.question(`Press enter when you're done`, () => {
rl.close();
resolveInput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('opensearchArchiver createParseArchiveStreams', () => {

it('provides each JSON object as soon as it is parsed', async () => {
let onReceived: (resolved: any) => void;
const receivedPromise = new Promise((resolve) => (onReceived = resolve));
const receivedPromise = new Promise<void>((resolve) => (onReceived = resolve));
const input = new PassThrough();
const check = new Transform({
writableObjectMode: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export async function waitForSnapshotCompletion(client: Client, index: string, l

while (await isSnapshotPending(repository, found.snapshot)) {
// wait a bit before getting status again
await new Promise((resolve) => setTimeout(resolve, 500));
await new Promise<void>((resolve) => setTimeout(resolve, 500));
}

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,6 @@ it('stops an infinite stream when unsubscribed', async () => {

// ensure summarizer still only called 10 times after a timeout
expect(summarize).toHaveBeenCalledTimes(10);
await new Promise((resolve) => setTimeout(resolve, 1000));
await new Promise<void>((resolve) => setTimeout(resolve, 1000));
expect(summarize).toHaveBeenCalledTimes(10);
});
4 changes: 3 additions & 1 deletion packages/osd-optimizer/src/node/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ export class Cache {
}
} else {
// delay a smidge to allow other things to happen before the next batch of checks
promises.add(new Promise((resolve) => setTimeout(resolve, 1)));
promises.add(
new Promise<void>((resolve) => setTimeout(resolve, 1))
);
}

invalidKeys.length = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-optimizer/src/worker/bundle_refs_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { BundleRefModule } from './bundle_ref_module';
const RESOLVE_EXTENSIONS = ['.js', '.ts', '.tsx'];

function safeStat(path: string): Promise<Fs.Stats | undefined> {
return new Promise((resolve, reject) => {
return new Promise<Fs.Stats | undefined>((resolve, reject) => {
Fs.stat(path, (error, stat) => {
if (error?.code === 'ENOENT') {
resolve(undefined);
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-plugin-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"@types/gulp-zip": "^4.0.1",
"@types/inquirer": "^7.3.1",
"extract-zip": "^2.0.1",
"typescript": "4.0.2"
"typescript": "4.1.6"
}
}
Loading

0 comments on commit 5027633

Please sign in to comment.