Skip to content

[Feature]: Feature Request: Add Preview.AssertJavaScript for Automated Testing of Web Resources #621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Grant-Archibald-MS opened this issue May 16, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@Grant-Archibald-MS
Copy link
Contributor

Grant-Archibald-MS commented May 16, 2025

Is your feature request related to a problem? Please describe.

Currently, there is integrated way to automatically test web resources (such as JavaScript files) that are part of a solution in model-driven Power Apps applications.

While it is straightforward to attach and associate a web resource with a model-driven app, validating its behavior is can be manual and difficult to validate different test cases. This introduces risks of regressions and makes it difficult to guarantee the quality of custom client-side logic.

Describe the solution you'd like

Introduce a new testing function:
Preview.AssertJavaScript({WebResource: string, Location: string, Setup: string, Run: string, Expected: string})

Functionality:

  • Allow users to specify the name of a JavaScript web resource or local location of the JS file
  • Define setup scripts
  • Define the script/function to run
  • Define JavaScript to run and the expected outcome.

The test engine should be able to:

  • Query and retrieve the definition of the specified JavaScript web resource.
  • Reference a local JS file included with Native Source control integration as part of a solution
  • Execute unit tests for the resource in an isolated sandbox environment, preventing side effects.
  • Compare the actual outcome with the expected outcome and report results.

Example Usage:

Preview.AssertJavaScript({
  WebResource: "myScript.js",
  Setup: "mockXrm.js",
  Run: "calculateTotal(5, 10);",
  Expected: "15"
});

Where mockXrm.js could be included with the yaml test

 Xrm = {
      Page: {
        data: {
          entity: {
            getId: () => "mock-id",
            getEntityName: () => "account"
          }
        },
        ui: {
          controls: {
            get: (name) => ({
              getName: () => name,
              setVisible: (visible) => {},
              setDisabled: (disabled) => {}
            })
          },
          getFormType: () => 2,
          setFormNotification: (msg, type, id) => {}
        },
        getAttribute: (name) => ({
          getValue: () => "mock-value",
          setValue: (val) => {}
        }),
        getControl: (name) => ({
          setVisible: (visible) => {},
          setDisabled: (disabled) => {}
        })
      },
      Utility: {
        openWebResource: (name, options) => {}
      },
      WebApi: {
        retrieveRecord: (entity, id, options) => Promise.resolve({ id, entity }),
        createRecord: (entity, data) => Promise.resolve({ id: "new-id", ...data })
      }
    };

Benefits:

  • Automates testing for JavaScript web resources, improving reliability and maintainability.
  • Supports test-driven development for Power Apps solutions.
  • Sandboxed execution ensures that tests do not affect other components or data.

Additional Notes:

  • The test runner should support mocking dependencies and isolating test cases.
  • Consider supporting assertion libraries or providing basic assertion methods out-of-the-box.

Describe alternatives you've considered

No response

Additional context?

No response

@Grant-Archibald-MS Grant-Archibald-MS added the enhancement New feature or request label May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant