Skip to content

Fails when trying to run test on cart transform function #46

Description

@mnj-novicell

Hi,

I´m trying to run tests for a cart transform function.
It gave me this error.

Image

I also tried creating a new app with a cart transform function, which gives me the same error.

It looks for a src folder in the app node modules, but the folder does not exist in the node modules.

Image

I use Shopify CLI version 3.85.5
Any suggestions?

Activity

  1. lopert commented on Jan 15, 2026

    @lopert
    Collaborator

    Hi @mnj-novicell , thanks for reaching out.

    I think you'll need Shopify ClI version 3.87.0 at minimum since that introduced the info command, which this package uses.
    https://github.com/Shopify/cli/releases/tag/3.87.0

    I went ahead used CLI v 3.85.5 and created a fresh app, generated a javascript cart_transform extension, and ran npx vitest run from the extension directory.

    In my case, I got an error message about the new command, which is what I'd expect.

     ❯ tests/default.test.js (1 test | 1 skipped) 15336ms
       ↓ Default Integration Test > runs no-operations.json
    
    ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
    
     FAIL  tests/default.test.js > Default Integration Test
    Error: The "shopify app function info" command is not available in your CLI version.
    Please upgrade to the latest version:
      npm install -g @shopify/cli@latest
    
    
     ❯ ChildProcess.<anonymous> ../../node_modules/@shopify/shopify-function-test-helpers/src/methods/get-function-info.ts:64:13

    It looks like it's not making it passed this buildFunction step in your setup.

    Do you have the CLI installed globally?
    Are you able to run shopify app function build anywhere? From a non app directory, it should give you an error that looks like:

     ~/code/functions  shopify app function build                                                                                                                                                                 ✔
    ╭─ error ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
    │                                                                                                                                          │
    │  Couldn't find an app toml file at ~/code/functions, is this an app directory?                                               │
    │                                                                                                                                          │
    ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
  2. mnj-novicell commented on Jan 16, 2026

    @mnj-novicell
    Author

    Thank you for your reply @lopert.

    If I run shopify app function build in a non app directory, then it gives me the same error Couldn't find an app toml file at ~/code/functions, is this an app directory?

    I´ll try updating the version.

  3. mnj-novicell commented on Jan 22, 2026

    @mnj-novicell
    Author

    Update:

    I have updated Shopify CLI globally to version 3.89.0 .
    I still get the same error, where it looks for a src folder, which is not included in the node modules.

    Image Image

    Any suggestions?

  4. lopert commented on Jan 22, 2026

    @lopert
    Collaborator

    I believe it's normal for packages to ship without the src directory.
    My node_modules/@shopify/shopify-function-test-helpers looks identical, no src, just dist.

    In fact, the lines reported (92:11) correspond to exactly where this library raises the error.

    reject(
    new Error(`Failed to start shopify build command: ${error.message}`),
    );

    So I don't think that's the issue.

    I am able to reproduce your error message if I uninstall the cli.

     ~/code/functions/test-helpers-issue-46  main ?24  npm uninstall -g @shopify/cli                                                                  ✔ 
    
    removed 26 packages in 290ms
    
     ~/code/functions/test-helpers-issue-46  main ?24  which shopify                                                                                  ✔ 
    shopify not found
    
    ~/code/functions/test-helpers-issue-46  main ?24  npx vitest run                                                                               1 ✘ 
    npm warn Unknown project config "shamefully-hoist". This will stop working in the next major version of npm.
    
     RUN  v3.2.4 /Users/lopert/code/functions/test-helpers-issue-46
    
     ❯ extensions/test-46/tests/default.test.js (1 test | 1 skipped) 6ms
       ↓ Default Integration Test > runs no-operations.json
    
    ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
    
     FAIL  extensions/test-46/tests/default.test.js > Default Integration Test
    Error: Failed to start shopify build command: spawn shopify ENOENT
     ❯ ChildProcess.<anonymous> node_modules/@shopify/shopify-function-test-helpers/src/methods/build-function.ts:92:11
    

    I can then recover from this by installing the latest globally once again.

     ~/code/functions/test-helpers-issue-46  main ?24  npm install -g @shopify/cli                                                                  1 ✘ 
    npm warn deprecated boolean@3.2.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
    
    added 59 packages in 6s
    
     ~/code/functions/test-helpers-issue-46  main ?24  which shopify                                                                             ✔  7s 
    /opt/homebrew/bin/shopify
     ~/code/functions/test-helpers-issue-46  main ?24  shopify --version                                                                              ✔ 
    @shopify/cli/3.89.0 darwin-arm64 node-v24.9.0
     ~/code/functions/test-helpers-issue-46  main ?24  npx vitest run                                                                                 ✔ 
    npm warn Unknown project config "shamefully-hoist". This will stop working in the next major version of npm.
    
     RUN  v3.2.4 /Users/lopert/code/functions/test-helpers-issue-46
    
     ✓ extensions/test-46/tests/default.test.js (1 test) 13900ms
       ✓ Default Integration Test > runs no-operations.json  591ms
    
     Test Files  1 passed (1)
          Tests  1 passed (1)
       Start at  13:38:41
       Duration  14.29s (transform 6ms, setup 0ms, collect 80ms, tests 13.90s, environment 0ms, prepare 51ms)
    
  5. mnj-novicell commented on Jan 23, 2026

    @mnj-novicell
    Author

    Hmm, I still get the error after uninstalling and reinstalling CLI globally.

  6. lopert commented on Jan 23, 2026

    @lopert
    Collaborator

    @mnj-novicell What operating system are you on?

  7. Xurya commented on Feb 4, 2026

    @Xurya

    I ran into the same issue on Windows. I've done the global installation, as well as doing a local installation without success. I found a workaround by modifying build-function.js in the node modules manually.

    What I did was set shell: true on Windows for the shopify child process:

    export async function buildFunction(functionPath) {
              ...
              return new Promise((resolve, reject) => {
                 const shopifyProcess = spawn("shopify", ["app", "function", "build", "--path", functionName], {
                    cwd: appRootDir,
                    stdio: ["pipe", "pipe", "pipe"],
                    env: {
                        ...process.env,
                        SHOPIFY_INVOKED_BY: "shopify-function-test-helpers",
                      },
    +               // Ensure resolution of .cmd on Windows
    +               shell: process.platform === "win32",
                }); 
            ...

    Edit: This also applies for the spawn in get-function-info.ts

    A more robust solution may be to allow for override, perhaps through an env variable like SHOPIFY_CLI_PATH.

  8. Xurya commented on Feb 4, 2026

    @Xurya

    PR for easy testing/modification: #47

  9. lopert commented on Feb 5, 2026

    @lopert
    Collaborator

    Thanks for looking into this as well @Xurya .
    I tried this on windows and was able to reproduce.

    Instead of continuing to use spawn, I'm thinking of using execa, similarly to how the shopify CLI works.

  10. Xurya commented on May 26, 2026

    @Xurya

    @lopert Good afternoon, sorry to revive this thread. When would these fixes be expected to be in a release?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions