Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore committed Oct 24, 2016
1 parent 5930db7 commit 48179ba
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
34 changes: 21 additions & 13 deletions test/lib/application.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ const Application = require('../../lib/application');
const path = require('path');

describe('test/lib/application.test.js', () => {
let app;
afterEach(() => app.close());

describe('create application', () => {

it('should throw options.baseDir required', () => {
(function() {
new Application({
Expand Down Expand Up @@ -32,16 +36,19 @@ describe('test/lib/application.test.js', () => {

describe('application.deprecate', () => {
it('should get deprecate with namespace egg', () => {
const app = createApplication();
app = createApplication();
const deprecate = app.deprecate;
deprecate._namespace.should.equal('egg');
deprecate.should.equal(app.deprecate);
return app.ready();
});
});

describe('curl()', () => {
it('should curl success', function* () {
const app = createApplication();
this.timeout(10000);
app = createApplication();
yield app.ready();
const res = yield app.curl('https://a.alipayobjects.com/aliBridge/1.0.0/aliBridge.min.js');
res.status.should.equal(200);
});
Expand All @@ -50,48 +57,49 @@ describe('test/lib/application.test.js', () => {
describe('dumpConfig()', () => {
it('should dump config and plugins', () => {
const baseDir = path.join(__dirname, '../fixtures/apps/demo');
new Application({
app = new Application({
baseDir,
});
const json = require(path.join(baseDir, 'run/application_config.json'));
json.plugins.onerror.version.should.match(/\d+\.\d+\.\d+/);
json.config.name.should.equal('demo');
return app.ready();
});
});

describe('close()', () => {
it('should close all listeners', function* () {
const baseDir = path.join(__dirname, '../fixtures/apps/demo');
const application = new Application({
app = new Application({
baseDir,
});
process.listeners('unhandledRejection')
.indexOf(application._unhandledRejectionHandler).should.not.equal(-1);
yield application.close();
.indexOf(app._unhandledRejectionHandler).should.not.equal(-1);
yield app.close();
process.listeners('unhandledRejection')
.indexOf(application._unhandledRejectionHandler).should.equal(-1);
.indexOf(app._unhandledRejectionHandler).should.equal(-1);
});
it('should emit close event before exit', () => {
it('should emit close event before exit', function* () {
const baseDir = path.join(__dirname, '../fixtures/apps/demo');
const application = new Application({
app = new Application({
baseDir,
});
let called = false;
application.on('close', () => {
app.on('close', () => {
called = true;
});
application.close();
yield app.close();
called.should.equal(true);
});
});

describe('app start timeout', function() {
it('should emit `startTimeout` event', function(done) {
const baseDir = path.join(__dirname, '../fixtures/apps/app-start-timeout');
const application = new Application({
app = new Application({
baseDir,
});
application.once('startTimeout', done);
app.once('startTimeout', done);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/lib/core/agent_worker_client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const fs = require('fs');

const fixtures = path.join(__dirname, '../../fixtures');

describe('test/lib/core/agent_worker_client.test.js', () => {
describe.skip('test/lib/core/agent_worker_client.test.js', () => {

describe('single process', () => {
let agent;
Expand Down
10 changes: 10 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');
const mm = require('egg-mock');
const fixtures = path.join(__dirname, 'fixtures');
const eggPath = path.join(__dirname, '..');
// const execSync = require('child_process').execSync;

exports.app = (name, options) => {
options = formatOptions(name, options);
Expand All @@ -19,6 +20,7 @@ exports.app = (name, options) => {
* @return {App} app - Application object.
*/
exports.cluster = (name, options) => {
// removeLogOnWindows(name);
options = formatOptions(name, options);
const cluster = mm.cluster(options);
const close = cluster.close;
Expand All @@ -37,6 +39,14 @@ exports.getJSON = name => {
return JSON.parse(fs.readFileSync(exports.getFilepath(name)));
};

// function removeLogOnWindows(name) {
// const logPath = path.join(exports.getFilepath(name), 'logs');
// if (process.platform === 'win32') {
// console.info(`deleting ${logPath}`);
// execSync('rmdir /s /q');
// }
// }

function formatOptions(name, options) {
let baseDir;
if (typeof name === 'string') {
Expand Down

0 comments on commit 48179ba

Please sign in to comment.