Skip to content

Commit 8da108a

Browse files
author
Tommy Markley
committed
Upgrades jest to v27, simplifies GitHub workflow
* Upgrades `jest` from v26.4.2 to v27.5.1. * [CHANGELOG](https://github.com/facebook/jest/blob/v27.5.1/CHANGELOG.md) * v27 introduced breaking changes that had to be addressed. * Removes caching from GitHub test workflow to simplify. * Removes "bad apples" check from GitHub workflow. * Runs unit tests in band to reduce execution time from ~90 minutes to ~11 minutes. * Adds ci-specific scripts to eliminate duplication of commands. * `yarn test:jest:ci` and `yarn test:jest_integration:ci` are now used in the workflow. * Upgrades testing-related dependencies, removes unused dependency `babel-plugin-istanbul`, and replaces `jest-environment-jsdom-thirteen` with the built-in `jest-environment-jsdom`. * Skips a few flaky tests that need require additional investigation. Resolves #1231 Signed-off-by: Tommy Markley <[email protected]>
1 parent 7cb8297 commit 8da108a

File tree

62 files changed

+1954
-2599
lines changed

Some content is hidden

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

62 files changed

+1954
-2599
lines changed

.eslintrc.js

-10
Original file line numberDiff line numberDiff line change
@@ -536,16 +536,6 @@ module.exports = {
536536
},
537537
},
538538

539-
/**
540-
* Jest specific rules
541-
*/
542-
{
543-
files: ['**/*.test.{js,mjs,ts,tsx}'],
544-
rules: {
545-
'jest/valid-describe': 'error',
546-
},
547-
},
548-
549539
/**
550540
* Harden specific rules
551541
*/

.github/workflows/pr_check_workflow.yml

+4-113
Original file line numberDiff line numberDiff line change
@@ -26,108 +26,36 @@ jobs:
2626
runs-on: ubuntu-latest
2727
name: Build and Verify
2828
steps:
29-
# Access a cache of set results from a previous run of the job
30-
# This is to prevent re-running steps that were already successful since it is not native to github actions
31-
# Can be used to verify flaky steps with reduced times
32-
- name: Restore the cached run
33-
uses: actions/cache@v2
34-
with:
35-
path: |
36-
job_successful
37-
linter_results
38-
unit_tests_results
39-
integration_tests_results
40-
key: ${{ github.run_id }}-${{ github.job }}-${{ github.sha }}
41-
restore-keys: |
42-
${{ github.run_id }}-${{ github.job }}-${{ github.sha }}
43-
44-
- name: Get if previous job was successful
45-
id: job_successful
46-
run: cat job_successful 2>/dev/null || echo 'false'
47-
48-
- name: Get the previous linter results
49-
id: linter_results
50-
run: cat linter_results 2>/dev/null || echo 'default'
51-
52-
- name: Get the previous unit tests results
53-
id: unit_tests_results
54-
run: cat unit_tests_results 2>/dev/null || echo 'default'
55-
56-
- name: Get the previous integration tests results
57-
id: integration_tests_results
58-
run: cat integration_tests_results 2>/dev/null || echo 'default'
5929

6030
- name: Checkout code
61-
if: steps.job_successful.outputs.job_successful != 'true'
6231
uses: actions/checkout@v2
6332

6433
- name: Setup Node
65-
if: steps.job_successful.outputs.job_successful != 'true'
6634
uses: actions/setup-node@v2
6735
with:
6836
node-version-file: ".nvmrc"
6937
registry-url: 'https://registry.npmjs.org'
7038

7139
- name: Setup Yarn
72-
if: steps.job_successful.outputs.job_successful != 'true'
7340
run: |
7441
npm uninstall -g yarn
7542
7643
7744
- name: Run bootstrap
78-
if: steps.job_successful.outputs.job_successful != 'true'
7945
run: yarn osd bootstrap
8046

8147
- name: Run linter
82-
if: steps.linter_results.outputs.linter_results != 'success'
8348
id: linter
8449
run: yarn lint
8550

86-
# Runs unit tests while limiting workers because github actions will spawn more than it can handle and crash
87-
# Continues on error but will create a comment on the pull request if this step failed.
8851
- name: Run unit tests
89-
if: steps.unit_tests_results.outputs.unit_tests_results != 'success'
9052
id: unit-tests
91-
continue-on-error: true
92-
run: node scripts/jest --ci --colors --maxWorkers=10
93-
env:
94-
SKIP_BAD_APPLES: true
95-
96-
- run: echo Unit tests completed unsuccessfully. However, unit tests are inconsistent on the CI so please verify locally with `yarn test:jest`.
97-
if: steps.unit_tests_results.outputs.unit_tests_results != 'success' && steps.unit-tests.outcome != 'success'
98-
99-
# TODO: This gets rejected, we need approval to add this
100-
# - name: Add comment if unit tests did not succeed
101-
# if: steps.unit_tests_results.outputs.unit_tests_results != 'success' && steps.unit-tests.outcome != 'success'
102-
# uses: actions/github-script@v5
103-
# with:
104-
# github-token: ${{ secrets.GITHUB_TOKEN }}
105-
# script: |
106-
# github.rest.issues.createComment({
107-
# issue_number: context.issue.number,
108-
# owner: context.repo.owner,
109-
# repo: context.repo.repo,
110-
# body: 'Unit tests completed unsuccessfully. However, unit tests are inconsistent on the CI so please verify locally with `yarn test:jest`.'
111-
# })
53+
run: yarn test:jest:ci
11254

11355
- name: Run integration tests
114-
if: steps.integration_tests_results.outputs.integration_tests_results != 'success'
11556
id: integration-tests
116-
run: node scripts/jest_integration --ci --colors --max-old-space-size=5120
117-
118-
# Set cache if linter, unit tests, and integration tests were successful then the job will be marked successful
119-
# Sets individual results to empower re-runs of the same build without re-running successful steps.
120-
- if: |
121-
(steps.linter.outcome == 'success' || steps.linter.outcome == 'skipped') &&
122-
(steps.unit-tests.outcome == 'success' || steps.unit-tests.outcome == 'skipped') &&
123-
(steps.integration-tests.outcome == 'success' || steps.integration-tests.outcome == 'skipped')
124-
run: echo "::set-output name=job_successful::true" > job_successful
125-
- if: steps.linter.outcome == 'success' || steps.linter.outcome == 'skipped'
126-
run: echo "::set-output name=linter_results::success" > linter_results
127-
- if: steps.unit-tests.outcome == 'success' || steps.unit-tests.outcome == 'skipped'
128-
run: echo "::set-output name=unit_tests_results::success" > unit_tests_results
129-
- if: steps.integration-tests.outcome == 'success' || steps.integration-tests.outcome == 'skipped'
130-
run: echo "::set-output name=integration_tests_results::success" > integration_tests_results
57+
run: yarn test:jest_integration:ci
58+
13159
functional-tests:
13260
needs: [ build-lint-test ]
13361
runs-on: ubuntu-latest
@@ -138,76 +66,39 @@ jobs:
13866
steps:
13967
- run: echo Running functional tests for ciGroup${{ matrix.group }}
14068

141-
# Access a cache of set results from a previous run of the job
142-
# This is to prevent re-running a CI group that was already successful since it is not native to github actions
143-
# Can be used to verify flaky steps with reduced times
144-
- name: Restore the cached run
145-
uses: actions/cache@v2
146-
with:
147-
path: |
148-
ftr_tests_results
149-
key: ${{ github.run_id }}-${{ github.job }}-${{ matrix.group }}-${{ github.sha }}
150-
restore-keys: |
151-
${{ github.run_id }}-${{ github.job }}-${{ matrix.group }}-${{ github.sha }}
152-
15369
- name: Get the cached tests results
15470
id: ftr_tests_results
15571
run: cat ftr_tests_results 2>/dev/null || echo 'default'
15672

