Skip to content

Commit

Permalink
Support Ember CLI >= 3.25.1 (#197)
Browse files Browse the repository at this point in the history
* Update nonce matching to reflect updates to test-body-footer in https://github.com/ember-cli/ember-cli/pull/9467/files
* Apply for Ember CLI >= 3.25.1 only
  • Loading branch information
snewcomer authored Apr 16, 2021
1 parent 8f2bb08 commit a744b2e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,23 @@ module.exports = {

// Add nonce to <script> tag inserted by Ember CLI to assert that test file was loaded.
if (type === 'test-body-footer') {
let emberCliDependency = new VersionChecker(this.project).for(
'ember-cli'
);

existingContent.forEach((entry, index) => {
if (
/<script>\s*Ember.assert\(.*EmberENV.TESTS_FILE_LOADED\);\s*<\/script>/.test(
let result;
if (emberCliDependency.exists() && emberCliDependency.lt('3.25.1')) {
result = /<script>\s*Ember.assert\(.*EmberENV.TESTS_FILE_LOADED\);\s*<\/script>/.test(
entry
);
} else {
result = /<script>.*?Ember\.assert\(.*EmberENV\.TESTS_FILE_LOADED\);\s*}\);<\/script>/.test(
entry
)
) {
);
}

if (result) {
existingContent[index] = entry.replace(
'<script>',
'<script nonce="' + STATIC_TEST_NONCE + '">'
Expand Down

0 comments on commit a744b2e

Please sign in to comment.