Skip to content

Commit 3b5c51a

Browse files
author
Tommy Markley
committed
Upgrades TypeScript to 4.1, simplifies jest config
* 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 #1081 Signed-off-by: Tommy Markley <[email protected]>
1 parent 082f44a commit 3b5c51a

File tree

376 files changed

+1672
-1434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

376 files changed

+1672
-1434
lines changed

examples/bfetch_explorer/server/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class BfetchExplorerPlugin implements Plugin {
6767
// Validate inputs.
6868
if (num < 0) throw new Error('Invalid number');
6969
// Wait number of specified milliseconds.
70-
await new Promise((r) => setTimeout(r, num));
70+
await new Promise<void>((r) => setTimeout(r, num));
7171
// Double the number and send it back.
7272
return { num: 2 * num };
7373
},

examples/embeddable_examples/public/book/edit_book_action.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const createEditBookAction = (getStartServices: () => Promise<StartServic
8181
return savedObjectsClient.create(BOOK_EMBEDDABLE, attributes);
8282
},
8383
checkForDuplicateTitle: (props: OnSaveProps) => {
84-
return new Promise(() => {
84+
return new Promise<true>(() => {
8585
return true;
8686
});
8787
},

examples/state_containers_examples/public/todo/todo.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export const TodoAppPage: React.FC<{
326326

327327
function withDefaultState<State extends BaseState>(
328328
stateContainer: BaseStateContainer<State>,
329-
// eslint-disable-next-line no-shadow
329+
// eslint-disable-next-line @typescript-eslint/no-shadow
330330
defaultState: State
331331
): INullableBaseStateContainer<State> {
332332
return {

examples/state_containers_examples/public/with_data_services/components/app.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ function useGlobalStateSyncing(
193193
}, [query, osdUrlStateStorage]);
194194
}
195195

196+
// eslint-disable-next-line @typescript-eslint/no-shadow
196197
function useAppStateSyncing<AppState extends QueryState>(
197198
appStateContainer: BaseStateContainer<AppState>,
198199
query: DataPublicPluginStart['query'],

package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"**/minimist": "^1.2.5",
8383
"**/node-jose": "^2.1.0",
8484
"**/trim": "^0.0.3",
85-
"**/typescript": "4.0.2"
85+
"**/typescript": "4.1.6"
8686
},
8787
"workspaces": {
8888
"packages": [
@@ -243,7 +243,7 @@
243243
"@types/babel__core": "^7.1.17",
244244
"@types/bluebird": "^3.1.1",
245245
"@types/chance": "^1.0.0",
246-
"@types/cheerio": "^0.22.10",
246+
"@types/cheerio": "^0.22.30",
247247
"@types/chromedriver": "^81.0.0",
248248
"@types/classnames": "^2.2.9",
249249
"@types/color": "^3.0.0",
@@ -252,7 +252,7 @@
252252
"@types/deep-freeze-strict": "^1.1.0",
253253
"@types/delete-empty": "^2.0.0",
254254
"@types/elasticsearch": "^5.0.33",
255-
"@types/enzyme": "^3.10.5",
255+
"@types/enzyme": "^3.10.11",
256256
"@types/eslint": "^6.1.3",
257257
"@types/fetch-mock": "^7.3.1",
258258
"@types/flot": "^0.0.31",
@@ -317,8 +317,8 @@
317317
"@types/webpack": "^4.41.31",
318318
"@types/webpack-env": "^1.16.3",
319319
"@types/zen-observable": "^0.8.0",
320-
"@typescript-eslint/eslint-plugin": "^3.10.0",
321-
"@typescript-eslint/parser": "^3.10.0",
320+
"@typescript-eslint/eslint-plugin": "^5.10.0",
321+
"@typescript-eslint/parser": "^5.10.0",
322322
"angular-aria": "^1.8.0",
323323
"angular-mocks": "^1.8.2",
324324
"angular-recursion": "^1.0.5",
@@ -331,7 +331,7 @@
331331
"brace": "0.11.1",
332332
"chai": "3.5.0",
333333
"chance": "1.0.18",
334-
"cheerio": "0.22.0",
334+
"cheerio": "^1.0.0-rc.10",
335335
"chromedriver": "^91.0.1",
336336
"classnames": "2.2.6",
337337
"compare-versions": "3.5.1",
@@ -340,8 +340,8 @@
340340
"dedent": "^0.7.0",
341341
"delete-empty": "^2.0.0",
342342
"enzyme": "^3.11.0",
343-
"enzyme-adapter-react-16": "^1.15.2",
344-
"enzyme-to-json": "^3.4.4",
343+
"enzyme-adapter-react-16": "^1.15.6",
344+
"enzyme-to-json": "^3.6.2",
345345
"eslint": "^6.8.0",
346346
"eslint-config-prettier": "^6.11.0",
347347
"eslint-plugin-babel": "^5.3.1",
@@ -357,7 +357,7 @@
357357
"eslint-plugin-prefer-object-spread": "^1.2.1",
358358
"eslint-plugin-prettier": "^3.1.4",
359359
"eslint-plugin-react": "^7.20.3",
360-
"eslint-plugin-react-hooks": "^4.0.4",
360+
"eslint-plugin-react-hooks": "^4.2.0",
361361
"eslint-plugin-react-perf": "^3.2.3",
362362
"exit-hook": "^2.2.0",
363363
"fetch-mock": "^7.3.9",
@@ -434,7 +434,7 @@
434434
"topojson-client": "3.0.0",
435435
"tough-cookie": "^4.0.0",
436436
"tree-kill": "^1.2.2",
437-
"typescript": "4.0.2",
437+
"typescript": "4.1.6",
438438
"ui-select": "0.19.8",
439439
"vega": "^5.17.3",
440440
"vega-lite": "^4.16.8",

packages/opensearch-eslint-config-opensearch-dashboards/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
},
1919
"homepage": "https://github.com/opensearch-project/OpenSearch-Dashboards/tree/main/packages/opensearch-eslint-config-opensearch-dashboards",
2020
"peerDependencies": {
21-
"@typescript-eslint/eslint-plugin": "^3.10.0",
22-
"@typescript-eslint/parser": "^3.10.0",
21+
"@typescript-eslint/eslint-plugin": "^5.10.0",
22+
"@typescript-eslint/parser": "^5.10.0",
2323
"babel-eslint": "^10.0.3",
2424
"eslint": "^6.8.0",
2525
"eslint-plugin-babel": "^5.3.1",
@@ -32,6 +32,6 @@
3232
"eslint-plugin-no-unsanitized": "^3.0.2",
3333
"eslint-plugin-prefer-object-spread": "^1.2.1",
3434
"eslint-plugin-react": "^7.17.0",
35-
"eslint-plugin-react-hooks": "^4.0.4"
35+
"eslint-plugin-react-hooks": "^4.2.0"
3636
}
3737
}

packages/opensearch-eslint-config-opensearch-dashboards/typescript.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ module.exports = {
224224
'@typescript-eslint/no-extra-non-null-assertion': 'error',
225225
'@typescript-eslint/no-misused-new': 'error',
226226
'@typescript-eslint/no-namespace': 'error',
227+
'@typescript-eslint/no-shadow': 'error',
228+
'@typescript-eslint/no-undef': 'off',
227229
'@typescript-eslint/triple-slash-reference': [
228230
'error',
229231
{
@@ -255,7 +257,6 @@ module.exports = {
255257
'no-eval': 'error',
256258
'no-new-wrappers': 'error',
257259
'no-script-url': 'error',
258-
'no-shadow': 'error',
259260
'no-throw-literal': 'error',
260261
'no-undef-init': 'error',
261262
'no-unsafe-finally': 'error',

packages/osd-ace/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@osd/dev-utils": "1.0.0",
1616
"@osd/babel-preset": "1.0.0",
1717
"raw-loader": "^4.0.2",
18-
"typescript": "4.0.2",
18+
"typescript": "4.1.6",
1919
"webpack": "^4.41.5"
2020
}
2121
}

packages/osd-analytics/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"@babel/cli": "^7.16.0",
1818
"@osd/dev-utils": "1.0.0",
1919
"@osd/babel-preset": "1.0.0",
20-
"typescript": "4.0.2"
20+
"typescript": "4.1.6"
2121
}
2222
}

packages/osd-apm-config-loader/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"lodash": "^4.17.21"
1818
},
1919
"devDependencies": {
20-
"typescript": "4.0.2",
20+
"typescript": "4.1.6",
2121
"tsd": "^0.16.0"
2222
}
2323
}

packages/osd-config-schema/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"osd:bootstrap": "yarn build"
1111
},
1212
"devDependencies": {
13-
"typescript": "4.0.2",
13+
"typescript": "4.1.6",
1414
"tsd": "^0.16.0"
1515
},
1616
"peerDependencies": {

packages/osd-config/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"devDependencies": {
2525
"@osd/dev-utils": "1.0.0",
2626
"@osd/utility-types": "1.0.0",
27-
"typescript": "4.0.2",
27+
"typescript": "4.1.6",
2828
"tsd": "^0.16.0"
2929
}
3030
}

