Repository: psychopy/psychopy

Issue:
Mismatching filenames and experiment names cause online studies to fail
When users change the experiment name (e.g., to ```myExp```) in experiment settings to one that is different from the original filename (e.g., ```myOriginalName.psyexp```), the HTML file calls a JavaScript file by the experiment name defined in the  experiment settings e.g., ```myExp.js```, however the actual JavaScript file has the same name as the psyexp file (```myOriginalName.js```).

For solutions:
1) We could instead populate HTML and JS outputs using the psyexp filename
2) Write the JS output scripts using filenames created from experiment settings exp. name
3) Make experiment name field immutable
4) Warn the participant of what is happening, but do nothing



Discussion:
I think option 1. It's confusing if the filenames are different for the python and JS files.

I think we should still allow the experiment name to differ (although by default it tries to track the filename). I might use something in that field that's easier to read (e.g. with punctuation) even though I wouldn't personally do that in the filename.


Resolving patch:
diff --git a/psychopy/experiment/components/settings/__init__.py b/psychopy/experiment/components/settings/__init__.py
--- a/psychopy/experiment/components/settings/__init__.py
+++ b/psychopy/experiment/components/settings/__init__.py
@@ -495,11 +495,11 @@ def copyFileWithMD5(src, dst):
     def writeInitCodeJS(self, buff, version, localDateTime, modular=True):
         # create resources folder
         self.prepareResourcesJS()
-
+        jsFilename = os.path.basename(os.path.splitext(self.exp.filename)[0])
         # html header
         template = readTextFile("JS_htmlHeader.tmpl")
         header = template.format(
-            name=self.params['expName'].val,  # prevent repr() conversion
+            name=jsFilename,
             version=version,
             params=self.params)
         jsFile = self.exp.expPath
@@ -511,11 +511,11 @@ def writeInitCodeJS(self, buff, version, localDateTime, modular=True):
         html.close()
 
         # Write header comment
-        starLen = "*"*(len(self.params['expName'].val)+9)
+        starLen = "*"*(len(jsFilename) + 9)
         code = ("/%s \n"
                " * %s Test *\n" 
                " %s/\n\n")
-        buff.writeIndentedLines(code % (starLen, self.params['expName'].val.title(), starLen))
+        buff.writeIndentedLines(code % (starLen, jsFilename.title(), starLen))
 
         # Write imports if modular
         if modular:
@@ -532,9 +532,9 @@ def writeInitCodeJS(self, buff, version, localDateTime, modular=True):
         # Write window code
         self.writeWindowCodeJS(buff)
         code = ("\n// store info about the experiment session:\n"
-                "let expName = %s;  // from the Builder filename that created this script\n"
+                "let expName = '%s';  // from the Builder filename that created this script\n"
                 "let expInfo = %s;\n"
-                "\n" % (self.params['expName'], self.getInfo()))
+                "\n" % (jsFilename, self.getInfo()))
         buff.writeIndentedLines(code)
 
     def writeExpSetupCodeJS(self, buff, version):


Test patch: