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

maestro-ts

v0.4.10

Published

An executable compiler for creating Maestro's yaml-flows with typescript.

Downloads

1,653

Readme

Maestro-ts

An executable compiler for creating maestro's yaml-flows from typescript files.

What it is

TLDR: You can write Maestro flows in TypeScript 😍

Maestro is a new and amazing e2e testing tool for mobile apps. It's incredibly easy to set up and easy to use. Usually, you would write test flows in yaml. That however, can be a hassle to write since there is no easy way to set up autocomplete for yaml and the syntax can be fairly verbose at times. Additionally, there are still some instabilities with maestro, such as with the inputText-directive, which can be fixed using hacky workarounds. Maestro-ts introduces a compiling-layer which takes a test flows written in typescript and generates the yaml for you. If you enjoy trying out or using maestro-ts and want to support the development, I'd be happy if you give the repo a star ⭐️ - Thanks!

Advantages over writing flows in yaml:

  • Discoverable and documented Api thanks to typescript and jsdoc
  • Autocomplete and typechecking out of the box
  • Simpler, less verbose and less fragile syntax compared to yaml
  • auto-applied fixes to common problems with maestro, such as inputting text

Disadvantages:

  • Special use cases and complex commands might not be supported, yet
  • You'll have to have typescript set up
  • You won't benefit from using Maestro studio

Usage

💡 NOTE: First off, make sure you've set up maestro correctly.

In your app, create a folder your tests will live in. We recommend my-app/test/e2e.

Setting up types

To set up types, run

yarn add maestro-ts --dev # or npm i maestro --save-dev

Create your first flow

Create a file called my-first-flow.maestro.ts and add the following content:

import { M } from "maestro-ts"

M.initFlow("com.myTeam.myApp")
M.tapOn("someTestId")
// Add more commands here 😎

Compiling and running your flows

Now, from your e2e test folder, generate the yaml flows and run them.

cd test/e2e && npx maestro-ts
maestro test my-first-flow.yaml

Advanced Usage

By adding a config file to your project, you can take advantage of some extra features and save a bit of work while writing flows:

// create test/e2e/maestro-ts.config.cjs

module.exports = {
  // default for commands like launchApp
  appId: "com.some.app",
  // used for M.navigate("/profile"). Only works if you've properly set up deep linking for the desired uris.
  deepLinkBase: "com.some.app://",
}

Example usage

Here's a short sample flow, but feel free to check out the examples for more extensive flows.

// test/e2e/my-flow.maestro.ts
import { M, N } from "maestro-ts"

M.initFlow({ appId: "com.my.app", NAME: "Maestro" })
M.tapOn("someTestId")
M.inputText("Hello", "someTextInputId") // taps input before typing
M.inputText("${NAME}") // uses focused input

M.repeat(3, () => {
  N.tapOn("myButton") // for nested commands, you need to use the N-module.
})

/**
 * Navigating will only work once you've set up deep linking in your app
 * and you've set the appropriate deepLinkingBase in maestro.config.ts.
 * This pattern integrates beautifully with Solito or expo-router where deep links are a given.
 */
M.navigate("/profile")

/**
 * If you apply routes as testIDs to your ScreenContainers, you can easily assert if a screen is visible: 😎
 * // profile-screen.tsx
 *
 * export const ProfileScreen = () => {
 *    return (
 *      <ScreenContainer testID="/profile">
 *        {content}
 *      </ScreenContainer>
 *    )
 * }
 */
M.assertVisible("/profile")

When not to use maestro-ts

Maestro-ts certainly isn't the solution for everyone, so here are a few cases where you most likely wouldn't use or stop using maestro-ts:

You've got plenty of experience writing yaml flows for maestro and don't mind writing it.

If that's the case - congrats! Maybe you've even enhanced your yaml-writing-workflow using vscode-snippets for specific maestro-commands?

You've hit a wall using maestro-ts and need a functionality it doesn't provide.

Nothing stops you from initially creating your flows using maestro-ts and then manually extending them in the yaml file. Just make sure you don't overwrite your manually edited flow next time you run npx maestro-ts. However, since we supply a M.yaml() function, you can literally do anything in maestro-ts you could do in yaml. Additionally, you can write your own extensions for maestro-ts and override functionalities as you please. So with with that, nothing should stop you, really 🚀.

You're writing your app with RN+JS, Flutter or in native iOS and Android

I get that you might not want to set up maestro-ts in a non-TypeScript-app, so possibly you just want to write yaml yourself. However, if you still want to try maestro-ts, why not set up a separate project, just to create flows with?

mkdir my-flows && cd my-flows
yarn init -y
yarn add maestro-ts typescript --dev
npx tsc --init
touch my-flow.maestro.ts # create your flow in here
# creates my-flow.yaml which you can just drop into your flutter, iOS or Android app.
npx maestro-ts

ToDos / Road Map

  • [x] Add sample flows
  • [ ] Supply sample app with multiple flows.
  • [x] Support custom compiler-blocks for extending and overwriting maestro-ts's functionality.
  • [ ] Optional testID-autocomplete - In the future, we might provide a tool which crawls your codebase for testIds and let's you use autoComplete in your flows.
  • [ ] Add tests
  • [ ] Add linting rule to prevent nested usages of M - module