mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Move tests from core to root (#11700)
- move all test files from core/test to test/ - updated all imports and other references - all code inside of core/ is then application code - tests are correctly at the root level - consistent with other repos/projects Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
This commit is contained in:
parent
b7b4026fd5
commit
7e20949956
2 changed files with 125 additions and 0 deletions
97
ghost/promise/test/pipeline_spec.js
Normal file
97
ghost/promise/test/pipeline_spec.js
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
var should = require('should'),
|
||||||
|
sinon = require('sinon'),
|
||||||
|
Promise = require('bluebird'),
|
||||||
|
|
||||||
|
// Stuff we are testing
|
||||||
|
pipeline = require('../../../../core/server/lib/promise/pipeline');
|
||||||
|
|
||||||
|
// These tests are based on the tests in https://github.com/cujojs/when/blob/3.7.4/test/pipeline-test.js
|
||||||
|
function createTask(y) {
|
||||||
|
return function (x) {
|
||||||
|
return x + y;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Pipeline', function () {
|
||||||
|
afterEach(function () {
|
||||||
|
sinon.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should execute tasks in order', function () {
|
||||||
|
return pipeline([createTask('b'), createTask('c'), createTask('d')], 'a').then(function (result) {
|
||||||
|
result.should.eql('abcd');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resolve to initial args when no tasks supplied', function () {
|
||||||
|
return pipeline([], 'a', 'b').then(function (result) {
|
||||||
|
result.should.eql(['a', 'b']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resolve to empty array when no tasks and no args supplied', function () {
|
||||||
|
return pipeline([]).then(function (result) {
|
||||||
|
result.should.eql([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should pass args to initial task', function () {
|
||||||
|
var expected = [1, 2, 3],
|
||||||
|
tasks = [sinon.spy()];
|
||||||
|
|
||||||
|
return pipeline(tasks, 1, 2, 3).then(function () {
|
||||||
|
tasks[0].calledOnce.should.be.true();
|
||||||
|
tasks[0].firstCall.args.should.eql(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow initial args to be promises', function () {
|
||||||
|
var expected = [1, 2, 3],
|
||||||
|
tasks = [sinon.spy()],
|
||||||
|
Resolver = Promise.resolve;
|
||||||
|
|
||||||
|
return pipeline(tasks, new Resolver(1), new Resolver(2), new Resolver(3)).then(function () {
|
||||||
|
tasks[0].calledOnce.should.be.true();
|
||||||
|
tasks[0].firstCall.args.should.eql(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow tasks to be promises', function () {
|
||||||
|
var expected = [1, 2, 3],
|
||||||
|
tasks = [
|
||||||
|
sinon.stub().returns(new Promise.resolve(4)),
|
||||||
|
sinon.stub().returns(new Promise.resolve(5)),
|
||||||
|
sinon.stub().returns(new Promise.resolve(6))
|
||||||
|
];
|
||||||
|
|
||||||
|
return pipeline(tasks, 1, 2, 3).then(function (result) {
|
||||||
|
result.should.eql(6);
|
||||||
|
tasks[0].calledOnce.should.be.true();
|
||||||
|
tasks[0].firstCall.args.should.eql(expected);
|
||||||
|
tasks[1].calledOnce.should.be.true();
|
||||||
|
tasks[1].firstCall.calledWith(4).should.be.true();
|
||||||
|
tasks[2].calledOnce.should.be.true();
|
||||||
|
tasks[2].firstCall.calledWith(5).should.be.true();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow tasks and args to be promises', function () {
|
||||||
|
var expected = [1, 2, 3],
|
||||||
|
tasks = [
|
||||||
|
sinon.stub().returns(new Promise.resolve(4)),
|
||||||
|
sinon.stub().returns(new Promise.resolve(5)),
|
||||||
|
sinon.stub().returns(new Promise.resolve(6))
|
||||||
|
],
|
||||||
|
Resolver = Promise.resolve;
|
||||||
|
|
||||||
|
return pipeline(tasks, new Resolver(1), new Resolver(2), new Resolver(3)).then(function (result) {
|
||||||
|
result.should.eql(6);
|
||||||
|
tasks[0].calledOnce.should.be.true();
|
||||||
|
tasks[0].firstCall.args.should.eql(expected);
|
||||||
|
tasks[1].calledOnce.should.be.true();
|
||||||
|
tasks[1].firstCall.calledWith(4).should.be.true();
|
||||||
|
tasks[2].calledOnce.should.be.true();
|
||||||
|
tasks[2].firstCall.calledWith(5).should.be.true();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
28
ghost/promise/test/sequence_spec.js
Normal file
28
ghost/promise/test/sequence_spec.js
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
const should = require('should');
|
||||||
|
const sinon = require('sinon');
|
||||||
|
const Promise = require('bluebird');
|
||||||
|
const sequence = require('../../../../core/server/lib/promise/sequence');
|
||||||
|
|
||||||
|
describe('Unit: lib/promise/sequence', function () {
|
||||||
|
afterEach(function () {
|
||||||
|
sinon.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('mixed tasks: promise and none promise', function () {
|
||||||
|
const tasks = [
|
||||||
|
function a() {
|
||||||
|
return Promise.resolve('hello');
|
||||||
|
},
|
||||||
|
function b() {
|
||||||
|
return 'from';
|
||||||
|
},
|
||||||
|
function c() {
|
||||||
|
return Promise.resolve('chio');
|
||||||
|
}
|
||||||
|
];
|
||||||
|
return sequence(tasks)
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.eql(['hello','from', 'chio']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue