Skip to content

Commit

Permalink
Merge pull request #193 from monet/test-build
Browse files Browse the repository at this point in the history
Better build test (+ fix UMD issues)
  • Loading branch information
ulfryk authored Nov 18, 2018
2 parents 5923f23 + c181fa3 commit 84b6aca
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 56 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions .config/jasmine-prepublish-global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"spec_files": [
"prepublish-test/node-global.js"
],
"oneFailurePerSpec": true
}
6 changes: 6 additions & 0 deletions .config/jasmine-prepublish.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"spec_files": [
"prepublish-test/node-regular.js"
],
"oneFailurePerSpec": true
}
6 changes: 6 additions & 0 deletions .config/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"spec_files": [
"test/node-index.js"
],
"oneFailurePerSpec": true
}
4 changes: 4 additions & 0 deletions .config/karma-prepublish-browser.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = require('./karma.conf.base')([
'dist/monet.js',
'prepublish-test/browser-global.js'
])
17 changes: 5 additions & 12 deletions karma.conf.js → .config/karma.conf.base.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -22,6 +16,5 @@ module.exports = function (config) {
},
singleRun: true,
concurrency: 6e6
});

};
})
}
5 changes: 5 additions & 0 deletions .config/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = require('./karma.conf.base')([
'src/monet.js',
'test/*-helper.js',
'test/*-spec.js'
])
20 changes: 20 additions & 0 deletions .config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
4 changes: 1 addition & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
.gitignore
.travis.yml
.eslintrc.json
.npmignore

CONTRIBUTING.md
karma.conf.js
tsconfig.json

.config/
docs/
scripts/
src/
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
39 changes: 22 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions prepublish-test/browser-global.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
11 changes: 11 additions & 0 deletions prepublish-test/node-global.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
10 changes: 10 additions & 0 deletions prepublish-test/node-regular.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
2 changes: 1 addition & 1 deletion src/monet-pimp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 7 additions & 3 deletions src/monet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
})
}))
5 changes: 5 additions & 0 deletions test/matcher-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ function getCustomMatcher(fn) {
}
}
}

try {
// allow in node
global.getCustomMatcher = getCustomMatcher;
} catch (e) {}
15 changes: 15 additions & 0 deletions test/node-index.js
Original file line number Diff line number Diff line change
@@ -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')
20 changes: 0 additions & 20 deletions tsconfig.json

This file was deleted.

0 comments on commit 84b6aca

Please sign in to comment.