From 61c3b169c58bf5b51d86bf2cf01bd8d51d450ffa Mon Sep 17 00:00:00 2001 From: Vitali Zaidman Date: Thu, 10 Oct 2024 13:01:24 +0100 Subject: [PATCH] skip certain tests when installing yarn ignoring the lockfile --- .github/workflows/nightly-tests.yml | 4 +++- .github/workflows/test.yml | 2 ++ package.json | 4 ++++ scripts/jestFilter.js | 22 ++++++++++++++++++++ scripts/setupJestAfterEnv.js | 31 +++++++++++++++++++++++++++++ yarn.lock | 5 +++++ 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 scripts/jestFilter.js create mode 100644 scripts/setupJestAfterEnv.js diff --git a/.github/workflows/nightly-tests.yml b/.github/workflows/nightly-tests.yml index 3843bda357..541c8dde7d 100644 --- a/.github/workflows/nightly-tests.yml +++ b/.github/workflows/nightly-tests.yml @@ -11,6 +11,9 @@ on: schedule: # Daily at at 5:00 UTC - cron: '0 5 * * *' + # @nocommit (this is just used to trigger nightlies on this PR) + pull_request: + types: [opened, synchronize] jobs: test: @@ -26,7 +29,6 @@ jobs: 'current' # newest ] no-lockfile: ['false', 'true'] - name: "Tests [Node.js ${{ matrix.node-version }}, ${{ matrix.runs-on }}, ${{ matrix.no-lockfile == 'false' && 'Using yarn.lock' || 'Ignoring yarn.lock' }}]" uses: ./.github/workflows/test.yml with: node-version: ${{ matrix.node-version }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7da3ddc69b..ac3c3c8cc0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,3 +27,5 @@ jobs: no-lockfile: ${{ inputs.no-lockfile }} - name: Run Jest Tests run: yarn jest --ci --maxWorkers 4 --reporters=default --reporters=jest-junit --rootdir='./' + env: + YARN_INSTALL_NO_LOCKFILE: ${{ inputs.no-lockfile }} diff --git a/package.json b/package.json index 33266f5df6..ee1de31f9c 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "babel-jest": "^29.6.3", "babel-plugin-syntax-hermes-parser": "0.24.0", "babel-plugin-transform-flow-enums": "^0.0.2", + "callsites": "^4.2.0", "chalk": "^4.0.0", "debug": "^2.2.0", "eslint": "^8.57.0", @@ -86,6 +87,9 @@ "setupFiles": [ "/scripts/setupJest.js" ], + "setupFilesAfterEnv": [ + "/scripts/setupJestAfterEnv.js" + ], "watchPlugins": [ "jest-watch-typeahead/filename", "jest-watch-typeahead/testname" diff --git a/scripts/jestFilter.js b/scripts/jestFilter.js new file mode 100644 index 0000000000..99d955227d --- /dev/null +++ b/scripts/jestFilter.js @@ -0,0 +1,22 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @oncall react_native + */ + +const ignoredTests = { + // "path/ending-with/test-name.js": ["test name 1", "test name 2"] +}; + +if (process.env.YARN_INSTALL_NO_LOCKFILE) { + // flaky babel types test - this should be removed once babel is updated + ignoredTests['__tests__/babel-lib-defs-test.js'] = [ + 'Babel Flow library definitions should be up to date', + ]; +} + +module.exports = ignoredTests; diff --git a/scripts/setupJestAfterEnv.js b/scripts/setupJestAfterEnv.js new file mode 100644 index 0000000000..2b4d06fe33 --- /dev/null +++ b/scripts/setupJestAfterEnv.js @@ -0,0 +1,31 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @oncall react_native + */ + +import jestFilter from './jestFilter'; +import callsites from 'callsites'; + +const origTest = test; +global.test = (testName, ...args) => { + const calledFromFile = callsites()[1].getFileName(); + const shouldSkip = Object.entries(jestFilter).some( + ([ignoredFile, ignoredTestNames]) => { + return ( + calledFromFile.endsWith(ignoredFile) && + ignoredTestNames.includes(testName) + ); + }, + ); + return (shouldSkip ? origTest.skip : origTest)(testName, ...args); +}; +Object.keys(origTest).forEach(propName => { + global.test[propName] = origTest[propName]; +}); +global.test; +global.it = test; diff --git a/yarn.lock b/yarn.lock index 3b1d715fe0..efb7b9f408 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2051,6 +2051,11 @@ callsites@^3.0.0: resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ== +callsites@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/callsites/-/callsites-4.2.0.tgz#98761d5be3ce092e4b9c92f7fb8c8eb9b83cadc8" + integrity sha512-kfzR4zzQtAE9PC7CzZsjl3aBNbXWuXiSeOCdLcPpBfGW8YuCqQHcRPFDbr/BPVmd3EEPVpuFzLyuT/cUhPr4OQ== + camelcase@^5.3.1: version "5.3.1" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"