+ test load custom model config format

This commit is contained in:
Riceball LEE 2017-02-14 16:03:41 +08:00
parent 6c4b025ebf
commit ff085bdd6a
5 changed files with 48 additions and 0 deletions

View File

@ -46,6 +46,7 @@
"eslint": "^2.11.1",
"eslint-config-loopback": "^1.0.0",
"fs-extra": "^0.30.0",
"js-yaml": "^3.8.1",
"loopback": "^3.0.0",
"mocha": "^2.5.3",
"supertest": "^1.2.0"

View File

@ -1,5 +1,8 @@
{
"Customer": {
"dataSource": "db"
},
"Order": {
"dataSource": "db"
}
}

View File

@ -0,0 +1,3 @@
module.exports = (Model) ->
Model.settings._customized = 'Order'
Model.base.settings._customized = 'Base'

View File

@ -0,0 +1 @@
name: "Order"

View File

@ -0,0 +1,40 @@
// Copyright IBM Corp. 2014,2016. All Rights Reserved.
// Node module: loopback-boot
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
var boot = require('../');
var fs = require('fs-extra');
var path = require('path');
var expect = require('chai').expect;
var loadConfig = require('load-config-file');
var yaml = require('js-yaml');
loadConfig.register(['.yaml', '.yml'], yaml.safeLoad);
// add coffee-script to require.extensions
require('coffee-script/register');
var COFFEE_APP = path.join(__dirname, 'fixtures', 'coffee-app');
describe('compiler', function() {
function getModelByName(aModels, aName) {
for (let model of aModels) {
if (model.name === aName) return model;
}
}
describe.only('from directory', function() {
it('loads Model yaml config files', function(done) {
boot.compile(COFFEE_APP, function(err, context) {
if (err) return done(err);
var instructions = context.instructions;
var model = getModelByName(instructions.models, 'Order');
expect(model).to.be.exist;
expect(model.sourceFile).to.be.exist;
done();
});
});
});
});