[PR #5745] feat(common): add collection-level pre-request and test scripts #5334

Open
opened 2026-03-17 02:47:27 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5745
Author: @johnan319
Created: 1/5/2026
Status: 🔄 Open

Base: mainHead: feat/collection-level-scripts


📝 Commits (10+)

  • 217584e feat(common): add collection-level pre-request and test scripts
  • 943912e fix: address review feedback
  • 7cf2698 fix: update test mocks to use v12 collection schema
  • 3ceae08 fix: wrap inherited scripts in IIFE to prevent variable clashes
  • 6c22e6d Merge branch 'main' into feat/collection-level-scripts
  • a3a6ceb fix: prevent array mutation and enable async/await in script IIFEs
  • 4be8fa2 fix(cli): strip module prefix and support async/await in script IIFEs
  • 04c9401 Merge branch 'main' into feat/collection-level-scripts
  • 205038c feat: add collection-level pre-request and test script inheritance
  • a3ca2ee chore: remove unnecessary comments

📊 Changes

55 files changed (+1708 additions, -188 deletions)

View changed files

📝 packages/hoppscotch-backend/src/team-collection/team-collection.service.ts (+35 -20)
📝 packages/hoppscotch-backend/src/team-request/team-request.service.ts (+15 -13)
📝 packages/hoppscotch-backend/src/user-collection/user-collection.service.ts (+34 -18)
📝 packages/hoppscotch-cli/src/__tests__/unit/fixtures/workspace-access.mock.ts (+56 -12)
packages/hoppscotch-cli/src/__tests__/unit/pre-request-inheritance.spec.ts (+172 -0)
packages/hoppscotch-cli/src/__tests__/unit/scripting.spec.ts (+138 -0)
packages/hoppscotch-cli/src/__tests__/unit/test-runner-inheritance.spec.ts (+194 -0)
📝 packages/hoppscotch-cli/src/interfaces/response.ts (+2 -0)
📝 packages/hoppscotch-cli/src/types/request.ts (+2 -0)
📝 packages/hoppscotch-cli/src/utils/collections.ts (+17 -2)
📝 packages/hoppscotch-cli/src/utils/pre-request.ts (+18 -3)
📝 packages/hoppscotch-cli/src/utils/request.ts (+14 -6)
packages/hoppscotch-cli/src/utils/scripting.ts (+54 -0)
📝 packages/hoppscotch-cli/src/utils/test.ts (+16 -3)
📝 packages/hoppscotch-cli/src/utils/workspace-access.ts (+6 -0)
📝 packages/hoppscotch-common/locales/en.json (+5 -0)
📝 packages/hoppscotch-common/src/components.d.ts (+1 -0)
📝 packages/hoppscotch-common/src/components/collections/Properties.vue (+150 -1)
📝 packages/hoppscotch-common/src/components/collections/documentation/index.vue (+4 -0)
📝 packages/hoppscotch-common/src/components/collections/graphql/Add.vue (+3 -0)

...and 35 more files

📄 Description

Summary

Adds support for defining pre-request and test scripts at the collection level, which are inherited by all requests within that collection. This reduces code duplication when multiple requests need the same script logic (e.g., authentication token refresh).

Changes

  • UI: Add "Scripts" tab to collection properties with pre-request and test script textareas
  • Script Inheritance:
    • Pre-request scripts execute in order: Root collection → Parent folder → Child folder → Request
    • Test scripts execute in order: Request → Child folder → Parent folder → Root collection
  • Schema: Update collection schema to v12 with preRequestScript and testScript fields
  • CLI Support: Add inherited script support to CLI pre-request and test runners
  • Type Updates: Add scripts property to HoppInheritedProperty type

Closes #3728


Summary by cubic

Adds collection-level pre-request and test scripts that inherit through the collection tree. Scripts run in order with isolated scope across app, CLI, and test runner; Postman collection/folder scripts are imported. Closes #3728.

  • New Features

    • Scripts tab in collection properties with Monaco editor (CodeMirror fallback), plus inherited script indicators and list in Pre-request/Tests panels.
    • Inheritance: pre-request runs Root → Parent → Child → Request; tests run Request → Child → Parent → Root; app/CLI/test runner pass inherited scripts.
    • Collection schema v12 adds preRequestScript and testScript; persisted in import/export, workspace transforms, published docs, validation, team/user collections, and self-host sync; Postman importer reads collection/folder scripts.
    • CLI/test runner combine inherited scripts with async IIFEs for sequential execution and variable isolation.
  • Bug Fixes

    • Strip "export {};" module prefix before execution/export; filter empty scripts; use slice().reverse() to avoid array mutation.
    • Enforce tab access rules so Scripts shows only when applicable; catch delete race (P2025) and prevent move deadlocks via deterministic lock order.
    • Fix inherited scripts handling in team request search.

Written for commit 8e5fa6f7f5. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5745 **Author:** [@johnan319](https://github.com/johnan319) **Created:** 1/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/collection-level-scripts` --- ### 📝 Commits (10+) - [`217584e`](https://github.com/hoppscotch/hoppscotch/commit/217584e057527bce57e2d9ec6efbde304c631066) feat(common): add collection-level pre-request and test scripts - [`943912e`](https://github.com/hoppscotch/hoppscotch/commit/943912ef414fd6840e1da7923b8cb79bd52826bb) fix: address review feedback - [`7cf2698`](https://github.com/hoppscotch/hoppscotch/commit/7cf269805bd813866a4a6f768aea644b944a41f9) fix: update test mocks to use v12 collection schema - [`3ceae08`](https://github.com/hoppscotch/hoppscotch/commit/3ceae08d621235f89debb79a83e0bbb3416068ab) fix: wrap inherited scripts in IIFE to prevent variable clashes - [`6c22e6d`](https://github.com/hoppscotch/hoppscotch/commit/6c22e6da3c485a7b130db4284bb205521ef8f149) Merge branch 'main' into feat/collection-level-scripts - [`a3a6ceb`](https://github.com/hoppscotch/hoppscotch/commit/a3a6cebb3728a367f6caf786ae9c81b504287c35) fix: prevent array mutation and enable async/await in script IIFEs - [`4be8fa2`](https://github.com/hoppscotch/hoppscotch/commit/4be8fa246b09b515d716807bfc85f169e052e4b8) fix(cli): strip module prefix and support async/await in script IIFEs - [`04c9401`](https://github.com/hoppscotch/hoppscotch/commit/04c9401591136b2cac43a807498207b8527b8c6e) Merge branch 'main' into feat/collection-level-scripts - [`205038c`](https://github.com/hoppscotch/hoppscotch/commit/205038cf26b8ac07d0c7e92cbd4a8d48b1d32e72) feat: add collection-level pre-request and test script inheritance - [`a3ca2ee`](https://github.com/hoppscotch/hoppscotch/commit/a3ca2ee0f4250179dbf32e354881fd6d0c90d503) chore: remove unnecessary comments ### 📊 Changes **55 files changed** (+1708 additions, -188 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-backend/src/team-collection/team-collection.service.ts` (+35 -20) 📝 `packages/hoppscotch-backend/src/team-request/team-request.service.ts` (+15 -13) 📝 `packages/hoppscotch-backend/src/user-collection/user-collection.service.ts` (+34 -18) 📝 `packages/hoppscotch-cli/src/__tests__/unit/fixtures/workspace-access.mock.ts` (+56 -12) ➕ `packages/hoppscotch-cli/src/__tests__/unit/pre-request-inheritance.spec.ts` (+172 -0) ➕ `packages/hoppscotch-cli/src/__tests__/unit/scripting.spec.ts` (+138 -0) ➕ `packages/hoppscotch-cli/src/__tests__/unit/test-runner-inheritance.spec.ts` (+194 -0) 📝 `packages/hoppscotch-cli/src/interfaces/response.ts` (+2 -0) 📝 `packages/hoppscotch-cli/src/types/request.ts` (+2 -0) 📝 `packages/hoppscotch-cli/src/utils/collections.ts` (+17 -2) 📝 `packages/hoppscotch-cli/src/utils/pre-request.ts` (+18 -3) 📝 `packages/hoppscotch-cli/src/utils/request.ts` (+14 -6) ➕ `packages/hoppscotch-cli/src/utils/scripting.ts` (+54 -0) 📝 `packages/hoppscotch-cli/src/utils/test.ts` (+16 -3) 📝 `packages/hoppscotch-cli/src/utils/workspace-access.ts` (+6 -0) 📝 `packages/hoppscotch-common/locales/en.json` (+5 -0) 📝 `packages/hoppscotch-common/src/components.d.ts` (+1 -0) 📝 `packages/hoppscotch-common/src/components/collections/Properties.vue` (+150 -1) 📝 `packages/hoppscotch-common/src/components/collections/documentation/index.vue` (+4 -0) 📝 `packages/hoppscotch-common/src/components/collections/graphql/Add.vue` (+3 -0) _...and 35 more files_ </details> ### 📄 Description ## Summary Adds support for defining pre-request and test scripts at the collection level, which are inherited by all requests within that collection. This reduces code duplication when multiple requests need the same script logic (e.g., authentication token refresh). ### Changes - **UI**: Add "Scripts" tab to collection properties with pre-request and test script textareas - **Script Inheritance**: - Pre-request scripts execute in order: Root collection → Parent folder → Child folder → Request - Test scripts execute in order: Request → Child folder → Parent folder → Root collection - **Schema**: Update collection schema to v12 with `preRequestScript` and `testScript` fields - **CLI Support**: Add inherited script support to CLI pre-request and test runners - **Type Updates**: Add `scripts` property to `HoppInheritedProperty` type Closes #3728 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds collection-level pre-request and test scripts that inherit through the collection tree. Scripts run in order with isolated scope across app, CLI, and test runner; Postman collection/folder scripts are imported. Closes #3728. - New Features - Scripts tab in collection properties with Monaco editor (CodeMirror fallback), plus inherited script indicators and list in Pre-request/Tests panels. - Inheritance: pre-request runs Root → Parent → Child → Request; tests run Request → Child → Parent → Root; app/CLI/test runner pass inherited scripts. - Collection schema v12 adds preRequestScript and testScript; persisted in import/export, workspace transforms, published docs, validation, team/user collections, and self-host sync; Postman importer reads collection/folder scripts. - CLI/test runner combine inherited scripts with async IIFEs for sequential execution and variable isolation. - Bug Fixes - Strip "export {};" module prefix before execution/export; filter empty scripts; use slice().reverse() to avoid array mutation. - Enforce tab access rules so Scripts shows only when applicable; catch delete race (P2025) and prevent move deadlocks via deterministic lock order. - Fix inherited scripts handling in team request search. <sup>Written for commit 8e5fa6f7f5f71503cd7dc755694b9cf21e86f609. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5334
No description provided.