From ff085bdd6a374a942e67c62aa6842a28afc56c98 Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Tue, 14 Feb 2017 16:03:41 +0800 Subject: [PATCH] + test load custom model config format --- package.json | 1 + test/fixtures/coffee-app/model-config.json | 3 ++ test/fixtures/coffee-app/models/order.coffee | 3 ++ test/fixtures/coffee-app/models/order.yaml | 1 + test/model-load-config.test.js | 40 ++++++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 test/fixtures/coffee-app/models/order.coffee create mode 100644 test/fixtures/coffee-app/models/order.yaml create mode 100644 test/model-load-config.test.js diff --git a/package.json b/package.json index 6439cc8..d02ff31 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/test/fixtures/coffee-app/model-config.json b/test/fixtures/coffee-app/model-config.json index 3566c55..a3b7a43 100644 --- a/test/fixtures/coffee-app/model-config.json +++ b/test/fixtures/coffee-app/model-config.json @@ -1,5 +1,8 @@ { "Customer": { "dataSource": "db" + }, + "Order": { + "dataSource": "db" } } diff --git a/test/fixtures/coffee-app/models/order.coffee b/test/fixtures/coffee-app/models/order.coffee new file mode 100644 index 0000000..f374fa9 --- /dev/null +++ b/test/fixtures/coffee-app/models/order.coffee @@ -0,0 +1,3 @@ +module.exports = (Model) -> + Model.settings._customized = 'Order' + Model.base.settings._customized = 'Base' diff --git a/test/fixtures/coffee-app/models/order.yaml b/test/fixtures/coffee-app/models/order.yaml new file mode 100644 index 0000000..aa9999c --- /dev/null +++ b/test/fixtures/coffee-app/models/order.yaml @@ -0,0 +1 @@ +name: "Order" diff --git a/test/model-load-config.test.js b/test/model-load-config.test.js new file mode 100644 index 0000000..171de32 --- /dev/null +++ b/test/model-load-config.test.js @@ -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(); + }); + }); + }); +}); +