twolfson / grunt-curl

Download files from the internet via grunt.
The Unlicense
73 stars 28 forks source link

Tests assume localhost #18

Closed hpurmann closed 10 years ago

hpurmann commented 10 years ago

I just forked this repo and tried to run the Gruntfile in the test folder. I got this:

Running "clean:test" (clean) task
Cleaning actual/...OK

Running "curl:js" (curl) task
File "actual/file.js" created.

Running "curl:zip" (curl) task
File "actual/file.zip" created.

Running "curl:post" (curl) task
Warning: connect ECONNREFUSED Use --force to continue.

Aborted due to warnings.

Looking at 'curl-dir':post in the grunt.js file I saw that you assume a file at http://localhost:4000/post.txt Why? I think all test tasks should pass after I just forked it.

twolfson commented 10 years ago

It starts a server during testing

https://github.com/twolfson/grunt-curl/blob/1.4.0/test/curl_test_content.js#L28-L39

Let's get the obvious parts out of the way:

hpurmann commented 10 years ago

Ah sorry, I didn't saw this. But the problem remains: It doesn't start a server for me.

twolfson commented 10 years ago

Hmmm, have you ever removed localhost from your /etc/hosts? It is usually a default on most machines.

# Linux/OSX
cat /etc/hosts

# Windows: Open in notepad.exe
C:\WIndows\system32\drivers\etc\hosts

http://en.wikipedia.org/wiki/Hosts_%28file%29

hpurmann commented 10 years ago

I'm getting

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0 localhost

Seems ok, doesn't it?

twolfson commented 10 years ago

Yea, it does =_=

Let's perform a sanity check. serve is a CLI tool that hosts a directory on a local web server. Please install serve globally

npm install -g serve

https://www.npmjs.org/package/serve

Then, run it locally and try accessing these various URLs:

serve .

http://localhost:3000/ http://127.0.0.1:3000/ http://0.0.0.0:3000/

hpurmann commented 10 years ago

Sorry, that I answer so late now. serve works well.

twolfson commented 10 years ago

All of the 3 URLs worked?

hpurmann commented 10 years ago

Yes

twolfson commented 10 years ago

I am afraid I am out of ideas o_o

The next step would be to strip away code pieces until we are left with nothing but the failing test. Can you move your outline.yml to:

- 'grunt curl':
  - 'using POST':
    - 'is successful'

You might see some warnings about unused keys but ignore them.

hpurmann commented 10 years ago

Where is this outline file? Sorry for that probably dumb question but I couldn't find it.

twolfson commented 10 years ago

No worries, this uses a non-canonical testing framework, doubleshot. I was going through an experimentation phase.

https://github.com/twolfson/doubleshot

The outline can be found here in test/curl_test_outline.yml:

https://github.com/twolfson/grunt-curl/blob/1.4.0/test/curl_test_outline.yml

hpurmann commented 10 years ago

Ok I deleted everything in curl_test_outline.yml and added your lines but nothing changed. Does the content of the file actually affects the outcome of the test?

twolfson commented 10 years ago

No, it was just to run the test in isolation. If you were to adjust the outline to everything but the failing test, it should pass.

# Clean up the test directory
- 'A clean test directory':
  - 'is clean'
# curl tests
- 'grunt curl':
  - 'downloading a js (utf16) file':
      - 'is successful'
  - 'downloading a zip (binary) file':
      - 'is successful'
  - 'downloading a file from an invalid domain':
      - 'throws an error'
      - 'does not create the file'
  - 'downloading a nonexistant file':
      - 'throws an error'
      - 'does not create the file'
  - 'downloading a POST file':
    - 'is successful'
# curl-dir tests
- 'grunt curl-dir':
  - 'downloading multiple files':
    - 'is successful'
  - 'downloading brace expanded files':
    - 'is successful'
  - 'using a custom router':
    - 'is successful'

I am realizing that no other tests use a local express server and wonder if it has anything to do with that.

twolfson commented 10 years ago

Going to rewrite test suite as I am trying to move away from doubleshot. Then, going to add a test for GET against a local server.

This probably won't change anything but it might allow us to debug easier.

twolfson commented 10 years ago

Alright, transitioned onto mocha in 1.5.0. Adding local GET test now.

twolfson commented 10 years ago

In 1.5.1 I have added a local GET test. Please pull that down and try to run them.

hpurmann commented 10 years ago

I pulled down your commits and it says that no clean targets were found. As I deleted the invocation of clean it gave me the same error again:

Running "curl:js" (curl) task
File "actual/file.js" created.

Running "curl:zip" (curl) task
File "actual/file.zip" created.

Running "curl:get" (curl) task
Warning: connect ECONNREFUSED Use --force to continue.

Aborted due to warnings.
twolfson commented 10 years ago

Alright, I think I know the issue. You are attempting to run the tests via grunt or some variation but that is not how we test in this repo. We test via npm test. If you follow the instructions below, the tests should work:

# Clone repo
git clone https://github.com/twolfson/grunt-curl
cd grunt-curl/

# Install dependencies
npm install

# Run tests
npm test

The output should look like:

$ npm test

> grunt-curl@1.5.1 test /Users/todd/github/grunt-curl
> rm -r test/actual 2> /dev/null; mocha

  ․․․․․․․․․․․․․․․

  15 passing (8s)
hpurmann commented 10 years ago

Oh ok! I always thought of testing with the grunt command in the test folder. Sorry that I wasted your time, npm test works like a charm!