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

Target multiple plattforms (node, browser) using a bundler (Browserify) #53

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage
node_modules
browser
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.log
*.gz

.cache
node_modules
package-lock.json
coverage
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ before_install:
# Setup Node.js version-specific dependencies
- "test $TRAVIS_NODE_VERSION != '0.6' || npm rm --save-dev istanbul"
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
# ddd browser testing just in node version 6
- "test $TRAVIS_NODE_VERSION == '6.13' || npm rm --save-dev chai karma karma-chai karma-chrome-launcher karma-firefox-launcher karma-mocha karma-spec-reporter parcel"
- "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev $(grep -E '\"eslint\\S*\"' package.json | cut -d'\"' -f2)"
# Update Node.js modules
- "test ! -d node_modules || npm prune"
- "test ! -d node_modules || npm rebuild"
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
script:
# Run test script, depending on istanbul install
- "test ! -z $(npm -ps ls istanbul) || npm test"
- "test -z $(npm -ps ls istanbul) || npm run-script test-travis"
# test in browser if karma available
- "test $TRAVIS_NODE_VERSION != '6.13' || npm run-script test-browser"
- "test -z $(npm -ps ls eslint ) || npm run-script lint"
after_script:
- "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

13 changes: 13 additions & 0 deletions browser/index.js

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Karma configuration
// Generated on Sun May 20 2018 18:22:29 GMT+0200 (CEST)

module.exports = function (config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai'],

// list of files / patterns to load in the browser
files: [
'browser/index.js',
'test/test.js'
],

// list of files / patterns to exclude
exclude: [
],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['spec'],

// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
21 changes: 17 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,40 @@
"mime-db": "~1.33.0"
},
"devDependencies": {
"chai": "4.1.2",
"eslint": "3.19.0",
"eslint-config-standard": "10.2.1",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-node": "5.2.1",
"eslint-plugin-promise": "3.6.0",
"eslint-plugin-standard": "3.0.1",
"istanbul": "0.4.5",
"mocha": "1.21.5"
"karma": "2.0.2",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-firefox-launcher": "1.1.0",
"karma-mocha": "1.3.0",
"karma-spec-reporter": "0.0.32",
"mocha": "1.21.5",
"parcel": "1.8.1"
},
"files": [
"HISTORY.md",
"LICENSE",
"index.js"
"index.js",
"browser/index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"build-browser": "parcel build index.js --out-dir browser/ --global mime-types --no-source-maps",
"lint": "eslint .",
"test": "mocha --reporter spec test/test.js",
"test": "npm run test-node",
"pretest-browser": "npm run build-browser",
"test-browser": "node_modules/karma/bin/karma start",
"test-node": "mocha --reporter spec test/test.js",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/test.js",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot test/test.js"
}
}
}
11 changes: 9 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

var assert = require('assert')
var mimeTypes = require('..')
var mimeTypes

// check if browser or node enviroment
if (typeof window !== 'undefined') {
mimeTypes = window['mime-types']
} else {
var assert = require('assert')
mimeTypes = require('..')
}

describe('mimeTypes', function () {
describe('.charset(type)', function () {
Expand Down