To make a VS Code task wait for a build to finish before it runs another command on macOS, define the build as a dependency and set "dependsOrder": "sequence" on the task that depends on it. VS Code runs multiple dependencies in parallel by default, so listing the build first is not enough. The example below runs npm run build to completion before npm test.

Define the build and dependent task

In your project, open the Command Palette with ⇧⌘P, run Tasks: Configure Task, or use Terminal > Configure Tasks. Create or edit .vscode/tasks.json in the workspace. Keep any existing tasks you still need, and add tasks like these inside its tasks array:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Build project",
      "type": "shell",
      "command": "npm run build",
      "problemMatcher": []
    },
    {
      "label": "Test after build",
      "dependsOn": ["Build project"],
      "dependsOrder": "sequence"
    }
  ]
}

The dependent task has no command of its own: its job is to run the dependency first. To make it perform a follow-up action, add a command and shell task type, for example "type": "shell" and "command": "npm test", to Test after build. Run that parent task through Terminal > Run Task or the Command Palette’s Tasks: Run Task command. VS Code’s documentation says that dependsOn composes tasks, dependencies run in parallel by default, and dependsOrder: "sequence" runs them in the listed order. Integrate with External Tools via Tasks

This example assumes the project’s package.json defines working build and test scripts and that npm is available to VS Code. Replace the commands with the actual build and follow-up commands for your project. On macOS, VS Code shell tasks run through a shell; if you write a command as one string, include the quoting or escaping its shell needs. In particular, quote paths containing spaces, such as "command": "./scripts/build.sh 'Assets Folder'". Integrate with External Tools via Tasks

What “wait” means for a build

For a normal one-shot build, the sequence lets the dependency finish before starting the next dependency or the parent task. This works when the build command exits after completing. If you list several dependencies, sequence them in the order they appear in dependsOn; without dependsOrder, VS Code may start them together.

A watch task behaves differently because it is intended to keep running. VS Code documents that background tasks in a sequential dependency chain need a problem matcher that detects when they are “done.” For a watcher, that means defining a matcher that recognizes its ready state; otherwise, VS Code cannot determine when it is ready to move on. A one-time build usually should not use watch mode or isBackground. Integrate with External Tools via Tasks

Run it and diagnose common problems

Save tasks.json, then run Test after build from Terminal > Run Task. Read the integrated terminal output to confirm the actual command ran and finished. If the parent task is missing or the build does not start first, check these points:

  • The label in dependsOn exactly matches the build task’s label—including spaces and capitalization.
  • Both task definitions are inside the same tasks array, and the file uses task version 2.0.0.
  • dependsOrder is set on the parent task, alongside dependsOn.
  • The shell command works from the workspace folder, or set options.cwd if the build script lives in a subfolder.
  • If the build is a watcher, configure a background problem matcher that signals readiness; merely setting isBackground does not tell VS Code when it is ready.

VS Code documents platform-specific task configuration, including an osx section, but the dependency ordering mechanism is the same: dependsOn and dependsOrder. You do not need an invented “wait” shell command for this task chain. The documented boundary is that a long-running background task needs a problem matcher to report its readiness. Appendix: Schema for tasks.json

Sources