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

feat(middleware): added manual file type option #2846

Merged
merged 7 commits into from
Nov 21, 2017
Merged

feat(middleware): added manual file type option #2846

merged 7 commits into from
Nov 21, 2017

Conversation

josh18
Copy link
Contributor

@josh18 josh18 commented Oct 20, 2017

Adds a manual file type so that users can instruct Karma which method to use when loading a file without an extension (such as Google font files)

Example:

files: [
    {
        pattern: 'https://fonts.googleapis.com/icon?family=Material+Icons',
        type: 'css'
    }
]

Fix for #2824

First time working karma so let me know if there are any changes I need to make.

Adds a manual file type so that users can instruct Karma which method to use when loading a file without an extension (such as Google font files)
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@josh18
Copy link
Contributor Author

josh18 commented Oct 20, 2017

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

Copy link
Member

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this looks like a good idea. A couple of things

  1. could you update the docs please to include this
  2. lets also add a script type for script files
  3. can you add some validation to the type in the pattern, such that it logs a warning on unknow types?

@josh18
Copy link
Contributor Author

josh18 commented Oct 25, 2017

  1. Sure thing
  2. As this is the default is this necessary? Or are you just thinking of adding it to the validation in (3)?
  3. Will do, what would I use to log it? Just something like log.warn()?

Another thing I was just thinking of is if it should be fileExt === '.css' || fileType === 'css' (can't override file extension) or (fileExt === '.css' && !fileType) || fileType === 'css' (fileType always overrides extension). This would make (2) more necessary

scriptTags.push(util.format(LINK_TAG_CSS, filePath))
continue
}

if (fileExt === '.html') {
if (fileExt === '.html' || fileType === 'html') {
scriptTags.push(util.format(LINK_TAG_HTML, filePath))
continue
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 208, scriptType should be fileType || SCRIPT_TYPE[fileExt] || 'text/javascript'. I think that would let us strip the code out of #2834 and just merge its tests.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub sadly wouldn't let me comment on the correct line.

scriptTags.push(util.format(LINK_TAG_CSS, filePath))
continue
}

if (fileExt === '.html') {
if (fileExt === '.html' || fileType === 'html') {
scriptTags.push(util.format(LINK_TAG_HTML, filePath))
continue
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub sadly wouldn't let me comment on the correct line.

@josh18
Copy link
Contributor Author

josh18 commented Oct 30, 2017

Made some changes, let me know what you think.

  • File type overrides extension
  • Added script file types (including esModule)
  • Added file type validation
  • Added file type documentation
    • Renamed one instance of Possible values -> Possible Values for consistency
    • Removed extra white space (done automatically by my editor, not sure if you want to keep this change)

'html',
'js',
'dart',
'esModule'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is total bikeshedding, but this could be more simply called module. It removes the only camel-cased option, and makes the API more consistent with the browser: type: 'module'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine I was just copying from the previous PR but I think 'module' is better. Fixed now

@@ -425,7 +425,7 @@ httpsServerOptions: {

**CLI:** `--log-level debug`

**Possible values:**
**Possible Values:**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull requests usually follow the mantra "one idea -> one PR". This correction should probably have been a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, sorry about that. Reverted now. Should I squash all my commits?

@dignifiedquire dignifiedquire merged commit 0330cd1 into karma-runner:master Nov 21, 2017
@dignifiedquire
Copy link
Member

Thank you :octocat:

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

Successfully merging this pull request may close these issues.

4 participants