Repository navigation
Fails when trying to run test on cart transform function #46
Description
Activity
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.0I went ahead used CLI v 3.85.5 and created a fresh app, generated a javascript cart_transform extension, and ran
npx vitest runfrom 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 runshopify app function buildanywhere? 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? │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Thank you for your reply @lopert.
If I run
shopify app function buildin a non app directory, then it gives me the same errorCouldn't find an app toml file at ~/code/functions, is this an app directory?I´ll try updating the version.
I believe it's normal for packages to ship without the src directory.
Mynode_modules/@shopify/shopify-function-test-helperslooks identical, no src, just dist.In fact, the lines reported (92:11) correspond to exactly where this library raises the error.
shopify-function-test-helpers/src/methods/build-function.ts
Lines 91 to 93 in 1280cfd
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:11I 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)Hmm, I still get the error after uninstalling and reinstalling CLI globally.
@mnj-novicell What operating system are you on?
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.jsin the node modules manually.What I did was set
shell: trueon 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.tsA more robust solution may be to allow for override, perhaps through an env variable like
SHOPIFY_CLI_PATH.PR for easy testing/modification: #47
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.
Reacted by Ryan Xu@lopert Good afternoon, sorry to revive this thread. When would these fixes be expected to be in a release?


Hi,
I´m trying to run tests for a cart transform function.
It gave me this error.
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.
I use Shopify CLI version 3.85.5
Any suggestions?