15773
- name: Checkout code
158-
if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success'
15974
uses: actions/checkout@v2
16075

16176
- name: Setup Node
162-
if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success'
16377
uses: actions/setup-node@v2
16478
with:
16579
node-version-file: ".nvmrc"
16680
registry-url: 'https://registry.npmjs.org'
16781

16882
- name: Setup Yarn
169-
if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success'
17083
run: |
17184
npm uninstall -g yarn
17285
17386
174-
- name: Get cache path
175-
if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success'
176-
id: cache-path
177-
run: echo "::set-output name=CACHE_DIR::$(yarn cache dir)"
178-
179-
- name: Setup cache
180-
if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success'
181-
uses: actions/cache@v2
182-
with:
183-
path: ${{ steps.cache-path.outputs.CACHE_DIR }}
184-
key: ${{ runner.os }}-yarn-${{ env.CACHE_NAME }}-${{ hashFiles('**/yarn.lock') }}
185-
restore-keys: |
186-
${{ runner.os }}-yarn-${{ env.CACHE_NAME }}-
187-
${{ runner.os }}-yarn-
188-
${{ runner.os }}-
189-
19087
# github virtual env is the latest chrome
19188
- name: Setup chromedriver
192-
if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success'
19389
run: yarn add --dev [email protected]
19490

19591
- name: Run bootstrap
196-
if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success'
19792
run: yarn osd bootstrap
19893

19994
- name: Build plugins
200-
if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success'
20195
run: node scripts/build_opensearch_dashboards_platform_plugins --no-examples --workers 10
20296

203-
- if: steps.ftr_tests_results.outputs.ftr_tests_results != 'success'
97+
- name: Run CI test group ${{ matrix.group }}
20498
id: ftr-tests
20599
run: node scripts/functional_tests.js --config test/functional/config.js --include ciGroup${{ matrix.group }}
206100
env:
207101
CI_GROUP: ciGroup${{ matrix.group }}
208102
CI_PARALLEL_PROCESS_NUMBER: ciGroup${{ matrix.group }}
209103
JOB: ci${{ matrix.group }}
210104
CACHE_DIR: ciGroup${{ matrix.group }}
211-
212-
- if: steps.ftr-tests.outcome == 'success' || steps.ftr-tests.outcome == 'skipped'
213-
run: echo "::set-output name=ftr_tests_results::success" > ftr_tests_results

package.json

