diff --git a/.eslintrc b/.eslintrc.js similarity index 68% rename from .eslintrc rename to .eslintrc.js index f532699..d3cf5cb 100644 --- a/.eslintrc +++ b/.eslintrc.js @@ -1,4 +1,10 @@ -{ +const config = { + parserOptions: { + ecmaVersion: 2018, + }, + env: { + node: true, + }, "extends": [ "airbnb-base", "prettier" @@ -6,9 +12,6 @@ "plugins": [ "prettier" ], - "ecmaFeatures": { - "experimentalObjectRestSpread": true - }, "rules": { "prettier/prettier": [ "error", @@ -27,5 +30,16 @@ "exports": "always-multiline", "functions": "never" }] - } + }, + overrides: [ + { + files: ['**/*.d.ts'], + rules: { + strict: 'off', + 'no-var': 'off', + }, + }, + ] } + +module.exports = config diff --git a/babel.config.js b/babel.config.js index 15fae81..08865aa 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,14 +1,14 @@ -module.exports = (api) => { +module.exports = api => { api.cache(true) return { presets: [ [ '@babel/preset-env', { - loose: true, - targets: { - browsers: ['last 2 versions', 'IE >= 9'], - }, + loose: true, + targets: { + browsers: ['last 2 versions', 'IE >= 9'], + }, }, ], ], diff --git a/createWebpackConfig.js b/createWebpackConfig.js index 1cfde76..407d9df 100644 --- a/createWebpackConfig.js +++ b/createWebpackConfig.js @@ -11,7 +11,8 @@ module.exports = function createWebpackConfig(_options) { config = { context: options.context, entry: options.entry, - + mode: 'development', + devtool: 'inline-source-map', plugins: [ new webpack.optimize.OccurrenceOrderPlugin(), new webpack.DefinePlugin({ @@ -26,8 +27,8 @@ module.exports = function createWebpackConfig(_options) { }, module: { - loaders: [ - { test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ }, + rules: [ + { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ }, ], }, @@ -37,7 +38,7 @@ module.exports = function createWebpackConfig(_options) { }, resolve: { - extensions: ['', '.js'], + extensions: ['.js'], }, } diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 14b799d..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,95 +0,0 @@ -'use strict' - -/* eslint strict:0, no-var:0, func-names:0 */ -var path = require('path') -var gulp = require('gulp') - -var babel = require('gulp-babel') -var eslint = require('gulp-eslint') -var mocha = require('gulp-mocha') -var rimraf = require('rimraf') -var webpack = require('webpack-stream') - -var KarmaServer = require('karma').Server - -var createWebpackConfig = require('./createWebpackConfig.js') - -// Initialize the babel transpiler so ES2015 files gets compiled -// when they're loaded -require('babel-core/register') - -gulp.task('clean', cb => { - rimraf('./dist', cb) -}) - -gulp.task('static', () => - gulp - .src(['*.js', 'lib/**/*.js', 'test/**/*.js']) - .pipe(eslint()) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()) -) - -gulp.task('test', ['test:karma', 'test:node']) - -gulp.task('test:node', () => - gulp.src('test/**/*.js').pipe(mocha({ reporter: 'dot' })) -) - -gulp.task('test:karma', done => { - new KarmaServer( - { - configFile: path.join(__dirname, 'karma.conf.js'), - singleRun: true, - }, - done - ).start() -}) - -gulp.task('babel', () => - gulp - .src('lib/**/*.js') - .pipe(babel()) - .pipe(gulp.dest('dist')) -) - -gulp.task('watch', () => { - gulp.start(['test:node']) - gulp.watch(['lib/**/*.js', 'test/**/*.js'], ['test:node']) - new KarmaServer({ - configFile: path.join(__dirname, 'karma.conf.js'), - }).start() -}) - -gulp.task('webpack', ['webpack:standalone', 'webpack:standalone:min']) - -gulp.task('webpack:standalone', () => { - var config = createWebpackConfig({ filename: 'updeep-standalone.js' }) - - return gulp - .src('lib/index.js') - .pipe(webpack(config)) - .pipe(gulp.dest('dist/umd/')) -}) - -gulp.task('webpack:standalone:min', () => { - var config = createWebpackConfig({ - filename: 'updeep-standalone.min.js', - minify: true, - env: 'production', - }) - - return gulp - .src('lib/index.js') - .pipe(webpack(config)) - .pipe(gulp.dest('dist/umd/')) -}) - -gulp.task('build', ['babel', 'webpack']) - -gulp.task('build:clean', ['clean'], done => { - gulp.start('build', done) -}) - -gulp.task('prepublish', ['build:clean']) -gulp.task('default', ['static', 'test']) diff --git a/karma.conf.js b/karma.conf.js index b5e17a7..a737e37 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -4,6 +4,22 @@ var createWebpackConfig = require('./createWebpackConfig') +var localLaunchers = { + ChromeNoSandboxHeadless: { + base: 'Chrome', + flags: [ + '--no-sandbox', + '--disable-setuid-sandbox', + // See https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md + '--headless', + '--disable-gpu', + '--no-gpu', + // Without a remote debugging port, Google Chrome exits immediately. + '--remote-debugging-port=9333', + ], + }, +} + module.exports = function(config) { config.set({ // base path that will be used to resolve all patterns (eg. files, exclude) @@ -13,10 +29,11 @@ module.exports = function(config) { // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['mocha'], - // list of files / patterns to load in the browser - files: [ - { pattern: 'test/**/*.js', watched: false, included: true, served: true }, - ], + mochaReporter: { + showDiff: true, + }, + + files: [{ pattern: 'test/**/*.js', watched: false }], // list of files to exclude exclude: [], @@ -24,20 +41,20 @@ module.exports = function(config) { // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { - 'test/**/*.js': ['webpack'], + 'test/**/*.js': ['webpack', 'sourcemap'], }, webpack: createWebpackConfig(), webpackMiddleware: { noInfo: true, - watch: true, + stats: 'errors-only', }, // test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['dots'], + reporters: ['mocha'], // web server port port: 9876, @@ -52,10 +69,7 @@ module.exports = function(config) { // start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: ['PhantomJS'], - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: false, + browsers: Object.keys(localLaunchers), + customLaunchers: localLaunchers, }) } diff --git a/lib/.eslintrc.js b/lib/.eslintrc.js new file mode 100644 index 0000000..ec9f788 --- /dev/null +++ b/lib/.eslintrc.js @@ -0,0 +1,13 @@ +module.exports = { + "extends": require.resolve("../.eslintrc"), + env: { + es6: true, + }, + "rules": { + "new-cap": [2, { + "capIsNewExceptions": [ + "Suite" + ] + }], + } +} diff --git a/lib/index.js b/lib/index.js index f2502cd..9130337 100644 --- a/lib/index.js +++ b/lib/index.js @@ -29,4 +29,4 @@ u.updateIn = updateIn u.omitted = omitted u.withDefault = withDefault -module.exports = u +export default u diff --git a/package.json b/package.json index acb9c38..c658b91 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,10 @@ ], "scripts": { "dtslint": "dtslint --localTs node_modules/typescript/lib types", - "test:mocha": "mocha --recursive --require \"@babel/register\" test", - "perf-server": "`npm bin`/webpack-dev-server --config perf/webpack.config.js --hot" + "lint": "npm run dtslint && eslint .", + "test": "npm run test:mocha && npm run test:karma", + "test:karma": "karma start karma.conf.js --single-run", + "test:mocha": "mocha --recursive --require \"@babel/register\" test" }, "license": "MIT", "bugs": { @@ -57,10 +59,9 @@ "karma-chrome-launcher": "^3.1.0", "karma-mocha": "^1.3.0", "karma-mocha-reporter": "^2.2.5", - "karma-phantomjs-launcher": "^1.0.4", + "karma-sourcemap-loader": "^0.3.7", "karma-webpack": "^4.0.2", "mocha": "^7.0.0", - "phantomjs-prebuilt": "^2.1.14", "prettier": "^1.1.0", "rimraf": "^3.0.0", "typescript": "^3.6.3", diff --git a/perf/.eslintrc b/perf/.eslintrc.js similarity index 61% rename from perf/.eslintrc rename to perf/.eslintrc.js index fa91c1b..808d2c5 100644 --- a/perf/.eslintrc +++ b/perf/.eslintrc.js @@ -1,5 +1,5 @@ -{ - "extends": "../.eslintrc", +module.exports = { + "extends": require.resolve("../.eslintrc"), "rules": { "new-cap": [2, { "capIsNewExceptions": [ diff --git a/perf/index.html b/perf/index.html index b1a7bdd..660cf8f 100644 --- a/perf/index.html +++ b/perf/index.html @@ -8,7 +8,7 @@
Done!