UNPKG

specify-core

Version:

Describe, structure and runs tests for the Specify framework.

245 lines 11.2 kB
var alright = require('alright'); var specify = require('specify-core'); var moment = require('moment'); var claire = require('claire'); var flip = require('core.lambda').flip; var forAll = claire.forAll; var fmap = claire.transform; var t = claire.data; var TDuration = t.Int.then(function (x) { return flip(fmap)(t.Int, function (y) { return Duration(moment().toDate(), moment().add(x, 'ms').toDate(), y); }); }); var TResultTag = claire.choice('Success', 'Failure', 'Ignored'); var TResult = TResultTag.then(function (x) { return flip(fmap)(t.Array(t.Str), function (y) { return makeResult(x, y); }); }); function makeResult(tag, path) { var d = Duration(new Date(), new Date(), 0); return tag === 'Success' ? Result.Success(path, d, []) : tag === 'Failure' ? Result.Failure(path, null, d, []) : /* otherwise */ Result.Ignored(path); } var Duration = specify.Duration; var Result = specify.Result; module.exports = function (specify$2) { var _scope = { specify: specify$2, tests: [], beforeAll: [], afterAll: [], beforeEach: [], afterEach: [] }; (function () { var _scope$2 = { specify: _scope.specify, tests: [], beforeAll: [], afterAll: [], beforeEach: [], afterEach: [] }; (function () { var _scope$3 = { specify: _scope$2.specify, tests: [], beforeAll: [], afterAll: [], beforeEach: [], afterEach: [] }; _scope$3.tests.push(_scope$3.specify.Test.Case.create({ name: 'Should be true when the duration is greater than the slow threshold.', timeout: new _scope$3.specify._Maybe.Nothing(), slow: new _scope$3.specify._Maybe.Nothing(), enabled: new _scope$3.specify._Maybe.Nothing(), test: new _scope$3.specify._Future(function (reject, resolve) { try { (function () { (function (alright$2) { return alright$2.verify(Duration(moment().toDate(), moment().add(100, 'ms').toDate(), 150).isSlow())(alright$2.equal(false)); }(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright)); (function (alright$2) { return alright$2.verify(Duration(moment().toDate(), moment().add(150, 'ms').toDate(), 150).isSlow())(alright$2.equal(true)); }(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright)); (function (alright$2) { return alright$2.verify(Duration(moment().toDate(), moment().add(200, 'ms').toDate(), 150).isSlow())(alright$2.equal(true)); }(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright)); }()); resolve(); } catch (e) { reject(e); } }) })); _scope$2.tests.push(_scope$2.specify.Test.Suite.create({ name: 'Duration#isSlow()', tests: _scope$3.tests, beforeAll: _scope$2.specify.Hook(_scope$3.beforeAll), beforeEach: _scope$2.specify.Hook(_scope$3.beforeEach), afterAll: _scope$2.specify.Hook(_scope$3.afterAll), afterEach: _scope$2.specify.Hook(_scope$3.afterEach) })); }()); (function () { var _scope$3 = { specify: _scope$2.specify, tests: [], beforeAll: [], afterAll: [], beforeEach: [], afterEach: [] }; _scope$3.tests.push(_scope$3.specify.Test.Case.create({ name: 'Should return the total duration in milliseconds.', timeout: new _scope$3.specify._Maybe.Nothing(), slow: new _scope$3.specify._Maybe.Nothing(), enabled: new _scope$3.specify._Maybe.Nothing(), test: new _scope$3.specify._Future(function (reject, resolve) { try { (function () { forAll(TDuration).satisfy(function (a) { return !!function (alright$2) { return alright$2.verify(a.time())(alright$2.equal(a.finished - a.started)); }(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright); }).asTest()(); }()); resolve(); } catch (e) { reject(e); } }) })); _scope$2.tests.push(_scope$2.specify.Test.Suite.create({ name: 'Duration#time()', tests: _scope$3.tests, beforeAll: _scope$2.specify.Hook(_scope$3.beforeAll), beforeEach: _scope$2.specify.Hook(_scope$3.beforeEach), afterAll: _scope$2.specify.Hook(_scope$3.afterAll), afterEach: _scope$2.specify.Hook(_scope$3.afterEach) })); }()); (function () { var _scope$3 = { specify: _scope$2.specify, tests: [], beforeAll: [], afterAll: [], beforeEach: [], afterEach: [] }; _scope$3.tests.push(_scope$3.specify.Test.Case.create({ name: 'Should return the total duration (in ms) as a formatted string.', timeout: new _scope$3.specify._Maybe.Nothing(), slow: new _scope$3.specify._Maybe.Nothing(), enabled: new _scope$3.specify._Maybe.Nothing(), test: new _scope$3.specify._Future(function (reject, resolve) { try { (function () { forAll(TDuration).satisfy(function (a) { return !!function (alright$2) { return alright$2.verify(a.toString())(alright$2.equal(a.finished - a.started + 'ms')); }(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright); }).asTest()(); }()); resolve(); } catch (e) { reject(e); } }) })); _scope$2.tests.push(_scope$2.specify.Test.Suite.create({ name: 'Duration#toString()', tests: _scope$3.tests, beforeAll: _scope$2.specify.Hook(_scope$3.beforeAll), beforeEach: _scope$2.specify.Hook(_scope$3.beforeEach), afterAll: _scope$2.specify.Hook(_scope$3.afterAll), afterEach: _scope$2.specify.Hook(_scope$3.afterEach) })); }()); (function () { var _scope$3 = { specify: _scope$2.specify, tests: [], beforeAll: [], afterAll: [], beforeEach: [], afterEach: [] }; _scope$3.tests.push(_scope$3.specify.Test.Case.create({ name: 'Should return only the name of the test.', timeout: new _scope$3.specify._Maybe.Nothing(), slow: new _scope$3.specify._Maybe.Nothing(), enabled: new _scope$3.specify._Maybe.Nothing(), test: new _scope$3.specify._Future(function (reject, resolve) { try { (function () { forAll(TResult).satisfy(function (a) { return !!(a.name() === a.title[a.title.length - 1]); }).asTest()(); }()); resolve(); } catch (e) { reject(e); } }) })); _scope$2.tests.push(_scope$2.specify.Test.Suite.create({ name: 'Result#name()', tests: _scope$3.tests, beforeAll: _scope$2.specify.Hook(_scope$3.beforeAll), beforeEach: _scope$2.specify.Hook(_scope$3.beforeEach), afterAll: _scope$2.specify.Hook(_scope$3.afterAll), afterEach: _scope$2.specify.Hook(_scope$3.afterEach) })); }()); (function () { var _scope$3 = { specify: _scope$2.specify, tests: [], beforeAll: [], afterAll: [], beforeEach: [], afterEach: [] }; _scope$3.tests.push(_scope$3.specify.Test.Case.create({ name: 'Should return the full path of the test.', timeout: new _scope$3.specify._Maybe.Nothing(), slow: new _scope$3.specify._Maybe.Nothing(), enabled: new _scope$3.specify._Maybe.Nothing(), test: new _scope$3.specify._Future(function (reject, resolve) { try { (function () { forAll(TResult).satisfy(function (a) { return !!(a.fullTitle() === a.title.join(' ')); }).asTest()(); }()); resolve(); } catch (e) { reject(e); } }) })); _scope$2.tests.push(_scope$2.specify.Test.Suite.create({ name: 'Result#fullTitle()', tests: _scope$3.tests, beforeAll: _scope$2.specify.Hook(_scope$3.beforeAll), beforeEach: _scope$2.specify.Hook(_scope$3.beforeEach), afterAll: _scope$2.specify.Hook(_scope$3.afterAll), afterEach: _scope$2.specify.Hook(_scope$3.afterEach) })); }()); _scope.tests.push(_scope.specify.Test.Suite.create({ name: 'Result', tests: _scope$2.tests, beforeAll: _scope.specify.Hook(_scope$2.beforeAll), beforeEach: _scope.specify.Hook(_scope$2.beforeEach), afterAll: _scope.specify.Hook(_scope$2.afterAll), afterEach: _scope.specify.Hook(_scope$2.afterEach) })); }()); return _scope.tests[0]; }(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('specify-core') : window.Specify.core);