From f343905e789a6841784b76f836586a85f566e3a2 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 | 3 ++- .github/workflows/test.yml | 2 ++ package.json | 3 +++ scripts/jestFilter.js | 22 ++++++++++++++++++++ scripts/setupJestAfterEnv.js | 31 +++++++++++++++++++++++++++++ 5 files changed, 60 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..988339368c 100644 --- a/.github/workflows/nightly-tests.yml +++ b/.github/workflows/nightly-tests.yml @@ -11,6 +11,8 @@ on: schedule: # Daily at at 5:00 UTC - cron: '0 5 * * *' + pull_request: + types: [opened, synchronize] jobs: test: @@ -26,7 +28,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..bab9155c99 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,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..f140c6f99b --- /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.getOwnPropertyNames(origTest).forEach(propName => { + global.test[propName] = origTest[propName]; +}); +global.test; +global.it = test;