Yuki Takei 7 лет назад
Родитель
Сommit
2ad240b06c

+ 2 - 1
package.json

@@ -48,7 +48,7 @@
     "server:prod": "env-cmd config/env.prod.js node app.js",
     "server": "npm run server:dev",
     "start": "npm run server:prod",
-    "test": "mocha --timeout 10000 -r test/bootstrap.js test/**/*.js",
+    "test": "mocha --timeout 10000 -r src/test/bootstrap.js src/test/**/*.js",
     "version": "node -p \"require('./package.json').version\"",
     "webpack": "webpack"
   },
@@ -199,6 +199,7 @@
   },
   "_moduleAliases": {
     "@root": ".",
+    "@server": "lib",
     "@alias/logger": "lib/service/logger",
     "debug": "lib/service/logger/alias-for-debug"
   },

+ 2 - 2
test/bootstrap.js → src/test/bootstrap.js

@@ -5,8 +5,8 @@ process.env.NODE_ENV = 'test';
 require('module-alias/register');
 
 var express = require('express')
-  , ROOT_DIR = __dirname + '/..'
-  , MODEL_DIR = __dirname + '/../lib/models'
+  , ROOT_DIR = __dirname + '/../..'
+  , MODEL_DIR = __dirname + '/../../lib/models'
   , testDBUtil
   ;
 

+ 10 - 9
test/crowi/crowi.test.js → src/test/crowi/crowi.test.js

@@ -1,34 +1,35 @@
-var chai = require('chai')
+const chai = require('chai')
   , expect = chai.expect
   , sinon = require('sinon')
   , sinonChai = require('sinon-chai')
 
   , path = require('path')
+  , rootPath = path.normalize(__dirname + '/../../../')
   ;
 chai.use(sinonChai);
 
