npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

test-package-useless

v1.1.31

Published

AI-powered conversion of Enzyme to RTL

Downloads

207

Readme

Enzyme to RTL codemod

This package is designed to help with automated conversion of jest tests from Enzyme to RTL. It's intended to be used with your version of the LLM

Requirements

  1. Jest
    1. This package depends on your host project jest binary and configuration. See API/Usage for more info how to set it up
  2. Enzyme
    1. This package depends on your host project Enzyme version
  3. Jscodeshift
    1. Installed as part of this package
  4. LLM support
    1. You will need to call LLM with our generated prompt
    2. You will need to implement it yourself with your available LLM model
    3. LLM is instructed to return code in certain xml tags, that allows extracting that code for any model

How to install

  1. Install the package
npm install test-package-useless

or

yarn add test-package-useless

API/Usage

This package exports the following:

  1. setJestBinaryPath - set the path to the executable binary for jest, e.g. npm jest or yarn jest
setJestBinaryPath('yarn jest');
  1. setOutputResultsPath - filepath to output all the generated files in your host project
setOutputResultsPath('<path_to_results_folder>');
  1. converWithAST - run AST conversions/annotations
const astConverted = await converWithAST(filePath);
  1. getReactComponentDOM - collect DOM tree for each test case in your file
const reactCompDom = await getReactComponentDOM(filePath);
  1. generatePrompt - generate prompt with all the necessary info
const prompt = await generatePrompt(filePath, 'data-qa', astConverted, reactCompDom);
  1. extractCodeContent - extract code from the LLM response
const convertedFilePath = extractCodeContent(LLMResponse);
  1. runTestAndAnalyze - run the converted test file and analyze the logs
await runTestAndAnalyze(convertedFilePath);

Output results

  1. ast-transformed-file.jest.tsx - AST converted/annotated file
  2. enzyme-mount-overwrite.jest.tsx - Your file with overwritten Enzyme rendering methods that emit DOM for test cases
  3. enzyme-render-adapter.ts - Enzyme rendering methods with DOM logs collection logic
  4. rtl-converted-file.jest.tsx - Converted RTL file
  5. test-cases-dom-tree.csv - CSV with DOM tree for each test case
  6. jest-test-run-logs.md - Jest run logs for your RTL file

NOTE:

  1. This package will only work if your test files use Enzyme mount and shallow imported directly from Enzyme package. If you use helper methods to mount the components it will not work
import { mount } from 'enzyme';
  1. This package works only with jest, no other test runners have been tested
  2. enzyme-mount-adapter.js is a Javascript file to enable this for project that do not use Typescript

Example

// Import all the necessary methods
import {
	setJestBinaryPath,
	setOutputResultsPath,
	converWithAST,
	getReactComponentDOM,
	generatePrompt,
	extractCodeContent,
	runTestAndAnalyze,
} from 'test-package-useless';
// Import a helper method to call your LLM
import { callClaudeLLM } from './llm-helper/llm-helper';

// Create an async function to execute the flow
async function convertTestFile(filePath: string) {
	// Set host project jest bin path
	setJestBinaryPath('yarn jest');

	// Set host project results output path
	setOutputResultsPath('js/modern/test-utils/ai-package-testing/temp');

	// Get AST conversion
	const astConverted = await converWithAST(filePath);

	// Get React Component DOM tree for each test case
	const reactCompDom = await getReactComponentDOM(filePath);

	// Generate the prompt
	const prompt = await generatePrompt(filePath, 'data-qa', astConverted, reactCompDom);

	/**
	 * Call LLM
	 * 1. This would be specific for every project
	 * 2. We only add tooling for context gathering and prompt generation
     * 3. LLM is instructed to return the converted code in xml tags, which should work with any LLM model
	 */
	// Create Claude specific prompt, make a request, get response
	const LLMResponse = await callClaudeLLM(prompt);

	// Extract generated code
	const convertedFilePath = extractCodeContent(LLMResponse);

	// Run the file and analyze the failures
	await runTestAndAnalyze(convertedFilePath);
}

// Call the function
convertTestFile(
	'<your_enzyme_file>',
);

Debugging

  1. By default log level is info
  2. Set the log level to verbose by importing and setting setLogLevel('verbose')