+20-21
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
"test": "grunt test",
4444
"test:bwc": "./scripts/bwctest-osd.sh",
4545
"test:jest": "node scripts/jest",
46+
"test:jest:ci": "node scripts/jest --ci --colors --runInBand",
4647
"test:jest_integration": "node scripts/jest_integration",
48+
"test:jest_integration:ci": "node scripts/jest_integration --ci --colors --max-old-space-size=5120",
4749
"test:mocha": "node scripts/mocha",
4850
"test:mocha:coverage": "grunt test:mochaCoverage",
4951
"test:ftr": "node scripts/functional_tests",
@@ -135,7 +137,7 @@
135137
"@types/yauzl": "^2.9.1",
136138
"JSONStream": "1.3.5",
137139
"abortcontroller-polyfill": "^1.4.0",
138-
"angular": "^1.8.0",
140+
"angular": "^1.8.2",
139141
"angular-elastic": "^2.5.1",
140142
"angular-sanitize": "^1.8.0",
141143
"bluebird": "3.5.5",
@@ -233,12 +235,12 @@
233235
"@osd/utility-types": "1.0.0",
234236
"@percy/cli": "^1.0.0-beta.74",
235237
"@percy/sdk-utils": "^1.0.0-beta.74",
236-
"@testing-library/dom": "^7.24.2",
237-
"@testing-library/jest-dom": "^5.11.4",
238-
"@testing-library/react": "^11.0.4",
239-
"@testing-library/react-hooks": "^3.4.1",
240-
"@types/angular": "^1.6.56",
241-
"@types/angular-mocks": "^1.7.0",
238+
"@testing-library/dom": "^8.11.3",
239+
"@testing-library/jest-dom": "^5.16.2",
240+
"@testing-library/react": "^12.1.2",
241+
"@testing-library/react-hooks": "^7.0.2",
242+
"@types/angular": "^1.8.4",
243+
"@types/angular-mocks": "^1.7.1",
242244
"@types/archiver": "^3.1.0",
243245
"@types/babel__core": "^7.1.17",
244246
"@types/bluebird": "^3.1.1",
@@ -267,7 +269,7 @@
267269
"@types/has-ansi": "^3.0.0",
268270
"@types/history": "^4.7.3",
269271
"@types/hjson": "^2.4.2",
270-
"@types/jest": "^26.0.14",
272+
"@types/jest": "^27.4.0",
271273
"@types/joi": "^13.4.2",
272274
"@types/jquery": "^3.3.31",
273275
"@types/js-yaml": "^3.11.1",
@@ -304,12 +306,11 @@
304306
"@types/sinon": "^7.0.13",
305307
"@types/strip-ansi": "^5.2.1",
306308
"@types/styled-components": "^5.1.19",
307-
"@types/supertest": "^2.0.5",
309+
"@types/supertest": "^2.0.11",
308310
"@types/supertest-as-promised": "^2.0.38",
309311
"@types/tapable": "^1.0.6",
310312
"@types/tar": "^4.0.3",
311-
"@types/testing-library__jest-dom": "^5.9.3",
312-
"@types/testing-library__react-hooks": "^3.4.0",
313+
"@types/testing-library__jest-dom": "^5.14.2",
313314
"@types/tough-cookie": "^4.0.1",
314315
"@types/type-detect": "^4.0.1",
315316
"@types/uuid": "^3.4.4",
@@ -321,15 +322,14 @@
321322
"@typescript-eslint/eslint-plugin": "^3.10.0",
322323
"@typescript-eslint/parser": "^3.10.0",
323324
"angular-aria": "^1.8.0",
324-
"angular-mocks": "^1.7.9",
325+
"angular-mocks": "^1.8.2",
325326
"angular-recursion": "^1.0.5",
326327
"angular-route": "^1.8.0",
327328
"angular-sortable-view": "^0.0.17",
328329
"archiver": "^3.1.1",
329330
"axe-core": "^4.0.2",
330331
"babel-eslint": "^10.0.3",
331-
"babel-jest": "^26.3.0",
332-
"babel-plugin-istanbul": "^6.0.0",
332+
"babel-jest": "^27.5.1",
333333
"brace": "0.11.1",
334334
"chai": "3.5.0",
335335
"chance": "1.0.18",
@@ -350,8 +350,8 @@
350350
"eslint-plugin-ban": "^1.4.0",
351351
"eslint-plugin-cypress": "^2.8.1",
352352
"eslint-plugin-eslint-comments": "^3.2.0",
353-
"eslint-plugin-import": "^2.19.1",
354-
"eslint-plugin-jest": "^24.0.2",
353+
"eslint-plugin-import": "^2.25.4",
354+
"eslint-plugin-jest": "^26.1.1",
355355
"eslint-plugin-jsx-a11y": "^6.2.3",
356356
"eslint-plugin-mocha": "^6.2.2",
357357
"eslint-plugin-no-unsanitized": "^3.0.2",
@@ -378,9 +378,8 @@
378378
"history": "^4.9.0",
379379
"immer": "^9.0.6",
380380
"intl-messageformat-parser": "^1.4.0",
381-
"jest": "^26.4.2",
382-
"jest-canvas-mock": "^2.2.0",
383-
"jest-environment-jsdom-thirteen": "^1.0.1",
381+
"jest": "^27.5.1",
382+
"jest-canvas-mock": "^2.3.1",
384383
"jest-raw-loader": "^1.0.1",
385384
"jimp": "^0.14.0",
386385
"jquery": "^3.5.0",
@@ -406,7 +405,7 @@
406405
"ngreact": "^0.5.1",
407406
"nock": "12.0.3",
408407
"normalize-path": "^3.0.0",
409-
"nyc": "^14.1.1",
408+
"nyc": "^15.1.0",
410409
"pixelmatch": "^5.1.0",
411410
"pngjs": "^3.4.0",
412411
"postcss": "^8.4.5",
@@ -431,7 +430,7 @@
431430
"simple-git": "1.116.0",
432431
"sinon": "^7.4.2",
433432
"strip-ansi": "^6.0.0",
434-
"supertest": "^3.1.0",
433+
"supertest": "^6.2.2",
435434
"supertest-as-promised": "^4.0.2",
436435
"tape": "^5.0.1",
437436
"topojson-client": "3.0.0",

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"eslint-plugin-ban": "^1.4.0",
2727
"eslint-plugin-jsx-a11y": "^6.2.3",
2828
"eslint-plugin-eslint-comments": "^3.2.0",
29-
"eslint-plugin-import": "^2.19.1",
30-
"eslint-plugin-jest": "^24.0.2",
29+
"eslint-plugin-import": "^2.25.4",
30+
"eslint-plugin-jest": "^26.1.1",
3131
"eslint-plugin-mocha": "^6.2.2",
3232
"eslint-plugin-no-unsanitized": "^3.0.2",
3333
"eslint-plugin-prefer-object-spread": "^1.2.1",

packages/osd-optimizer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"del": "^5.1.0",
2828
"execa": "^4.0.2",
2929
"file-loader": "^4.2.0",
30-
"jest-diff": "^26.4.2",
30+
"jest-diff": "^27.5.1",
3131
"js-yaml": "^3.14.0",
3232
"json-stable-stringify": "^1.0.1",
3333
"lmdb-store": "^1.6.11",

packages/osd-optimizer/src/optimizer/cache_keys.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import Path from 'path';
3434

35-
import jestDiff from 'jest-diff';
35+
import { diff } from 'jest-diff';
3636
import { REPO_ROOT } from '@osd/utils';
3737
import { createAbsolutePathSerializer } from '@osd/dev-utils';
3838

@@ -187,7 +187,7 @@ describe('diffCacheKey()', () => {
187187

188188
describe('reformatJestDiff()', () => {
189189
it('reformats large jestDiff output to focus on the changed lines', () => {
190-
const diff = jestDiff(
190+
const jestDiff = diff(
191191
{
192192
a: ['1', '1', '1', '1', '1', '1', '1', '2', '1', '1', '1', '1', '1', '1', '1', '1', '1'],
193193
},
@@ -196,7 +196,7 @@ describe('reformatJestDiff()', () => {
196196
}
197197
);
198198

199-
expect(reformatJestDiff(diff)).toMatchInlineSnapshot(`
199+
expect(reformatJestDiff(jestDiff)).toMatchInlineSnapshot(`
200200
"- Expected
201201
+ Received
202202

packages/osd-optimizer/src/optimizer/cache_keys.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import execa from 'execa';
3939
import { REPO_ROOT } from '@osd/utils';
4040
import stripAnsi from 'strip-ansi';
4141

42-
import jestDiff from 'jest-diff';
42+
import { diff } from 'jest-diff';
4343
import jsonStable from 'json-stable-stringify';
4444
import { ascending, CacheableWorkerConfig } from '../common';
4545

@@ -62,11 +62,11 @@ export function diffCacheKey(expected?: unknown, actual?: unknown) {
6262
return;
6363
}
6464

65-
return reformatJestDiff(jestDiff(expectedJson, actualJson));
65+
return reformatJestDiff(diff(expectedJson, actualJson));
6666
}
6767

68-
export function reformatJestDiff(diff: string | null) {
69-
const diffLines = diff?.split('\n') || [];
68+
export function reformatJestDiff(jestDiff: string | null) {
69+
const diffLines = jestDiff?.split('\n') || [];
7070

7171
if (
7272
diffLines.length < 4 ||

0 commit comments

Comments
 (0)