Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(karma): use Trusted Types policy when loading scripts for Karma
When the Karma plugin is used in a testing environment that enforces Trusted Types, its loadFile functionality currently fails due to a Trusted Types violation when assigning to script.textContent. This makes it impossible to use the plugin with integration tests that ensure an application is compatible with Trusted Types. This is fixed by creating a Trusted Types policy specifically for the Karma plugin, and use it to promote any loaded scripts to a TrustedScript before assigning to script.textContent. This is done in a way that is backwards compatible: - The policy is `null` in browsers that don't yet support Trusted Types, in which case the original script string is used as before. - When Trusted Types are supported in the browser but not enforced by the application, the browser treats the TrustedScript as if it were a string when it is assigned to script.textContent.
- Loading branch information