DEV: Stop loading external scripts while running tests (#81)

DEV: Stop loading external scripts while running tests (#81)

  • DEV: Stop loading external scripts while running tests

  • Revert “Turn of CSP for tests”

This reverts commit db1bf99277b18fae53201bd18bbaabe9f3680dfa. It had no effect, since CSP is set by the server, and this was only affecting the client

diff --git a/assets/javascripts/discourse/components/adbutler-ad.js.es6 b/assets/javascripts/discourse/components/adbutler-ad.js.es6
index a54414a..6743e36 100644
--- a/assets/javascripts/discourse/components/adbutler-ad.js.es6
+++ b/assets/javascripts/discourse/components/adbutler-ad.js.es6
@@ -72,6 +72,10 @@ export default AdComponent.extend({
   },
 
   _triggerAds() {
+    if (Ember.testing) {
+      return; // Don't load external JS during tests
+    }
+
     loadAdbutler().then(
       function() {
         if (this.divs.length > 0) {
diff --git a/assets/javascripts/discourse/components/google-adsense.js.es6 b/assets/javascripts/discourse/components/google-adsense.js.es6
index e9041fb..5b10784 100644
--- a/assets/javascripts/discourse/components/google-adsense.js.es6
+++ b/assets/javascripts/discourse/components/google-adsense.js.es6
@@ -135,6 +135,10 @@ export default AdComponent.extend({
   },
 
   _triggerAds() {
+    if (Ember.testing) {
+      return; // Don't load external JS during tests
+    }
+
     this.set("adRequested", true);
     loadAdsense().then(function() {
       const adsbygoogle = window.adsbygoogle || [];
diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6
index 3df8126..cd94b66 100755
--- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6
+++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6
@@ -367,6 +367,10 @@ export default AdComponent.extend({
 
   @on("didInsertElement")
   _initGoogleDFP() {
+    if (Ember.testing) {
+      return; // Don't load external JS during tests
+    }
+
     if (!this.get("showAd")) {
       return;
     }
diff --git a/test/javascripts/acceptance/adsense-test.js.es6 b/test/javascripts/acceptance/adsense-test.js.es6
index 545666f..118b8d4 100644
--- a/test/javascripts/acceptance/adsense-test.js.es6
+++ b/test/javascripts/acceptance/adsense-test.js.es6
@@ -18,8 +18,7 @@ acceptance("AdSense", {
     adsense_mobile_post_bottom_ad_size: "300*250 - medium rectangle",
     adsense_nth_post_code: 6,
     adsense_topic_above_post_stream_code: "above_post_stream_ad_unit",
-    adsense_topic_above_post_stream_ad_sizes: "728*90 - leaderboard",
-    content_security_policy: false
+    adsense_topic_above_post_stream_ad_sizes: "728*90 - leaderboard"
   },
   site: {
     house_creatives: {
diff --git a/test/javascripts/acceptance/dfp-test.js.es6 b/test/javascripts/acceptance/dfp-test.js.es6
index 9c92701..26339b3 100644
--- a/test/javascripts/acceptance/dfp-test.js.es6
+++ b/test/javascripts/acceptance/dfp-test.js.es6
@@ -18,8 +18,7 @@ acceptance("DFP Ads", {
     dfp_mobile_post_bottom_ad_size: "300*250 - medium rectangle",
     dfp_nth_post_code: 6,
     dfp_topic_above_post_stream_code: "list_top_ad_unit",
-    dfp_topic_above_post_stream_ad_sizes: "728*90 - leaderboard",
-    content_security_policy: false
+    dfp_topic_above_post_stream_ad_sizes: "728*90 - leaderboard"
   },
   site: {
     house_creatives: {

GitHub sha: cf27a7be