Skip to content

Commit

Permalink
skip certain tests when installing yarn ignoring the lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
vzaidman committed Oct 11, 2024
1 parent a36e992 commit 61c3b16
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/nightly-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -86,6 +87,9 @@
"setupFiles": [
"<rootDir>/scripts/setupJest.js"
],
"setupFilesAfterEnv": [
"<rootDir>/scripts/setupJestAfterEnv.js"
],
"watchPlugins": [
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname"
Expand Down
22 changes: 22 additions & 0 deletions scripts/jestFilter.js
Original file line number Diff line number Diff line change
@@ -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;
31 changes: 31 additions & 0 deletions scripts/setupJestAfterEnv.js
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 61c3b16

Please sign in to comment.