jescalan / roots

a toolkit for rapid advanced front-end development
http://roots.netlify.com/
Other
1.45k stars 132 forks source link

Make Browsersync configurable #733

Open calebeby opened 8 years ago

calebeby commented 8 years ago

Browsersync is now configurable by:

browsersync:
  snippetOptions:
    rule:
      match: /<\/head>/i,
        fn: (snippet, match) ->
          return snippet + match
  ui:
    port: 8081

NOTE: I have not added tests for this, do I need to? If so, where?

calebeby commented 7 years ago

@jescalan can you look at this?

jescalan commented 7 years ago

Hi @calebeby! Sorry for the delay, I've been tied up with some projects recently. This looks good, could you add a simple test to verify that it's working, potentially?

calebeby commented 7 years ago

I haven't written tests before, is it documented how to do this?

calebeby commented 7 years ago

In which file are the tests for the server?

jescalan commented 7 years ago

@calebeby this is probably the closest match. this is a pretty tough test to start on - let me know if it's too confusing!

https://github.com/jescalan/roots/blob/master/test/watcher.coffee

calebeby commented 7 years ago

Here's the plan:

Which feature of Browsersync would be easiest to test? There is a list of them here. I was thinking the UI address, but I don't see a http request tester in mocha. We would have to do something like this.

What do you think?

jescalan commented 7 years ago

@calebeby so really the only thing you need to test is that the options are being passed through to browsersync correctly. they have tests for their own features, we just need to be sure the configuration is being passed to it!

calebeby commented 7 years ago

In the watcher.coffee file is it using the compile/basic fixture? That fixture does not have an app.coffee. Should I add one, or make a new fixture? If I make a new fixture, how is the fixture started by the test? How do I check variables in local_server.coffee from within the test?

Wow. I have a lot of questions today :smile:

jescalan commented 7 years ago

@calebeby So it will use whatever fixture you pass in when initializing the watcher class seen here, which for the existing test is basic.

If you need a new app.coffee, you're welcome to make a new fixture and pass that in, or you can pass your config options to the roots class when you initialize it, see js api docs

To check the variables passed through the internals, you can use the mockery package, you can see it at work in the CLI tests here. I think the approach here would be to replace browserify with a mock, then check the config coming into it through the mock

Hope this helps, and fire away with any more questions! This is definitely on the more complex end of tests that could be written, so big props for jumping in and going for it 😁