Git Product home page Git Product logo

Comments (6)

nitzanhen avatar nitzanhen commented on June 7, 2024 1

Hi! thanks for reaching out.

Yes, auto-generating test files could be very nice.
I'll try to research it in some when I have some time. Of course, if you have any ideas, suggestion or leads, please share them!

from agrippa.

chriszrc avatar chriszrc commented on June 7, 2024

@nitzanhen The project I linked to creates a file that follows this template:

MapLegend.test.tsx

import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import MapLegend from './MapLegend';

describe('<MapLegend />', () => {
  test('it should mount', () => {
    render(<MapLegend />);
    
    const mapLegend = screen.getByTestId('MapLegend');

    expect(mapLegend).toBeInTheDocument();
  });
});

When you generated a component named "MapLegend"-

from agrippa.

nitzanhen avatar nitzanhen commented on June 7, 2024

In the meantime, you can create test files using a post-command. This requires using a beta version, which you can install using npm i -g agrippa@next. If you run into any issues with it, please reply!

For example, create a file (e.g. gentest.sh) with the following content:

#!/bin/bash

COMPONENT_NAME=$1
COMPONENT_DIR=$2

DATA="
import React from 'react';
import ReactDOM from 'react-dom';
import { $COMPONENT_NAME } from './$COMPONENT_NAME';

it('It should mount', () => {
  const div = document.createElement('div');
  ReactDOM.render(<$COMPONENT_NAME />, div);
  ReactDOM.unmountComponentAtNode(div);
});
"

TEST_FILE_PATH="$COMPONENT_DIR/$COMPONENT_NAME.test.jsx"

echo "$DATA" > $TEST_FILE_PATH

Then, in .agripparc.json, add

{
  //...
  "postCommand": "<path_to_dir>/gentest.sh  <ComponentName> <dirPath>" 
}

Note: I am by no means proficient in bash scripting. This script can probably be improved, but it's simple to understand and seems to work decently.
Also, <ComponentName> is added in v1.4.0-alpha.1, which is why you need the beta version. You could get it to work without <ComponentName>, i.e. on the stable version, as you can see in the issue linked below.

You can also pass --post-command: "<path_to_dir>/gentest.sh <ComponentName> <dirPath> through the command line, though I'd recommend using a config for convenience.

For more info, see Post Command cookbook 🍲 the discussion on issue #42.

from agrippa.

nitzanhen avatar nitzanhen commented on June 7, 2024

@nitzanhen The project I linked to creates a file that follows this template:

MapLegend.test.tsx

import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import MapLegend from './MapLegend';

describe('<MapLegend />', () => {
  test('it should mount', () => {
    render(<MapLegend />);
    
    const mapLegend = screen.getByTestId('MapLegend');

    expect(mapLegend).toBeInTheDocument();
  });
});

When you generated a component named "MapLegend"-

Yes, they seemed to have done pretty well there (with support for multiple testing frameworks and fairly reasonable templates). I'll use it as a reference, thanks!

from agrippa.

rsturim avatar rsturim commented on June 7, 2024

I'd love to see this as well. I've been using hygen.io for a while, but have grown to like agrippa a lot. I really like using a config file to dictate good options, rather than re-inventing an entire template library to do codegen.

from agrippa.

nitzanhen avatar nitzanhen commented on June 7, 2024

Hi! Sorry for the delay. I've not forgotten about this issue.
I'm working on a big new version for Agrippa - one that will solve the current scalability issues and make Agrippa much more modular and customizable.

As soon as that's done - generating test files are at the top of my list. I'm making great progress on the new version, and will hopefully be able to get to it pretty soon.

In the meantime, we can already start planning - which testing frameworks are you using? what would a basic test-file template look like? I am by no means an expert on testing front-end components, so your input could be of great help.

Again, sorry for the delay.

from agrippa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.