From bccd878d89d2e9d9b3ddbc8bde76420d0615b254 Mon Sep 17 00:00:00 2001 From: Jakub Strojewski Date: Sun, 18 Nov 2018 12:42:18 +0100 Subject: [PATCH 1/2] Better build test --- .eslintrc.json => .config/eslintrc.json | 0 .config/jasmine-prepublish-global.json | 6 ++++ .config/jasmine-prepublish.json | 6 ++++ .config/jasmine.json | 6 ++++ .config/karma-prepublish-browser.conf.js | 4 +++ karma.conf.js => .config/karma.conf.base.js | 17 +++------- .config/karma.conf.js | 5 +++ .config/tsconfig.json | 20 +++++++++++ .npmignore | 4 +-- package.json | 37 ++++++++++++--------- prepublish-test/browser-global.js | 8 +++++ prepublish-test/node-global.js | 11 ++++++ prepublish-test/node-regular.js | 10 ++++++ src/monet-pimp.js | 2 +- src/monet.js | 10 ++++-- test/matcher-helper.js | 5 +++ test/node-index.js | 15 +++++++++ tsconfig.json | 20 ----------- 18 files changed, 131 insertions(+), 55 deletions(-) rename .eslintrc.json => .config/eslintrc.json (100%) create mode 100644 .config/jasmine-prepublish-global.json create mode 100644 .config/jasmine-prepublish.json create mode 100644 .config/jasmine.json create mode 100644 .config/karma-prepublish-browser.conf.js rename karma.conf.js => .config/karma.conf.base.js (69%) create mode 100644 .config/karma.conf.js create mode 100644 .config/tsconfig.json create mode 100644 prepublish-test/browser-global.js create mode 100644 prepublish-test/node-global.js create mode 100644 prepublish-test/node-regular.js create mode 100644 test/node-index.js delete mode 100644 tsconfig.json diff --git a/.eslintrc.json b/.config/eslintrc.json similarity index 100% rename from .eslintrc.json rename to .config/eslintrc.json diff --git a/.config/jasmine-prepublish-global.json b/.config/jasmine-prepublish-global.json new file mode 100644 index 0000000..fab3fb7 --- /dev/null +++ b/.config/jasmine-prepublish-global.json @@ -0,0 +1,6 @@ +{ + "spec_files": [ + "prepublish-test/node-global.js" + ], + "oneFailurePerSpec": true +} diff --git a/.config/jasmine-prepublish.json b/.config/jasmine-prepublish.json new file mode 100644 index 0000000..d7ce48b --- /dev/null +++ b/.config/jasmine-prepublish.json @@ -0,0 +1,6 @@ +{ + "spec_files": [ + "prepublish-test/node-regular.js" + ], + "oneFailurePerSpec": true +} diff --git a/.config/jasmine.json b/.config/jasmine.json new file mode 100644 index 0000000..7994712 --- /dev/null +++ b/.config/jasmine.json @@ -0,0 +1,6 @@ +{ + "spec_files": [ + "test/node-index.js" + ], + "oneFailurePerSpec": true +} diff --git a/.config/karma-prepublish-browser.conf.js b/.config/karma-prepublish-browser.conf.js new file mode 100644 index 0000000..d49f408 --- /dev/null +++ b/.config/karma-prepublish-browser.conf.js @@ -0,0 +1,4 @@ +module.exports = require('./karma.conf.base')([ + 'dist/monet.js', + 'prepublish-test/browser-global.js' +]) diff --git a/karma.conf.js b/.config/karma.conf.base.js similarity index 69% rename from karma.conf.js rename to .config/karma.conf.base.js index 664d0c1..ed87c1f 100644 --- a/karma.conf.js +++ b/.config/karma.conf.base.js @@ -1,14 +1,8 @@ -module.exports = function (config) { - +module.exports = files => config => { config.set({ - basePath: '', + basePath: '../', frameworks: ['jasmine'], - files: [ - // 'node_modules/core-js/client/core.min.js', - 'src/monet.js', - 'test/*-helper.js', - 'test/*-spec.js' - ], + files, exclude: [], reporters: ['mocha'], port: 9876, @@ -22,6 +16,5 @@ module.exports = function (config) { }, singleRun: true, concurrency: 6e6 - }); - -}; + }) +} diff --git a/.config/karma.conf.js b/.config/karma.conf.js new file mode 100644 index 0000000..2ad127d --- /dev/null +++ b/.config/karma.conf.js @@ -0,0 +1,5 @@ +module.exports = require('./karma.conf.base')([ + 'src/monet.js', + 'test/*-helper.js', + 'test/*-spec.js' +]) diff --git a/.config/tsconfig.json b/.config/tsconfig.json new file mode 100644 index 0000000..f55ccc9 --- /dev/null +++ b/.config/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "listFiles": true, + "lib": ["dom", "es5", "es2015.collection", "es2015.iterable"], + "noEmit": true, + "noImplicitAny": true, + "strict": true + }, + "files": [ + "../test/typings/identity-spec.ts", + "../test/typings/maybe-spec.ts", + "../test/typings/either-spec.ts", + "../test/typings/validation-spec.ts", + "../test/typings/list-spec.ts", + "../test/typings/nel-spec.ts", + "../test/typings/io-spec.ts", + "../test/typings/reader-spec.ts", + "../test/typings/free-spec.ts" + ] +} diff --git a/.npmignore b/.npmignore index 0680378..b9d0421 100644 --- a/.npmignore +++ b/.npmignore @@ -1,12 +1,10 @@ .gitignore .travis.yml -.eslintrc.json .npmignore CONTRIBUTING.md -karma.conf.js -tsconfig.json +.config/ docs/ scripts/ src/ diff --git a/package.json b/package.json index eeea933..53b9998 100644 --- a/package.json +++ b/package.json @@ -24,31 +24,36 @@ "dependencies": {}, "devDependencies": { "core-js": "2.5.7", - "eslint": "5.6.0", - "jasmine-core": "3.2.1", - "karma": "3.0.0", + "eslint": "5.9.0", + "jasmine": "3.3.0", + "jasmine-core": "3.3.0", + "karma": "3.1.1", "karma-chrome-launcher": "2.2.0", "karma-firefox-launcher": "1.1.0", - "karma-jasmine": "1.1.2", + "karma-jasmine": "2.0.1", "karma-mocha-reporter": "2.2.5", "typescript": "3.0.3", "uglify-js": "3.4.9" }, "scripts": { - "lint": "./node_modules/.bin/eslint --env browser,node './src/**/*.js'", - "test": "npm run test:karma && npm run test:typings && npm run lint && npm run test:build", - "test:karma": "./node_modules/.bin/karma start", - "test:typings": "./node_modules/.bin/tsc -m system", - "test:build": "npm run build && rm -Rf ./dist", - "tdd": "./node_modules/.bin/karma start --auto-watch --no-single-run", - "tdd-full": "./node_modules/.bin/karma start --auto-watch --no-single-run --browsers Chrome,Firefox,PhantomJS", - "tdd-full-osx": "./node_modules/.bin/karma start --auto-watch --no-single-run --browsers Chrome,Firefox,PhantomJS,Safari", - "minify:monet": "./node_modules/.bin/uglifyjs dist/monet.js -o dist/monet.min.js --source-map filename=dist/monet.min.js.map -m -c unsafe -v --comments --keep-fnames", - "minify:monet-pimp": "./node_modules/.bin/uglifyjs dist/monet-pimp.js -o dist/monet-pimp.min.js --source-map filename=dist/monet-pimp.min.js.map -m -c unsafe -v --comments --keep-fnames", + "lint": "eslint -c .config/eslintrc.json --env browser,node './src/**/*.js'", + "test": "npm run test:karma && npm run test:node && npm run test:typings && npm run lint && npm run test:build", + "test:karma": "karma start .config/karma.conf.js", + "test:node": "jasmine --config=.config/jasmine.json", + "test:typings": "tsc -p .config/tsconfig.json -m system", + "test:build": "npm run build && npm run test:prepublish && rm -Rf ./dist", + "test:prepublish": "npm run test:prepublish:node && npm run test:prepublish:browser", + "test:prepublish:node": "jasmine --config=.config/jasmine-prepublish-global.json && jasmine --config=.config/jasmine-prepublish.json", + "test:prepublish:browser": "karma start .config/karma-prepublish-browser.conf.js", + "tdd": "karma start --auto-watch --no-single-run", + "tdd-full": "karma start --auto-watch --no-single-run --browsers Chrome,Firefox,PhantomJS", + "tdd-full-osx": "karma start --auto-watch --no-single-run --browsers Chrome,Firefox,PhantomJS,Safari", + "minify:monet": "uglifyjs dist/monet.js -o dist/monet.min.js --source-map filename=dist/monet.min.js.map -m -c unsafe -v --comments --keep-fnames", + "minify:monet-pimp": "uglifyjs dist/monet-pimp.js -o dist/monet-pimp.min.js --source-map filename=dist/monet-pimp.min.js.map -m -c unsafe -v --comments --keep-fnames", "minify": "npm run minify:monet && npm run minify:monet-pimp", "copy:types": "cp src/monet.d.ts dist/", - "copy:monet": "./node_modules/.bin/uglifyjs src/monet.js -o dist/monet.js --lint --comments -b braces=true", - "copy:monet-pimp": "./node_modules/.bin/uglifyjs src/monet-pimp.js -o dist/monet-pimp.js --lint --comments -b braces=true", + "copy:monet": "uglifyjs src/monet.js -o dist/monet.js --lint --comments -b braces=true", + "copy:monet-pimp": "uglifyjs src/monet-pimp.js -o dist/monet-pimp.js --lint --comments -b braces=true", "copy": "npm run copy:monet && npm run copy:monet-pimp && npm run copy:types", "build": "rm -Rf ./dist && mkdir dist/ && npm run copy && npm run minify", "prepublishOnly": "npm run build" diff --git a/prepublish-test/browser-global.js b/prepublish-test/browser-global.js new file mode 100644 index 0000000..b86c29d --- /dev/null +++ b/prepublish-test/browser-global.js @@ -0,0 +1,8 @@ +describe('global Monet object', function () { + it('should be available', function () { + expect(Monet).toBeDefined() + expect(Maybe).toBeDefined() + expect(Either).toBeDefined() + expect(Validation.success).toBe(Success) + }) +}) diff --git a/prepublish-test/node-global.js b/prepublish-test/node-global.js new file mode 100644 index 0000000..470d3a5 --- /dev/null +++ b/prepublish-test/node-global.js @@ -0,0 +1,11 @@ +global.useMonetGlobalObject = true // run browser style tests +require('../dist/monet.js') + +describe('global Monet object', function () { + it('should be available', function () { + expect(Monet).toBeDefined() + expect(Maybe).toBeDefined() + expect(Either).toBeDefined() + expect(Validation.success).toBe(Success) + }) +}) diff --git a/prepublish-test/node-regular.js b/prepublish-test/node-regular.js new file mode 100644 index 0000000..3ca8809 --- /dev/null +++ b/prepublish-test/node-regular.js @@ -0,0 +1,10 @@ +const monet = require('../dist/monet.js') + +describe('monet.js exports object', function () { + it('should be available', function () { + expect(monet).toBeDefined() + expect(monet.Maybe).toBeDefined() + expect(monet.Either).toBeDefined() + expect(monet.Validation.success).toBe(monet.Success) + }) +}) diff --git a/src/monet-pimp.js b/src/monet-pimp.js index fb8ade1..ca8cf81 100644 --- a/src/monet-pimp.js +++ b/src/monet-pimp.js @@ -17,7 +17,7 @@ if (typeof define === 'function' && define.amd) { define(['monet'], factory) } else if (typeof module === 'object' && module.exports) { - module.exports = factory(require('monet'), root) + module.exports = factory(require('monet'), typeof global === 'object' ? global : root) } else { factory(root.Monet, root) } diff --git a/src/monet.js b/src/monet.js index f9a294b..314f5d4 100644 --- a/src/monet.js +++ b/src/monet.js @@ -14,9 +14,12 @@ if (typeof define === 'function' && define.amd) { define(factory) } else if (typeof module === 'object' && module.exports) { - module.exports = factory(root) + module.exports = factory(typeof global === 'object' ? global : root) } else { - root.notUseMonetGlobalObject = !root.useMonetGlobalObject + root.useMonetGlobalObject = + typeof root.useMonetGlobalObject === 'boolean' ? + root.useMonetGlobalObject : + true root.Monet = factory(root) } }(typeof self !== 'undefined' ? self : this, function (rootGlobalObject) { @@ -1468,9 +1471,10 @@ decorate(Identity) return Maybe.fromNull(rootGlobalObject) - .filter(function (rootObj) { return Boolean(rootObj.notUseMonetGlobalObject) }) + .filter(function (rootObj) { return rootObj.useMonetGlobalObject }) .cata(function () { return assign(Monet, root) }, function (rootObj) { assign(rootObj, root) + rootObj.Monet = Monet return Monet }) })) diff --git a/test/matcher-helper.js b/test/matcher-helper.js index 8a60499..17feb78 100644 --- a/test/matcher-helper.js +++ b/test/matcher-helper.js @@ -7,3 +7,8 @@ function getCustomMatcher(fn) { } } } + +try { + // allow in node + global.getCustomMatcher = getCustomMatcher; +} catch (e) {} diff --git a/test/node-index.js b/test/node-index.js new file mode 100644 index 0000000..ffce332 --- /dev/null +++ b/test/node-index.js @@ -0,0 +1,15 @@ +global.useMonetGlobalObject = true // run browser style tests +require('../src/monet') + +require('./matcher-helper') +require('./curry-spec') +require('./either-spec') +require('./free-spec') +require('./io-spec') +require('./list-spec') +require('./maybe-spec') +require('./monad-laws-spec') +require('./monad-transformer-spec') +require('./nel-spec') +require('./reader-spec') +require('./validation-spec') diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 8dcf08d..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "listFiles": true, - "lib": ["dom", "es5", "es2015.collection", "es2015.iterable"], - "noEmit": true, - "noImplicitAny": true, - "strict": true - }, - "files": [ - "test/typings/identity-spec.ts", - "test/typings/maybe-spec.ts", - "test/typings/either-spec.ts", - "test/typings/validation-spec.ts", - "test/typings/list-spec.ts", - "test/typings/nel-spec.ts", - "test/typings/io-spec.ts", - "test/typings/reader-spec.ts", - "test/typings/free-spec.ts" - ] -} From c181fa3af7e93a487a6ef6af28c236ac882cf6ae Mon Sep 17 00:00:00 2001 From: Jakub Strojewski Date: Sun, 18 Nov 2018 12:54:24 +0100 Subject: [PATCH 2/2] 0.9.0-rc.2 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f939302..094ae1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.9.0 +### rc.2 (18 Nov 2018) + +- [fix] broken UMD for node imports ( #193 ) + ### rc.1 (18 Sep 2018) - [fix] broken UMD for node imports -- thanks to @jfspencer ( #180 ) diff --git a/package.json b/package.json index 53b9998..6e944f0 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ ], "name": "monet", "description": "Monadic types library for JavaScript", - "version": "0.9.0-rc.1", + "version": "0.9.0-rc.2", "homepage": "https://monet.github.io/monet.js/", "repository": { "type": "git",