packages/osd-dev-utils/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"@osd/utils": "1.0.0",
1818
"axios": "^0.21.4",
1919
"chalk": "^4.1.0",
20-
"cheerio": "0.22.0",
2120
"dedent": "^0.7.0",
2221
"execa": "^4.0.2",
2322
"exit-hook": "^2.2.0",
@@ -37,6 +36,7 @@
3736
"@osd/expect": "1.0.0",
3837
"@types/vinyl": "^2.0.4",
3938
"chance": "1.0.18",
40-
"typescript": "4.0.2"
39+
"cheerio": "^1.0.0-rc.10",
40+
"typescript": "4.1.6"
4141
}
4242
}

packages/osd-dev-utils/src/ci_stats_reporter/ci_stats_reporter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class CiStatsReporter {
174174
`failed to reach opensearch-dashboards-ci-stats service [reason=${reason}], retrying in ${attempt} seconds`
175175
);
176176

177-
await new Promise((resolve) => setTimeout(resolve, attempt * 1000));
177+
await new Promise<void>((resolve) => setTimeout(resolve, attempt * 1000));
178178
}
179179
}
180180
}

packages/osd-dev-utils/src/osd_client/osd_client_requester.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export interface ReqOptions {
7878
}
7979

8080
const delay = (ms: number) =>
81-
new Promise((resolve) => {
81+
new Promise<void>((resolve) => {
8282
setTimeout(resolve, ms);
8383
});
8484

packages/osd-dev-utils/src/proc_runner/proc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function withTimeout(
6565
try {
6666
await Promise.race([
6767
attempt(),
68-
new Promise((_, reject) => setTimeout(() => reject(TIMEOUT), ms)),
68+
new Promise<void>((_, reject) => setTimeout(() => reject(TIMEOUT), ms)),
6969
]);
7070
} catch (error) {
7171
if (error === TIMEOUT) {

packages/osd-dev-utils/src/proc_runner/proc_runner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class ProcRunner {
150150
// processes and stopping, but consumers of run() shouldn't have to
151151
// prepare for that, so just return a never-resolving promise
152152
if (this.closing) {
153-
await new Promise(noop);
153+
await new Promise<void>(noop);
154154
}
155155
}
156156
}

packages/osd-dev-utils/src/proc_runner/with_proc_runner.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ it('waits for promise to resolve before tearing down proc', async () => {
6767
let teardownSpy;
6868

6969
await withProcRunner(new ToolingLog(), async (proc) => {
70-
await new Promise((resolve) => setTimeout(resolve, 500));
70+
await new Promise<void>((resolve) => setTimeout(resolve, 500));
7171
teardownSpy = jest.spyOn(proc, 'teardown');
7272
});
7373

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

8282
await expect(
8383
withProcRunner(new ToolingLog(), async (proc) => {
84-
await new Promise((resolve) => setTimeout(resolve, 500));
84+
await new Promise<void>((resolve) => setTimeout(resolve, 500));
8585
teardownSpy = jest.spyOn(proc, 'teardown');
8686
throw error;
8787
})

packages/osd-dev-utils/src/run/run_with_commands.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ beforeEach(() => {
6060
});
6161

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

packages/osd-eslint-import-resolver-opensearch-dashboards/lib/get_webpack_config.js

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ exports.getWebpackConfig = function (opensearchDashboardsPath) {
4242
alias: {
4343
// Dev defaults for test bundle https://github.com/opensearch-project/OpenSearch-Dashboards/blob/6998f074542e8c7b32955db159d15661aca253d7/src/core_plugins/tests_bundle/index.js#L73-L78
4444
fixtures: resolve(opensearchDashboardsPath, 'src/fixtures'),
45-
test_utils: resolve(opensearchDashboardsPath, 'src/test_utils/public'),
4645
},
4746
unsafeCache: true,
4847
},

packages/osd-i18n/GUIDELINE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ Testing React component that uses the `injectI18n` higher-order component is mor
391391

392392
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()`.
393393

394-
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`.
394+
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`.
395395

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

packages/osd-i18n/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"del": "^5.1.0",
2222
"getopts": "^2.2.5",
2323
"supports-color": "^7.0.0",
24-
"typescript": "4.0.2"
24+
"typescript": "4.1.6"
2525
},
2626
"dependencies": {
2727
"intl-format-cache": "^2.1.0",

packages/osd-i18n/src/react/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
*/
3232

3333
import { InjectedIntl as _InjectedIntl, InjectedIntlProps as _InjectedIntlProps } from 'react-intl';
34-
35-
export type InjectedIntl = _InjectedIntl;
36-
export type InjectedIntlProps = _InjectedIntlProps;
34+
export type { InjectedIntl, InjectedIntlProps } from 'react-intl';
3735

3836
export {
3937
intlShape,

packages/osd-logging/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"@osd/std": "1.0.0"
1414
},
1515
"devDependencies": {
16-
"typescript": "4.0.2"
16+
"typescript": "4.1.6"
1717
}
1818
}

packages/osd-monaco/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"del": "^5.1.0",
2121
"raw-loader": "^4.0.2",
2222
"supports-color": "^7.0.0",
23-
"typescript": "4.0.2",
23+
"typescript": "4.1.6",
2424
"webpack": "^4.41.5",
2525
"webpack-cli": "^4.9.2"
2626
}

packages/osd-opensearch-archiver/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@osd/dev-utils": "1.0.0",
15+
"@osd/test": "1.0.0",
1516
"elasticsearch": "^16.7.0"
1617
},
1718
"devDependencies": {

packages/osd-opensearch-archiver/src/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export function runCli() {
241241
output: process.stdout,
242242
});
243243

244-
await new Promise((resolveInput) => {
244+
await new Promise<void>((resolveInput) => {
245245
rl.question(`Press enter when you're done`, () => {
246246
rl.close();
247247
resolveInput();

packages/osd-opensearch-archiver/src/lib/archives/__tests__/parse.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('opensearchArchiver createParseArchiveStreams', () => {
8282

8383
it('provides each JSON object as soon as it is parsed', async () => {
8484
let onReceived: (resolved: any) => void;
85-
const receivedPromise = new Promise((resolve) => (onReceived = resolve));
85+
const receivedPromise = new Promise<void>((resolve) => (onReceived = resolve));
8686
const input = new PassThrough();
8787
const check = new Transform({
8888
writableObjectMode: true,

packages/osd-opensearch-archiver/src/lib/indices/delete_index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export async function waitForSnapshotCompletion(client: Client, index: string, l
122122

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

128128
return;

packages/osd-optimizer/src/common/event_stream_helpers.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,6 @@ it('stops an infinite stream when unsubscribed', async () => {
247247

248248
// ensure summarizer still only called 10 times after a timeout
249249
expect(summarize).toHaveBeenCalledTimes(10);
250-
await new Promise((resolve) => setTimeout(resolve, 1000));
250+
await new Promise<void>((resolve) => setTimeout(resolve, 1000));
251251
expect(summarize).toHaveBeenCalledTimes(10);
252252
});

packages/osd-optimizer/src/node/cache.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ export class Cache {
216216
}
217217
} else {
218218
// delay a smidge to allow other things to happen before the next batch of checks
219-
promises.add(new Promise((resolve) => setTimeout(resolve, 1)));
219+
promises.add(
220+
new Promise<void>((resolve) => setTimeout(resolve, 1))
221+
);
220222
}
221223

222224
invalidKeys.length = 0;

packages/osd-optimizer/src/worker/bundle_refs_plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { BundleRefModule } from './bundle_ref_module';
1919
const RESOLVE_EXTENSIONS = ['.js', '.ts', '.tsx'];
2020

2121
function safeStat(path: string): Promise<Fs.Stats | undefined> {
22-
return new Promise((resolve, reject) => {
22+
return new Promise<Fs.Stats | undefined>((resolve, reject) => {
2323
Fs.stat(path, (error, stat) => {
2424
if (error?.code === 'ENOENT') {
2525
resolve(undefined);

packages/osd-plugin-helpers/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
"@types/gulp-zip": "^4.0.1",
3131
"@types/inquirer": "^7.3.1",
3232
"extract-zip": "^2.0.1",
33-
"typescript": "4.0.2"
33+
"typescript": "4.1.6"
3434
}
3535
}

0 commit comments

Comments
 (0)