Skip to content

Conversation

hmil
Copy link
Contributor

@hmil hmil commented Mar 21, 2016

In some scenarios, one may need the runtime files to be served over http:// instead of file:// (ie. to bypass cross origin request security).

In this first attempt, I created a new trait for file materializer which also provide an absolute access url for materialized files. This allows to encapsulate the "absolutePath" function together with the materializer. This trait has two direct implementations. One which is a refactoring of the current code (for the scenario where you don't care how selenium gets its runtime files, you just want it to work). The other one allows to customize the location where files get saved and the actual URL used by selenium to access them.

At usage it is pretty nice:

jsSettings(
  jsEnv := new SeleniumJSEnv(org.scalajs.jsenv.selenium.Firefox)
      // materializes files in the .tmp directory which is served over http by an external program
      .withMaterializer(new SpecificFileMaterializer(".tmp", "http://localhost:8080"))
)

The main problem I see with this approach is that my FileMaterializer trait is pretty redundant with respect to the VirtualFileMaterializer class. I suppose a cleaner approach would be to push all of this logic upstream such that VirtualFileMaterializer is the trait with two children and it exposes the getAbsolutePath method.

@hmil hmil force-pushed the configurable-protocol branch from 1bc1b2c to 88e5aed Compare March 22, 2016 12:44
@nicolasstucki
Copy link
Contributor

You will need to add some tests that can be run on the CI.


/**
* Materializes virtual files in a temporary directory and links to them
* via file://
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should be formatted as follows.

/** Materializes virtual files in a temporary directory and links to them
 *  via file://
 */

@nicolasstucki
Copy link
Contributor

The code logic looks good to me, but we really need to test it on the CI.
That's all.

@hmil
Copy link
Contributor Author

hmil commented Mar 23, 2016

Not sure how to test the feature exactly. I added a new target seleniumJSHttpEnv using the SpecificFileMaterializer and running one test which makes sure the script is served over HTTP.
I also added a python command to serve the files over http on travis.

I noticed there is no '.idea/' in the .gitignore, shall this be added ?

@hmil hmil force-pushed the configurable-protocol branch from 892f8d2 to a95ab34 Compare March 23, 2016 13:59
@sjrd
Copy link
Member

sjrd commented Mar 23, 2016

I noticed there is no '.idea/' in the .gitignore, shall this be added ?

No. You should add that to your global .gitignore file, so that it applies only on machine, but to all your projects.


private val materializer = new VirtualFileMaterializer(true)

override def materialize(vf: VirtualTextFile): Unit = materializer.materialize(vf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, but needs verification, that it would be better if this method returned a URL, and getAbsolutePath was removed.

@hmil hmil force-pushed the configurable-protocol branch from a95ab34 to 60c805a Compare March 25, 2016 16:53
- sbt ++$TRAVIS_SCALA_VERSION seleniumJSEnvTest/run seleniumJSEnvTest/test 'set scalaJSStage in Global := FullOptStage' seleniumJSEnvTest/run seleniumJSEnvTest/test
- sbt ++$TRAVIS_SCALA_VERSION 'set inScope(ThisScope in seleniumJSEnvTest)(jsEnv := new org.scalajs.jsenv.selenium.SeleniumJSEnv(org.scalajs.jsenv.selenium.Firefox).withKeepAlive())' seleniumJSEnvTest/run seleniumJSEnvTest/test 'set scalaJSStage in Global := FullOptStage' seleniumJSEnvTest/run seleniumJSEnvTest/test
- sbt ++$TRAVIS_SCALA_VERSION seleniumJSHttpEnvTest/test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add fullOpt to the tests:

- sbt ++$TRAVIS_SCALA_VERSION seleniumJSHttpEnvTest/test 'set scalaJSStage in Global := FullOptStage' seleniumJSHttpEnvTest/test

@nicolasstucki
Copy link
Contributor

That is all.

@nicolasstucki
Copy link
Contributor

Could you also change the commit message to Fix #22: Implement mechanism to serve files via custom protocols. with no additional description.

@hmil hmil force-pushed the configurable-protocol branch from 60c805a to 8ec743d Compare March 29, 2016 19:11
@hmil
Copy link
Contributor Author

hmil commented Mar 29, 2016

All done, thanks for the review.

@nicolasstucki
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants