in scripts/babel-plugin-jest-native-globals.js [36:119]
ReferencedIdentifier(path, state) {
if (path.node.name === 'Promise' && !state.jestInjectedPromise) {
state.jestInjectedPromise = true;
path
.findParent(p => p.isProgram())
.unshiftContainer('body', promiseDeclaration());
path
.findParent(p => p.isProgram())
.unshiftContainer('body', symbolDeclaration());
}
if (path.node.name === 'Symbol' && !state.jestInjectedSymbol) {
state.jestInjectedSymbol = true;
path
.findParent(p => p.isProgram())
.unshiftContainer('body', symbolDeclaration());
}
if (
path.node.name === 'Date' &&
path.parent.property &&
path.parent.property.name === 'now'
) {
if (!state.jestInjectedNow) {
state.jestInjectedNow = true;
path
.findParent(p => p.isProgram())
.unshiftContainer('body', nowDeclaration());
path
.findParent(p => p.isProgram())
.unshiftContainer('body', symbolDeclaration());
}
path.parentPath.replaceWithSourceString('jestNow');
}
if (
path.node.name === 'fs' &&
path.parent.property &&
['readFileSync', 'writeFileSync', 'existsSync'].includes(
path.parent.property.name,
)
) {
if (
!state.jestInjectedRead &&
path.parent.property.name === 'readFileSync'
) {
state.jestInjectedRead = true;
path
.findParent(p => p.isProgram())
.unshiftContainer('body', fsReadFileDeclaration());
path
.findParent(p => p.isProgram())
.unshiftContainer('body', symbolDeclaration());
path.parentPath.replaceWithSourceString('jestReadFile');
}
if (
!state.jestInjectedWrite &&
path.parent.property.name === 'writeFileSync'
) {
state.jestInjectedWrite = true;
path
.findParent(p => p.isProgram())
.unshiftContainer('body', fsWriteFileDeclaration());
path
.findParent(p => p.isProgram())
.unshiftContainer('body', symbolDeclaration());
path.parentPath.replaceWithSourceString('jestWriteFile');
}
if (
!state.jestInjectedExists &&
path.parent.property.name === 'existsSync'
) {
state.jestInjectedExists = true;
path
.findParent(p => p.isProgram())
.unshiftContainer('body', fsExistsFileDeclaration());
path
.findParent(p => p.isProgram())
.unshiftContainer('body', symbolDeclaration());
path.parentPath.replaceWithSourceString('jestExistsFile');
}
}
},