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 f343905
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/nightly-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
schedule:
# Daily at at 5:00 UTC
- cron: '0 5 * * *'
pull_request:
types: [opened, synchronize]

jobs:
test:
Expand All @@ -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 }}
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 }}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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.getOwnPropertyNames(origTest).forEach(propName => {
global.test[propName] = origTest[propName];
});
global.test;
global.it = test;

0 comments on commit f343905

Please sign in to comment.