@babel/traverse - Couldn't find a Program #15340
Answered
by
JLHwung
robertoosantos
asked this question in
General
-
Hi! I have a jest test for my React Native Expo application and it was working pretty fine until I updated from Expo 45 to Expo 48. Now I get this error: The other test pass, but the one involving this particular component (1 out of 92 *.jsx) fails and I can't figure out why. May someone help me? package.json {
"scripts": {
"start": "expo start --dev-client",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"eject": "expo eject",
"test": "jest"
},
"jest": {
"preset": "jest-expo",
"setupFilesAfterEnv": [
"@testing-library/jest-native/extend-expect"
],
"transform": {
"\\.[jt]sx?$": "babel-jest"
},
"globals": {
"__DEV__": true
},
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg|@sentry.*)"
],
"testTimeout": 20000,
"setupFiles": [
"<rootDir>/jest/setup.js"
]
},
"dependencies": {
"@react-native-async-storage/async-storage": "~1.17.3",
"@react-native-community/datetimepicker": "6.5.2",
"@react-native-community/masked-view": "0.1.10",
"@react-native-firebase/analytics": "^16.5.0",
"@react-native-firebase/app": "^16.5.0",
"@react-native-firebase/auth": "^16.5.0",
"@react-navigation/material-bottom-tabs": "^6.0.9",
"@react-navigation/native": "^6.0.6",
"@react-navigation/stack": "^6.0.11",
"@reduxjs/toolkit": "^1.8.3",
"@sentry/react-native": "4.9.0",
"currency.js": "^2.0.3",
"dayjs": "^1.10.2",
"expo": "~47.0.9",
"expo-apple-authentication": "~5.0.1",
"expo-application": "~5.0.1",
"expo-build-properties": "~0.4.1",
"expo-constants": "~14.0.2",
"expo-dev-client": "~2.0.1",
"expo-device": "~5.0.0",
"expo-image-picker": "~14.0.2",
"expo-linking": "~3.3.0",
"expo-mail-composer": "~12.0.0",
"expo-notifications": "~0.17.0",
"expo-splash-screen": "~0.17.5",
"expo-status-bar": "~1.4.2",
"expo-store-review": "~6.0.0",
"expo-tracking-transparency": "~3.0.1",
"expo-updates": "~0.15.6",
"fraction.js": "^4.0.13",
"jest": "^26.6.3",
"jest-expo": "^47.0.0",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-native": "0.70.5",
"react-native-app-link": "^1.0.1",
"react-native-fbsdk-next": "^11.1.0",
"react-native-gesture-handler": "~2.8.0",
"react-native-image-zoom-viewer": "^3.0.1",
"react-native-paper": "^4.8.1",
"react-native-reanimated": "~2.12.0",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "~3.18.0",
"react-native-vector-icons": "^8.1.0",
"react-native-web": "~0.18.7",
"react-native-webview": "11.23.1",
"react-redux": "^7.2.2",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"sentry-expo": "~6.0.0"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@testing-library/jest-native": "^4.0.5",
"@testing-library/react-native": "^11.0.0",
"babel-jest": "^29.3.1",
"eslint": "^8.31.0",
"eslint-plugin-react": "^7.32.0",
"react-test-renderer": "^18.2.0",
"sentry-testkit": "^4.0.1"
},
"private": true,
"name": "caseira.app",
"version": "1.0.0"
} babel.config.js /* eslint-disable no-undef */
module.exports = function (api) {
api.cache(true);
return {
presets: [
'babel-preset-expo',
],
plugins: ['react-native-reanimated/plugin'],
};
}; The test /* eslint-disable no-undef */
import React from 'react';
import renderer from 'react-test-renderer';
import * as Sentry from "@sentry/browser"
global.Sentry = Sentry
jest.useFakeTimers()
jest.mock("@sentry/browser")
import App from '../App';
describe('<App />', () => {
it('has 1 child', () => {
const tree = renderer.create(<App />).toJSON();
expect(tree.children.length).toBe(1);
});
}); And the component import dayjs from 'dayjs';
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types'
import { StyleSheet, ScrollView, Alert } from 'react-native';
import { Button, Card, FAB } from 'react-native-paper';
import CaseiraAPI from '../services/caseira';
import { useDispatch, useSelector } from 'react-redux';
import nomesTelas from '../navigation/nomesTelas';
import MenuItemCardápio from '../components/menuItemCardapio';
import Container from '../components/container';
import SeleçãoData from '../components/selecaoData';
import QuantidadePlanejada from '../components/quantidadePlanejada';
import { atualizarDataPlanejamento } from '../actions/planejamento';
dayjs.locale('pt-br')
// cSpell:ignore terca, sabado refeicoes
function SugerirPlanejamento(props) {
const { slug } = props.route.params || {}
const dias = [0, 1, 2, 3, 4, 5, 6]
const nomesDias = ["domingo", "segunda", "terca", "quarta", "quinta", "sexta", "sabado"]
const [planejamento, setPlanejamento] = useState(null)
const [quantidade, setQuantidade] = useState(0)
const [autor, setAutor] = useState(false)
const [temSugestão, setTemSugestão] = useState([])
const [mostraCalendário, setMostraCalendário] = useState(false)
const [mostraQuantidadePlanejada, setMostraQuantidadePlanejada] = useState(false)
const [carregando, setCarregando] = useState(false)
const reduxState = useSelector(state => (
{
login: state.login.informações,
refeições: state.refeição.refeições,
planejamento: state.planejamento,
}))
const api = new CaseiraAPI(reduxState.login.token)
const idUsuário = reduxState.planejamento.planejamentoDe ?
reduxState.planejamento.planejamentoDe.user._id :
reduxState.login.user._id
const dispatch = useDispatch()
const consultar = async () => {
try {
let dados = {}
if (!slug)
dados = await api.ConsultarSugestãoAtual()
else
dados = await api.ConsultarSugestão(slug)
let temSugestãoAtualizado = []
for (let i = 0; i < dias.length; i++) {
const dia = dias[i];
reduxState.refeições.some(refeição => {
temSugestãoAtualizado[dia] = dados.refeicoes.some((r) => {
return r.nome === refeição.nome && r[nomesDias[dia]].length > 0
})
return temSugestãoAtualizado[dia]
})
}
setTemSugestão(temSugestãoAtualizado)
setAutor(dados.criadoPor === reduxState.login.user._id)
setPlanejamento(dados)
} catch (error) {
Alert.alert("Ops!", error.message)
}
}
useEffect(() => {
consultar()
}, [slug, reduxState.login, reduxState.refeições])
const remover = async (receita, dia, refeição) => {
try {
await api.AtualizarSugestão(
planejamento._id,
receita._id,
dia,
refeição.nome,
"Excluir"
)
consultar()
} catch (error) {
Alert.alert("Ops!", error.message)
}
};
const copiarRefeição = async (data, refeição, receita) => {
try {
const retorno = await api.AtualizarSugestão(
planejamento._id,
receita,
data,
refeição.nome,
"Incluir")
setPlanejamento(retorno)
} catch (error) {
Alert.alert("Ops!", error.message)
}
}
const mostrarPlanejar = !autor ? <FAB
icon="calendar-plus"
style={styles.FAB}
label="Planejar"
loading={carregando}
disabled={carregando}
onPress={() => { setMostraQuantidadePlanejada(true); }} /> : null;
return (
<Container>
<ScrollView horizontal={true} snapToInterval={330} decelerationRate="fast"
keyboardShouldPersistTaps='handled'>
{dias?.map((dia) => {
if (!autor && !temSugestão[dia])
return null
return (
<Card style={styles.card} key={dia} elevation={9}>
<Card.Title
title={dayjs().day(dia).format("dddd")} />
<Card.Content style={{ flex: 1 }}>
<ScrollView showsVerticalScrollIndicator={false}
keyboardShouldPersistTaps='handled'>
{reduxState.refeições?.map((refeição) => {
const chave = refeição.nome.concat(dia);
const refeiçãoPlanejada = planejamento?.refeicoes.find((r) => r.nome === refeição.nome);
const receitas = refeiçãoPlanejada ? refeiçãoPlanejada[nomesDias[dia]] : null;
if (!autor && (!receitas || receitas.length === 0))
return null
return (
<Card key={chave} style={styles.refeições} elevation={3}>
<Card.Title title={refeição.nome} />
<Card.Content>
{receitas?.map((receita) => {
const chave = refeição.nome.concat(receita.nome);
return <MenuItemCardápio
sugerindo={true}
podeAlterarQuantidade={false}
podeCopiar={autor}
podeRemover={autor}
key={chave}
receita={receita}
aoRemover={() => remover(receita, dia, refeição)}
aoCopiar={(dataPlanejada, refeição) => copiarRefeição(dataPlanejada, refeição, receita)}
{...props} />;
})}
</Card.Content>
{planejamento?.criadoPor === reduxState.login.user._id ?
<Card.Actions>
<Button
onPress={() => props.navigation.navigate(nomesTelas.pesquisar, {
sugestão: planejamento?._id,
dataPlanejando: dia,
refeiçãoPlanejando: refeição.nome,
sugerindo: true
})}
>Planejar</Button>
</Card.Actions> :
null}
</Card>);
})}
</ScrollView>
</Card.Content>
</Card>
);
})}
</ScrollView>
{mostrarPlanejar}
<QuantidadePlanejada
aoDispensar={() => setMostraQuantidadePlanejada(false)}
visível={mostraQuantidadePlanejada}
aoAlterar={(quantidade) => {
setMostraQuantidadePlanejada(false)
if (quantidade && quantidade !== "0") {
setQuantidade(quantidade)
setMostraCalendário(true)
}
}} />
<SeleçãoData
visível={mostraCalendário}
aoDispensar={() => setMostraCalendário(false)}
valorMínimo={new Date()}
aoAlterar={async (evento, data) => {
try {
setMostraCalendário(false);
if (data) {
setCarregando(true)
await api.PlanejarSugestão(planejamento._id, data, quantidade, idUsuário)
dispatch(atualizarDataPlanejamento(dayjs(data).format("YYYY-MM-DD"), false))
props.navigation.navigate(nomesTelas.planejamento.cardápio)
}
} catch (error) {
setCarregando(false)
Alert.alert("Ops!", error.message)
}
}} />
</Container>
)
}
SugerirPlanejamento.propTypes = {
navigation: PropTypes.object,
route: PropTypes.object,
}
export default SugerirPlanejamento;
const styles = StyleSheet.create({
diaDoMês: {
fontSize: 30,
fontWeight: "bold"
},
FAB: {
position: 'absolute',
margin: 16,
bottom: 0,
right: 0,
},
container: {
backgroundColor: '#FFFBF4',
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
controles: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center'
},
card: {
width: 300,
marginHorizontal: 15,
marginVertical: 10
},
refeições: {
marginHorizontal: 5,
marginVertical: 10
},
scroll: {
}
}); |
Beta Was this translation helpful? Give feedback.
Answered by
JLHwung
Jan 12, 2023
Replies: 1 comment 3 replies
-
Can you post the error stack trace? |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
liuxingbaoyu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you post the error stack trace?