yeoman server:test and access to the app js files #443

Closed
sleeper opened this Issue Sep 14, 2012 · 14 comments

Projects

None yet

3 participants

@sleeper

Sorry for the lame question, but I did not manage to understand how the server:test (but alose the test) command works w/r to the app.

Reading the code it seems that server:test do "mount" the test directory and the temp directory.

However the temp directory is not created by default (i.e. you need to build to create it, and still it will create versioned js files).

Actually I do not understand how the server:test can have visibility on my app script.

Shouldn't the app directory be mounted instead of the temp one ?

@mklabs

Hi Frederick ,

You're absolutely true. The server:test profile right now doesn't serve the app/ dir. Actually, it was a bit naive and just change the default app/ root dir to the test/ one. And we'll most likely need to access the files that are within app/ to be able to test them.

I'm starting to think that on server:test profile, we actually need to "mount" everything, app/, temp/ and test/. With test/ configured first, so that we serve test/index.html instead of the app one.

@sindresorhus
Yeoman member

^ I agree.

@sleeper

Yeaahhh ... I wrapped my head this afternoon and was not sure to understand it ;)
Happy to see I got it ;)

@sleeper

I'm going to try to make it work and submit a pull request ;)

@sleeper

Also, what is the rationale behind "mounting" the temp directory ?
If I understand correctly, in the case of server:app we have:

  1. We ensure that the temp directory is removed (grunt.task.run('clean coffee compass open-browser');)
  2. We then "mount" it in the middleware

My understanding is that this process should be the same for server:test as we want to be sure coffee / compass are triggered before running our tests.
In the case of server:dist, I guess that we do not want to have temp mounted.

The special server:reload target is said to act as app, so I would tend to say that in this case in this not needed too ...

Am I missing something ?

@sleeper sleeper added a commit to sleeper/yeoman that referenced this issue Sep 14, 2012
@sleeper sleeper Attempt to fix Issue #443 9899556
@sleeper

As highlighted in Issue #459, I do think there's a flaw in the what we're mounting for a test server:

  • In the case of the server:test, we're mounting the test directory (and potentially with the fix the app one)
  • In the case of the test task, phantomjs has the view on the whole filesystem (although relative to the considered html file).

So, my point of view would be to say that if we do want to be coherent and have html file that can be used both through phantomjs and when displayed by a server:test, we should, for server:test task, mount the whole project directory, and load the test/index.html file in the browser.
So far this is the only way I can see to have a single html file that can serve both purposes.

What do you think of that ?

@mklabs

@sleeper I think it's a definitely valid concern. Actually, this is what we used to have before the changes related to compilation output (in temp/) and the bits of magic added to make server:app serve both directories.

@sleeper

OK, so I would propose the following:

  • server:app would mount temp and app
  • server:test would mount . (i.e the project directory)

This way, both the test and server:test would have the same "visibility' on the project.

Are you OK with this ? If yes, I'll update my commit to reflect this.

Regards
Fred

@mklabs

I like it. In the meantime, I'm checking and playing with your fix_server_test branch right now. I'm trying to make the phantomjs environment use our server:test environment.
(just testing with the mocha part, to redo with Jasmine) Files are loaded through the file:// protocol, funny enough you can trick the task by changing the config with:

  mocha: {
    // tests: ['tests/**/*.html'],
    tests: ['http://localhost:3501/index.html']
  }

If it works as expected, it should let us use the exact same runner for both environments, while still keeping that behaviour of serving both test/ and app/ as root directories.

I'm just struggling with the server task itself, to find a way to prevent the last task watch to be run. It's then a matter of aliasing test (internally or on purpose in user's gruntfile) to be something like: grunt.registerTask('test', 'server:test mocha');.

@sleeper

Good idea ... I saw that files were loaded though `file://' and didn't go further down the road ... Good to know you can overwrite this !

Regarding the last watch: I made the server:test use the same as the server:app as in dev mode, I'll need to have my modified scripts reloaded...
So I did not try this but if we set back to normal (i.e. only the server:app will run the coffe, compass and watch stuff, and play with aliasing for the server:test by itself ?

@mklabs

Confirmed! It worked.

I simply commented out the watch and open-task for now, and aliased test to run server:test mocha with the config posted above.

Maybe, we can add one more additional target, make the generators alias grunt.registerTask('test', 'server:phantom mocha'); (or do it internally, in one of our task file). And prevent both watch / open-browser task to run in this configuration (when target === 'phantom').

@sleeper

Congrats !!!!!
I'm going to give it a try tonight, and add the server:phantomjs as you proposed.

@sleeper

Ok. With this commit (rebased and stashed):

  • the server:test has visibility on temp, test and app, and run the watch and open-browser
  • a new target server:phantom that has the same visibility as server:test but does not run the watch and open-browser

I'm going to submit a PR on the generator repo to alias the test target to server:phantom <which ever test framework you're using>.

@sleeper

Will also fix #438 (after a change in the Gruntfile)

@sleeper sleeper added a commit to sleeper/yeoman that referenced this issue Sep 23, 2012
@sleeper sleeper Attempt to fix Issue #443
It ensure that:
  - the server:test have visibility on test, temp and app directories
  - the test target is first launching a server dedicated to phantom
e8704ea
@sleeper sleeper closed this Oct 13, 2012
@szinya szinya pushed a commit to menthainternet/yeoman that referenced this issue Sep 17, 2014
@sleeper sleeper Attempt to fix Issue #443
It ensure that:
  - the server:test have visibility on test, temp and app directories
  - the test target is first launching a server dedicated to phantom
b30fd28
@sleeper sleeper added a commit that referenced this issue Apr 24, 2015
@sleeper sleeper Attempt to fix Issue #443
It ensure that:
  - the server:test have visibility on test, temp and app directories
  - the test target is first launching a server dedicated to phantom
0997248
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment