Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expo Web Broken after integrating Cavy #188

Open
YahyaBagia opened this issue Jun 18, 2020 · 8 comments
Open

Expo Web Broken after integrating Cavy #188

YahyaBagia opened this issue Jun 18, 2020 · 8 comments
Assignees

Comments

@YahyaBagia
Copy link

Just implemented Cavy into my expo project that runs on Android, iOS and Web (managed workflow). Test cases are working properly on Android and iOS but the app now fails to run on Web (non testing mode). It shows the following error :

/node_modules/cavy/src/Tester.js 127:6
Module parse failed: Unexpected token (127:6)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
render() {
|     return (
>       <TesterContext.Provider key={this.state.key} value={this.testHookStore}>
|         {Children.only(this.props.children)}
|       </TesterContext.Provider>

A couple of google search suggests creating / modifying webpack.config.js or .babelrc. My project doesn't have any of them. It's fine that cavy doesn't yet support testing on Web. I just want my app to be running on Web as usual.

@AbigailMcP
Copy link
Contributor

Hey there @YahyaBagia ! Sorry it's taken me a while to respond - are you still having issues?

I don't really have any experience with Expo web, so I might not be the best person to help! But it sounds like you need to get webpack to transpile your node_modules, using something like @expo/webpack-config : https://github.com/expo/expo-cli/tree/master/packages/webpack-config#include-modules.

Let me know how you get on!

@AbigailMcP AbigailMcP self-assigned this Jul 3, 2020
@YahyaBagia
Copy link
Author

Thank you @AbigailMcP for replying. For the time being I've excluded cavy from my Expo project. Please consider making cavy work out of the box with Expo web (if possible). Thank you for the great E2E testing library.

@mwarger
Copy link

mwarger commented Sep 3, 2020

@AbigailMcP I managed to get this working (for expo for web) after adding cavy to the list of modules that you mentioned in the custom webpack config. Transpiling as above handles the JSX in the Tester file (which was causing the above error). However, the index.js is using module.exports and I believe this is what might be causing the error. I was able to get it working in my project by changing the index.js file and just exporting the object rather than using module.exports.

I'm trying to see how I could automate this by modifying the webpack or babel config... if anyone has any thoughts, it would be appreciated. I'm not very familiar with this.

@YahyaBagia
Copy link
Author

@mwarger, can you share a demo project where you successfully implemented Cavy in an Expo project that works for Web as well? It would be a great help for anyone who is looking for this.

@mwarger
Copy link

mwarger commented Sep 3, 2020

Yes, i will get an example put up.

Also, the simpler way to do this might just be to change the index.js export and see if that doesn't happen to break anything. If that's the case then this library should work for web just by adding a transpilation step. I'm also wanting to look and see how other libraries that are web compatible allow for both to co-exist by building the appropriate output. React-Native-Paper comes to mind...

I'm going to pull the cavy-tester example and play with it.

@AbigailMcP
Copy link
Contributor

Hi @mwarger - thanks so much for sharing your success! 🎉

Did you manage to make any headway with a working demo in the Cavy Tester? I'd really love to get this documented / your demo included somewhere in the codebase as an example :)

Thanks!

@mwarger
Copy link

mwarger commented Sep 29, 2020

I haven't yet - I had other priorities. Thanks for the ping though, I'll look at doing this again soon.

@denniske
Copy link

@YahyaBagia
As a workaround you can create a dummy tester component for web tester.web.tsx which does not import cavy.

I use it in my project:
https://github.com/denniske/aoe2companion/tree/master/app/src/view/testing

tester.tsx

import {Tester, TestHookStore, useCavy} from "cavy";
import ExampleSpec from "../../ci/exampleSpec";
import React from "react";

export { useCavy };

const testHookStore = new TestHookStore();

export function ConditionalTester({children}: any) {
  return (
      <Tester clearAsyncStorage={false} waitTime={1000} specs={[ExampleSpec]} store={testHookStore}>
          {children}
      </Tester>
  );
}

tester.web.tsx

export function useCavy() { }

export function ConditionalTester({children}: any) {
    return children;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants