mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53205 Changelog: [internal] This injects a custom Babel transform for Fantom tests that automatically injects `debugger` statements in the generated code. This simplifies debugging by providing a default interruption point in the test setup for the test author to decide what to debug. This has no effect unless the debugger is opened, which isn't happening yet. Reviewed By: rshest Differential Revision: D79996000 fbshipit-source-id: 6153587264d293a067e359edba4f64f41898c506
36 lines
1013 B
JavaScript
36 lines
1013 B
JavaScript
/**
|
|
* 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.
|
|
*
|
|
* @noflow
|
|
* @format
|
|
*/
|
|
|
|
/**
|
|
* This transform injects a single `debugger;` statement at the top of every
|
|
* Fantom test, so we can automatically stop on them when debugging.
|
|
*/
|
|
module.exports = function ({types: t}) {
|
|
return {
|
|
name: 'inject-debugger-statements-in-tests',
|
|
visitor: {
|
|
Program(path, state) {
|
|
const filename = state.filename || '';
|
|
if (
|
|
(filename.endsWith('-itest.js') ||
|
|
filename.endsWith('-itest.fb.js')) &&
|
|
!filename.includes('/.out/')
|
|
) {
|
|
// Check if the first statement is already a debugger statement
|
|
const first = path.node.body[0];
|
|
if (!first || first.type !== 'DebuggerStatement') {
|
|
path.unshiftContainer('body', t.debuggerStatement());
|
|
}
|
|
}
|
|
},
|
|
},
|
|
};
|
|
};
|