specify-core
Version:
Describe, structure and runs tests for the Specify framework.
364 lines • 16.7 kB
JavaScript
var alright = require('alright');
var specify = require('specify-core');
var Future = require('data.future');
var fail = Future.rejected;
var Maybe = require('data.maybe');
var _ = alright;
var Nothing = Maybe.Nothing;
var Just = Maybe.Just;
var cfg = specify.Config(100, 100, function (x) {
return true;
});
var cfgDisabled = specify.Config(100, 100, function (x) {
return false;
});
function Test(x) {
x = x || {};
return specify.Test.Case.create({
name: x.name || '',
test: x.test || Future.of(),
timeout: x.timeout || Nothing(),
slow: x.slow || Nothing(),
enabled: x.enabled || Nothing()
});
}
function Suite(x) {
x = x || {};
return specify.Test.Suite.create({
name: x.name || '',
tests: x.tests || [],
beforeAll: x.beforeAll || specify.Hook([]),
beforeEach: x.beforeEach || specify.Hook([]),
afterAll: x.afterAll || specify.Hook([]),
afterEach: x.afterEach || specify.Hook([])
});
}
var t1 = Test({
name: 'a',
test: Future.of(1)
});
var t2 = Test({
name: 'b',
test: Future.of(2),
enabled: Just(function () {
return false;
})
});
var t3 = Test({
name: 'c',
test: fail(3)
});
var s1 = Suite({
name: 'A',
tests: [
t1,
t2,
t3
]
});
var s2 = Suite({
name: 'B',
tests: [
t1,
s1,
t2
]
});
var s3 = Suite({
name: 'C',
tests: [t2]
});
function noop() {
}
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 return a report with the results of the tests.',
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 () {
specify.makeRunner(cfg, [
s2,
s3
], noop).fork(noop, function (report) {
(function (alright$2) {
return alright$2.verify(report.passed.map(function (a) {
return a.fullTitle();
}))(alright$2.equal([
'B a',
'B A a'
]));
}(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright));
(function (alright$2) {
return alright$2.verify(report.failed.map(function (a) {
return a.fullTitle();
}))(alright$2.equal(['B A c']));
}(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright));
(function (alright$2) {
return alright$2.verify(report.ignored.map(function (a) {
return a.fullTitle();
}))(alright$2.equal([
'B A b',
'B b',
'C b'
]));
}(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright));
});
}());
resolve();
} catch (e) {
reject(e);
}
})
}));
_scope$3.tests.push(_scope$3.specify.Test.Case.create({
name: 'Should pass the stream of things to the reporter.',
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 () {
specify.makeRunner(cfg, [
s2,
s3
], function (xs) {
xs.reduce(function (acc, x) {
return x.cata({
Started: function (_$2) {
return acc.concat([[
's',
x.fullTitle()
]]);
},
Finished: function (_$2) {
return acc.concat([[
'f',
x.fullTitle()
]]);
},
TestResult: function (x$2) {
return x$2.cata({
Success: function (_$2) {
return acc.concat([[
'rs',
x$2.fullTitle()
]]);
},
Failure: function (_$2) {
return acc.concat([[
'rf',
x$2.fullTitle()
]]);
},
Ignored: function (_$2) {
return acc.concat([[
'ri',
x$2.fullTitle()
]]);
}
});
}
});
}, []).subscribe(function (v) {
(function (alright$2) {
return alright$2.verify(v)(alright$2.equal([
[
's',
'B'
],
[
's',
'B a'
],
[
'rs',
'B a'
],
[
'f',
'B a'
],
[
's',
'B A'
],
[
's',
'B A a'
],
[
'rs',
'B A a'
],
[
'f',
'B A a'
],
[
's',
'B A b'
],
[
'ri',
'B A b'
],
[
'f',
'B A b'
],
[
's',
'B A c'
],
[
'rf',
'B A c'
],
[
'f',
'B A c'
],
[
'f',
'B A'
],
[
's',
'B b'
],
[
'ri',
'B b'
],
[
'f',
'B b'
],
[
'f',
'B'
],
[
's',
'C'
],
[
's',
'C b'
],
[
'ri',
'C b'
],
[
'f',
'C b'
],
[
'f',
'C'
]
]));
}(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright));
});
}).fork(noop, noop);
}());
resolve();
} catch (e) {
reject(e);
}
})
}));
_scope$3.tests.push(_scope$3.specify.Test.Case.create({
name: 'Should pass the report to the reporter.',
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 () {
specify.makeRunner(cfg, [
s2,
s3
], function (_$2, reportStream) {
reportStream.subscribe(function (report) {
(function (alright$2) {
return alright$2.verify(report.passed.map(function (a) {
return a.fullTitle();
}))(alright$2.equal([
'B a',
'B A a'
]));
}(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright));
(function (alright$2) {
return alright$2.verify(report.failed.map(function (a) {
return a.fullTitle();
}))(alright$2.equal(['B A c']));
}(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright));
(function (alright$2) {
return alright$2.verify(report.ignored.map(function (a) {
return a.fullTitle();
}))(alright$2.equal([
'B A b',
'B b',
'C b'
]));
}(typeof module !== 'undefined' && typeof require !== 'undefined' ? require('alright') : window.alright));
});
}).fork(noop, noop);
}());
resolve();
} catch (e) {
reject(e);
}
})
}));
_scope$2.tests.push(_scope$2.specify.Test.Suite.create({
name: 'run()',
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: 'Runner',
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);