-describe('Test for Crowi application context', function () {
-  var Crowi = require('../../lib/crowi')
+describe('Test for Crowi application context', function() {
+  const Crowi = require('@server/crowi')
     , mongoose = require('mongoose')
     ;
 
   describe('construction', function() {
     it('initialize crowi context', function() {
-      var crowi = new Crowi(path.normalize(__dirname + '/../../'), process.env);
+      const crowi = new Crowi(rootPath, process.env);
       expect(crowi).to.be.instanceof(Crowi);
-      expect(crowi.version).to.equal(require('../../package.json').version);
+      expect(crowi.version).to.equal(require('../../../package.json').version);
       expect(crowi.env).to.be.an('Object');
     });
 
     it('config getter, setter', function() {
-      var crowi = new Crowi(path.normalize(__dirname + '/../../'), process.env);
+      const crowi = new Crowi(rootPath, process.env);
       expect(crowi.getConfig()).to.deep.equals({});
       crowi.setConfig({test: 1});
       expect(crowi.getConfig()).to.deep.equals({test: 1});
     });
 
     it('model getter, setter', function() {
-      var crowi = new Crowi(path.normalize(__dirname + '/../../'), process.env);
+      const crowi = new Crowi(rootPath, process.env);
       // set
       crowi.model('hoge', { fuga: 1 });
       expect(crowi.model('hoge')).to.deep.equals({ fuga: 1 });
@@ -40,9 +41,9 @@ describe('Test for Crowi application context', function () {
       mongoose.disconnect(); // avoid error of Trying to open unclosed connection
     });
     it('setup completed', function(done) {
-      var crowi = new Crowi(path.normalize(__dirname + '/../../'), process.env);
+      const crowi = new Crowi(rootPath, process.env);
       // set
-      var p = crowi.setupDatabase()
+      const p = crowi.setupDatabase()
       expect(p).to.instanceof(Promise);
       p.then(function() {
         expect(mongoose.connection.readyState).to.equals(1);

+ 0 - 0
test/models/config.test.js → src/test/models/config.test.js


+ 0 - 0
test/models/page.test.js → src/test/models/page.test.js


+ 0 - 0
test/models/updatePost.test.js → src/test/models/updatePost.test.js


+ 76 - 76
test/models/user.test.js → src/test/models/user.test.js

@@ -1,76 +1,76 @@
-var chai = require('chai')
-  , expect = chai.expect
-  , sinon = require('sinon')
-  , sinonChai = require('sinon-chai')
-  , utils = require('../utils.js')
-  ;
-chai.use(sinonChai);
-
-describe('User', function () {
-  var Page = utils.models.Page,
-    User   = utils.models.User,
-    conn   = utils.mongoose.connection;
-
-  // clear collection
-  before(done => {
-    conn.collection('users').remove()
-      .then(() => {
-        done();
-      });
-  });
-
-  describe('Create and Find.', function () {
-    context('The user', function() {
-      it('should created', function(done) {
-        User.createUserByEmailAndPassword('Aoi Miyazaki', 'aoi', 'aoi@example.com', 'hogefuga11', 'en', function (err, userData) {
-          expect(err).to.be.null;
-          expect(userData).to.instanceof(User);
-          done();
-        });
-      });
-
-      it('should be found by findUserByUsername', function(done) {
-        User.findUserByUsername('aoi')
-        .then(function(userData) {
-          expect(userData).to.instanceof(User);
-          done();
-        });
-      });
-
-      it('should be found by findUsersByPartOfEmail', function(done) {
-
-        User.findUsersByPartOfEmail('ao', {})
-        .then(function(userData) {
-          expect(userData).to.instanceof(Array);
-          expect(userData[0]).to.instanceof(User);
-          expect(userData[0].email).to.equal('aoi@example.com');
-          done();
-        });
-
-      });
-    });
-  });
-
-  describe('User Utilities', function () {
-    context('Get username from path', function() {
-      it('found', function(done) {
-        var username = null;
-        username = User.getUsernameByPath('/user/sotarok');
-        expect(username).to.equal('sotarok');
-
-        username = User.getUsernameByPath('/user/some.user.name12/'); // with slash
-        expect(username).to.equal('some.user.name12');
-
-        done();
-      });
-
-      it('not found', function(done) {
-        var username = null;
-        username = User.getUsernameByPath('/the/page/is/not/related/to/user/page');
-        expect(username).to.be.null;
-
-        done();
-      });
-    });
-  });
-});
+var chai = require('chai')
+  , expect = chai.expect
+  , sinon = require('sinon')
+  , sinonChai = require('sinon-chai')
+  , utils = require('../utils.js')
+  ;
+chai.use(sinonChai);
+
+describe('User', function () {
+  var Page = utils.models.Page,
+    User   = utils.models.User,
+    conn   = utils.mongoose.connection;
+
+  // clear collection
+  before(done => {
+    conn.collection('users').remove()
+      .then(() => {
+        done();
+      });
+  });
+
+  describe('Create and Find.', function () {
+    context('The user', function() {
+      it('should created', function(done) {
+        User.createUserByEmailAndPassword('Aoi Miyazaki', 'aoi', 'aoi@example.com', 'hogefuga11', 'en', function (err, userData) {
+          expect(err).to.be.null;
+          expect(userData).to.instanceof(User);
+          done();
+        });
+      });
+
+      it('should be found by findUserByUsername', function(done) {
+        User.findUserByUsername('aoi')
+        .then(function(userData) {
+          expect(userData).to.instanceof(User);
+          done();
+        });
+      });
+
+      it('should be found by findUsersByPartOfEmail', function(done) {
+
+        User.findUsersByPartOfEmail('ao', {})
+        .then(function(userData) {
+          expect(userData).to.instanceof(Array);
+          expect(userData[0]).to.instanceof(User);
+          expect(userData[0].email).to.equal('aoi@example.com');
+          done();
+        });
+
+      });
+    });
+  });
+
+  describe('User Utilities', function () {
+    context('Get username from path', function() {
+      it('found', function(done) {
+        var username = null;
+        username = User.getUsernameByPath('/user/sotarok');
+        expect(username).to.equal('sotarok');
+
+        username = User.getUsernameByPath('/user/some.user.name12/'); // with slash
+        expect(username).to.equal('some.user.name12');
+
+        done();
+      });
+
+      it('not found', function(done) {
+        var username = null;
+        username = User.getUsernameByPath('/the/page/is/not/related/to/user/page');
+        expect(username).to.be.null;
+
+        done();
+      });
+    });
+  });
+});

+ 0 - 0
test/util/slack.test.js → src/test/util/slack.test.js


+ 0 - 0
test/utils.js → src/test/utils.js