Skip to content

Karma webserver fails to properly serve mp3 files #2320

Closed
@gregor

Description

For a few of our unit tests I tried to set up audio elements and play them. The promise that Chrome returns on HTMLAudioElement.play() returns always rejects with a 'no available source' error. As far as I can tell the Karma web server that I configured to serve my mp3 files using the files pattern and required proxy does not properly serve the file.

I then kept the karma webserver alive using the singleRun: false flag and tried to access the file directly from Chrome at http://localhost:9876/audio/{filename}.mp3.

Expected behavior

The browser should be able to play the sound.

Actual behavior

The mp3 file is found. Webserver therefore seems to be properly configured. It is never able to play the file though. Audio.readyState stays at 0: HAVE_NOTHING.

Comparing the request to the mp3 file with one to our regular dev environment that is opening up the server via grunt-contrib-connect I notice a few differences. The response headers include connection: closedespite a request for keep-alive. It is missing a content-length header but contains transfer-encoding: chunked.

Also the nocache option of the file pattern seems to be ignored as the mp3 is served with cache-control: no-cachand pragma: no-cache headers.

webserver

Enviroment Details

  • Karma version 1.2.0
  • Relevant part of your karma.config.js file
browsers: ['Chrome'],
files: [
      {pattern: 'audio/*.mp3', included: false, served: true, nocache: false}
    ],
proxies: {
      '/audio/': '/base/audio/'
},
singleRun: false

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions