-
API to group test cases into test suites, e.g.
describe
andit
-
setup/teardown hooks (
before
,beforeEach
,after
,afterEach
) -
Support for promises: test case returns a promise, the test runner waits until the promise is resolved
-
Output formatters: junit/xunit for CI, spec-like for humans (a list of failed tests is printed again at the end)
-
Run all tests in a single file, run a single test case, run a single test suite.
Imagine a chat server persisting the messages, a simplified Slack chat. The domain is designed in the object-orientated style. In order to get realtime updates, we need to transport events emitted on the model constructor ("static" events) and on a model instance ("instance" events).
While it may not be immediately clear, the example is covering few other important LoopBack concepts too:
- authorization (
loopback.token
in REST) - current context (
loopback.context
in REST)
What is not covered:
- file uploads and downloads
function createLoopBackApp() { | |
var app = express(); | |
// add loopback stuff | |
app.phase('routes').use(function(req, res, next) { | |
if (app._router) { | |
app._router.handle(res, res, next); | |
} else { | |
next(); | |
} |
var jdb = require('./'); | |
var ModelBuilder = jdb.ModelBuilder; | |
var DataSource = jdb.DataSource; | |
var Memory = require('./lib/connectors/memory'); | |
var assert = require('assert'); | |
var ID = 'custom-generated-id'; | |
var memory = new DataSource({connector: Memory}); | |
var modelBuilder = memory.modelBuilder; |
This is an extra exercise for the workshop Building a full-stack application with LoopBack and AngularJS.
Now that we have the first version of our application ready, let's switch the storage backend from an in-memory database to MySQL.
- Install
loopback-connector-mysql
This is an extra exercise for the workshop Building a full-stack application with LoopBack and AngularJS.
Let's write a method Whiskey.prototype.ratingStats
that will provide
a breakdown of rating data for a given whiskey. This method should
be defined in common/models/whiskey.js
. Below is a template, it's
up to the reader to implement the statistical computation.
The instructions and the sample-data file were moved to https://github.com/bajtos/loopback-workshop.
# output of `dtruss -p {pid}` for /System/Library/CoreServices/launchservicesd | |
SYSCALL(args) = return | |
workq_kernreturn(0x20, 0x0, 0x1) = 0 0 | |
process_policy(0x1, 0xF, 0x7) = 0 0 | |
process_policy(0x1, 0xF, 0x7) = 0 0 | |
kevent64(0x3, 0x7FFF72E3F130, 0x1) = 1 0 | |
workq_kernreturn(0x20, 0x0, 0x1) = 0 0 | |
kevent64(0x3, 0x7FFF72E3F130, 0x1) = 1 0 | |
workq_kernreturn(0x20, 0x0, 0x1) = 0 0 | |
process_policy(0x1, 0xF, 0x7) = 0 0 |
var loopback = require('loopback'); | |
var boot = require('loopback-boot'); | |
var app = module.exports = loopback(); | |
// hack sharedCtor | |
var setup = loopback.PersistedModel.setup; | |
loopback.PersistedModel.setup = function(rec) { | |
var extend = require('util')._extend; |