MSBA-271 · Lesson 7 of 12 · 18 min
Testing and packaging components
▶ Video coming soon A video version of this lesson is on the way.
Rupert came to this session with a story. The previous spring a contractor had delivered a code component to the registrar as a solution file built on his laptop. It worked in test. In production it showed a blank square, because the version in the manifest had not changed since an earlier draft and the environment kept serving the old bundle. Nobody could rebuild it, because the source was on the contractor's laptop. "This session," Rupert said, "is about making sure that never happens again."
Two paths out of a developer machine
A code component leaves the developer's machine in one of two ways. The development path is fast and meant for a developer's own environment: pac pcf push builds the component and imports it into the environment the CLI is connected to, inside a temporary solution. The release path is slower and meant for everything else: the component is added to a solution project, built into a solution file by a repeatable build, and moved through environments by pipelines like any other solution.
The development path: pac pcf push
pac auth select --index 2 # Wiremu Dev
pac pcf push --publisher-prefix lccpac pcf push builds the component, creates or updates a temporary solution in the target environment, imports the component and publishes customizations. The temporary solution is named after the publisher prefix, and it exists only to get the control into the environment quickly. Its contents are unmanaged and its name means nothing to anyone else, so it should never be exported and moved on. Wiremu pushed RoomCapacity into Wiremu Dev, added it to the booked seats column on the Room form, with the capacity column as its input, and watched the bar appear with real data for the first time.
Adding a component to a model-driven form is done in the form designer: select the column, open its Components settings, add the component, and set its properties, including which column fills each input. Makers can choose whether the component shows on web, phone and tablet, and the standard control remains as a fallback. For canvas apps, an environment setting must allow code components; makers then import the component from the Get more components panel and use it like any other control.
Testing a component properly
The test harness from lesson 6 tests a component's drawing. Real confidence needs three more kinds of testing, and Lumenvale used all three for components that would reach production.
| Kind of test | Tool | What it catches |
|---|---|---|
| Unit tests | Jest or a similar test runner, run in the build | Logic errors: calculations, formatting, null handling, the undefined-or-null output rule |
| Harness tests | The component test harness, by hand | Drawing at different sizes, disabled mode, empty values |
| UI tests in the app | Playwright with Microsoft's Power Platform samples | The component working on the real form with real data, other scripts and business rules |
| Accessibility tests | Keyboard and screen reader checks, automated checkers | Missing labels, unreachable controls, poor contrast (lesson 10) |
Unit tests are easiest when the logic lives in plain functions that do not depend on the component context. Wiremu moved RoomCapacity's percentage and colour rules into a small module with no imports from the framework, and wrote tests for zero capacity, overbooking, the default warning threshold and a missing booked value. They ran in a second and ran again in every build.
import { capacityState } from "../src/capacityState";
test("shows warning at the threshold", () => {
expect(capacityState(18, 20, 90)).toEqual({ level: "warning", text: "18 of 20 booked" });
});
test("handles capacity not set", () => {
expect(capacityState(5, 0, 90)).toEqual({ level: "unknown", text: "Capacity not set" });
});For tests in the running app, MSBA-251 and MSBA-270 noted that Microsoft deprecated Power Apps Test Engine in April 2026 and recommends Playwright with its Power Platform samples. Lumenvale's facilities repository already had a Playwright project for the Field Tech app, and Wiremu added a test that opened a room in Facilities Test, checked the capacity text and checked that the bar was not shown when the column was empty.
The release path: solution projects
A solution project is a small project on disk that produces a Dataverse solution file when built. It references one or more component projects, and the build compiles them in release mode, adds them to the solution and zips it. The commands are short.
mkdir LumenvaleFacilitiesControls
cd LumenvaleFacilitiesControls
pac solution init --publisher-name Lumenvale --publisher-prefix lcc
pac solution add-reference --path ../RoomCapacity
dotnet build --configuration ReleaseThe build produces a solution file in the bin folder. In Release configuration the component bundle is built in production mode, which is smaller and faster than the development build used by the harness and by push. The solution project's settings decide whether the build produces an unmanaged solution, a managed one or both; Lumenvale built both, keeping the unmanaged one for development environments and importing the managed one everywhere else. The solution project can be committed to source control and built by GitHub Actions, as MSBA-270 described for the facilities repository.
There is a choice about where components live. A component can be referenced by its own solution, as here, so that several apps can depend on one controls solution; or it can be added to the main application solution. Lumenvale chose a separate solution, Lumenvale Facilities Controls, because RoomCapacity and later RoomPicker would be used by more than one app, and the Facilities and Registrar solutions would depend on it the same way they depended on Lumenvale Core.
Versions and updates
Two version numbers matter, and both must change. The manifest version of the component tells the platform that the control has changed; if it does not increase, environments may keep serving the previous bundle, which is exactly what had happened to the registrar's contractor. The solution version tells the import process that the solution is newer. Lumenvale's build pipeline checked that every changed component had a higher manifest version than the last release, and stopped the build if not.
| Change | Manifest version | Solution version |
|---|---|---|
| Bug fix in TypeScript or CSS | Increase the patch number, for example 1.0.3 to 1.0.4 | Increase |
| New optional property | Increase the minor number | Increase |
| Removing or renaming a property | Avoid; makers' configurations depend on it. If unavoidable, create a new component | Increase |
| Only the solution's other components changed | No change needed | Increase |
Removing or renaming a property is the one change that hurts makers. Every form and app that uses the component has saved settings for each property; a property that disappears leaves those settings broken. Signe's rule was to add new properties as optional with sensible defaults, and to treat existing property names as a public contract.
Checks before import
Solution checker analyses solutions, including web resources and code components, for patterns known to cause problems, and Managed Environments can require it to pass before import, as MSBA-253 described. For components it flags issues such as unsupported calls and outdated APIs. Lumenvale also ran npm audit in the build to catch vulnerable npm packages, and kept third-party dependencies to a minimum. A React component that uses the platform's React and Fluent libraries has far fewer packages to audit than a standard component that bundles its own.
Worked problem
Diagnosing a component that will not update
After a release to Facilities Test, testers report that RoomCapacity still shows the old grey bar, not the new Fluent one. The solution imported without errors. What should Wiremu check, in order?
Show solution
- Check the manifest version in the built solution. If it is the same as the previous release, the environment may keep using the earlier bundle. Increase it and rebuild.
- Check that the managed solution actually contains the new bundle: that the release build ran, and that the pipeline imported the new file rather than a cached artifact.
- Check the browser: a hard refresh, or a private window, rules out a cached script on the tester's machine.
- Check for a second copy of the component in another solution layer, such as an old temporary solution from pac pcf push imported into test by mistake.
Answer: In this case the manifest version had not changed. After it was raised to 1.0.4 and the solution rebuilt, the new bar appeared. The pipeline check that now blocks unchanged versions came from this incident.
Source control and review for components
A component project is a web project, and it belongs in source control like one. The facilities repository kept each component in its own folder under src, with the solution project beside them, and a .gitignore that excluded the folders the build creates: node_modules, out, bin and obj. The package-lock file was committed, so that every build installed exactly the same package versions. Nothing generated by the build was committed, because anything that can be rebuilt from source should be.
Every change reached the main branch through a pull request with a reviewer, and the pull request template held a short checklist. The reviewer confirmed that the manifest version had increased, that no property had been removed or renamed, that new strings were in the resx file rather than hard-coded, that unit tests covered new logic, and that the change had been seen in the harness at narrow and wide sizes. The accessibility checklist from lesson 10 was added to the template later.
| Folder or file | Purpose | In source control? |
|---|---|---|
| src/RoomCapacity | Component project: manifest, TypeScript, resources, tests | Yes |
| src/LumenvaleFacilitiesControls | Solution project referencing the components | Yes |
| package-lock.json | Exact package versions for repeatable builds | Yes |
| node_modules, out, bin, obj | Created by installs and builds | No |
| docs/components | Guidance for makers using each component | Yes |
Dependencies and layers
Putting components in their own solution creates a dependency that must be managed. When the Facilities Work Orders solution used RoomCapacity on a form, it came to depend on Lumenvale Facilities Controls, and the import order mattered: the controls solution first, then the solutions that use it. Lumenvale's pipelines already imported Lumenvale Core before Facilities and Registrar, and the controls solution took its place in that order.
Removing a component is harder than adding one. A managed solution cannot remove a component while any form still uses it, so retiring a component means first changing every form back to the standard control, releasing that change, and only then removing the component. Wiremu wrote this down in the component's documentation, because the person who retires a component is rarely the person who built it.
Documentation for makers
Makers who add a component to a form need to know what it does without reading its code. Each component's page in the repository's docs folder described its purpose, each property and what to bind it to, the hosts it had been tested in, the minimum and maximum sensible sizes, its accessibility behaviour, and known limits, such as RoomCapacity's untested behaviour in canvas apps. Kwabena, who had no plans to write a component, said the page was the first time he understood what one could and could not do.
Common mistakes
MistakeMoving the temporary solution created by pac pcf push to other environments.
InsteadUse pac pcf push only in a developer environment; release through a solution project and pipelines.
MistakeLeaving the manifest version unchanged.
InsteadIncrease it with every change, and check it in the build.
MistakeTesting only in the harness.
InsteadAdd unit tests in the build and UI tests in the app with Playwright.
MistakeRenaming or removing properties in an update.
InsteadTreat property names as a contract; add optional properties instead.
MistakeKeeping the only source on one developer's machine.
InsteadCommit component and solution projects to source control and build them in a pipeline.
Rupert left the session satisfied. RoomCapacity was in a solution project in the facilities repository, built by GitHub Actions in Release configuration, with unit tests and one Playwright test, and with a version check. It would reach Facilities Test with the next release of Lumenvale Facilities Controls. Production waited for the RoomPicker work, so both controls would arrive together.
Summary and key terms
- pac pcf push is the fast development path into a developer environment, using a temporary solution that should not be moved on.
- The release path uses a solution project: pac solution init, pac solution add-reference and a Release build that produces solution files for pipelines.
- Add components to forms in the form designer and to canvas apps through Get more components once the environment allows code components.
- Test logic with unit tests, drawing in the harness, behaviour in the app with Playwright, and accessibility separately.
- Increase the manifest version with every change and the solution version with every release; never remove or rename properties.
- Use solution checker and dependency audits before import.
- pac pcf push
- A CLI command that builds a component and imports it into the connected environment in a temporary solution.
- Solution project
- A project created with pac solution init that builds referenced components into a solution file.
- pac solution add-reference
- A CLI command that adds a component project to a solution project.
- Release configuration
- The build setting that produces a production bundle, smaller and faster than the development build.
- Manifest version
- The version in the component manifest that must increase for the platform to use an updated bundle.
- Playwright
- A browser automation framework Microsoft recommends, with Power Platform samples, for UI testing of apps.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Why should the temporary solution from pac pcf push not be moved to test or production?
Show answer
It exists only to get the control into a developer environment quickly; releases should come from a solution project built repeatably and moved by pipelines.
Which three commands create a solution project, reference a component and build it?
Show answer
pac solution init, pac solution add-reference and dotnet build (in Release configuration).
What happens if a component's manifest version is not increased?
Show answer
Environments may keep serving the previous bundle, so the change does not appear.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.