Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird static files behaviour with and without --port #69

Closed
axelpale opened this issue Dec 2, 2017 · 7 comments
Closed

Weird static files behaviour with and without --port #69

axelpale opened this issue Dec 2, 2017 · 7 comments

Comments

@axelpale
Copy link
Contributor

axelpale commented Dec 2, 2017

Consider a test suite test/static.test.js below. It contains single test case where a static image is fetched and response headers and body inspected.

var test = require('tape')

test('test static', function (t) {
  window.fetch('image.png').then(function (response) {
    if (response.ok) {
      console.log(Array.from(response.headers.entries()))
      response.text().then(function (text) {
        console.log(text)
      })
      return t.end()
    }
    return t.end(new Error('Fetch not successful'))
  }).catch(function (err) {
    t.end(err)
  })
})

Assume test/assets/image.png is a valid PNG image. Let us run the suite. Output indicates that the response contains a HTML document and not a trace of image.png:

$ browserify test/static.test.js | tape-run --static test/assets | tap-spec

  test static

    [ [ 'connection', 'keep-alive' ],
      [ 'content-length', '83' ],
      [ 'content-type', 'text/html' ],
      [ 'date', 'Sat, 02 Dec 2017 15:57:43 GMT' ] ]
    <!DOCTYPE html><meta charset="utf8"><body><script src="/bundle.js"></script></body>


  total:     0
  passing:   0
  duration:  2.9s

However, if we replace --static test/assets flag with --port 8000 the response suddenly contains the image.png. This makes no sense!

$ browserify test/static.test.js | tape-run --port 8000 | tap-spec

  test static

    cache-control,max-age=3600,content-length,155264,content-type,image/png; charset=utf-8,date,Sat, 02 Dec 2017 15:48:51 GMT,etag,"45643276-155264-"2017-12-02T15:23:13.000Z"",last-modified,Sat, 02 Dec 2017 15:23:13 GMT,server,ecstatic-2.2.1
    �PNG
    
IHD�?1
��wTS��Ͻ7��" %�zfileH    �;HQ�
    ...

This might have something to do with #61 that also deals with unexpected behavior with --port'.

In addition, if --node is added, a TypeError: Failed to fetch is thrown. I am becoming hopeless.

$ browserify test/static.test.js | tape-run --node --static test/assets | tap-spec

  test static


    ✖ TypeError: Failed to fetch
    -----------------------------
      operator: error
      expected: |-
        undefined
...
@axelpale
Copy link
Contributor Author

axelpale commented Dec 2, 2017

Additional note: running without any flags produces a result similar to --static test/assets:

$ browserify test/static.test.js | tape-run | tap-spec

  test static

    [ [ 'connection', 'keep-alive' ],
      [ 'content-length', '83' ],
      [ 'content-type', 'text/html' ],
      [ 'date', 'Sat, 02 Dec 2017 18:40:07 GMT' ] ]
    <!DOCTYPE html><meta charset="utf8"><body><script src="/bundle.js"></script></body>


  total:     0
  passing:   0
  duration:  3.4s

@axelpale
Copy link
Contributor Author

axelpale commented Dec 4, 2017

The issue is still on. However as a workaround, I use webpack with url-loader to preload static image files into the bundle as data URLs.

@juliangruber
Copy link
Collaborator

The problem is that the electron integration currently doesn't work with the static option. That was a yet unknown issue, I'll fix it now.

@juliangruber
Copy link
Collaborator

If you want to use browserify, you can also use brfs instead of the url-loader

@axelpale
Copy link
Contributor Author

axelpale commented Dec 4, 2017

@juliangruber Thanks, static files with electron would be very convenient. Great :)

@juliangruber
Copy link
Collaborator

3.0.1

@axelpale
Copy link
Contributor Author

axelpale commented Dec 5, 2017

Works great! Returns also 404 for missing files, as it should. I am using it with webpack-tape-run. Thanks to your diligence, I predict a good future for this module! Good job.

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

No branches or pull requests

2 participants