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

reset mime-types #124

Closed
dotnetCarpenter opened this issue May 11, 2015 · 7 comments
Closed

reset mime-types #124

dotnetCarpenter opened this issue May 11, 2015 · 7 comments
Labels

Comments

@dotnetCarpenter
Copy link

I'm writing unit tests for ecstatic's new custom mime-type feature and can't do a proper teardown between tests due to a number of reasons. But the main one, that stops me right now, is that mime doesn't have a reset-mime-types function.

I can do mime = new mime.Mime(); but that doesn't load the default types.

// Define built-in types
mime.define(require('./types.json'));

// Default type
mime.default_type = mime.lookup('bin');

Could you add a reset-mime-types function, please?

@Hypercubed
Copy link

Can be solved by #129

@dotnetCarpenter
Copy link
Author

@Hypercubed you mean I should use https://github.com/Hypercubed/node-mime?

@Hypercubed
Copy link

Your use case (feel free to correct me) is that you would like an mime lookup instance that includes the default types, expand the default types using mime.define, then later be able to create a new instance with only the default types not your additional defintions.

The main node-mime fork has two options:

  1. Use the default instance using var mime = require('mime').
  2. Create a new instance var mime = new require('mime').Mime() that does not include the default mime types.

This is an all or noting approach. # 1 includes the default types but since this is a singleton and addition definitions are global and cannot be reset. # 2 is a instance that you can expand with your types, destroy when done, then create a new instance. However, this instance lacks the default types.

My suggestion in https://github.com/Hypercubed/node-mime is to separate the db from the API. So you can do this:

var MimeLookup = require('mime-lookup');                           // load the class constructor
var mime = new MimeLookup (require('mime-db'));             // load the default types.

Teardown between tests would mean creating a new instance. I will likely make my version of node-mime a separate module (perhaps mime-lookup) but I am waiting for feedback from @broofa .

@broofa broofa added the V2 label Jun 15, 2017
@broofa
Copy link
Owner

broofa commented Jun 15, 2017

I know it's been a while, my apologies. I like this idea for v2. I'll figure something out for v2.

@broofa
Copy link
Owner

broofa commented Sep 15, 2017

v2 is out. index.js shows how to build the default mime object. Should be pretty straight-forward to address this in your tests.

Edit: See comment below

@broofa broofa closed this as completed Sep 15, 2017
@broofa
Copy link
Owner

broofa commented Sep 20, 2017

My apologies. index.js is misleading as it's using local paths to the types files. To create your own fresh mime instance with all of the type definitions:

const Mime = require('mime/Mime');
const mime = new Mime(require('mime/types/standard'), require('mime/types/other'));

@perrosen
Copy link

Just a note for anyone else coming across this issue. I needed to add the .json extension for webpack to find the types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants