-
Notifications
You must be signed in to change notification settings - Fork 72
Add support async scripts #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ var path = require('path'); | |
| var loopback = require('loopback'); | ||
| var assert = require('assert'); | ||
| var expect = require('must'); | ||
| var fs = require('fs-extra'); | ||
| var sandbox = require('./helpers/sandbox'); | ||
| var appdir = require('./helpers/appdir'); | ||
|
|
||
|
|
@@ -161,13 +162,62 @@ describe('executor', function() { | |
|
|
||
| describe('with boot and models files', function() { | ||
| beforeEach(function() { | ||
| process.bootFlags = process.bootFlags || []; | ||
| boot.execute(app, simpleAppInstructions()); | ||
| }); | ||
|
|
||
| it('should run `boot/*` files', function() { | ||
| assert(process.loadedFooJS); | ||
| delete process.loadedFooJS; | ||
| afterEach(function() { | ||
| delete process.bootFlags; | ||
| }); | ||
|
|
||
| it('should run `boot/*` files', function(done) { | ||
| // scripts are loaded by the order of file names | ||
| expect(process.bootFlags).to.eql([ | ||
| 'barLoaded', | ||
| 'barSyncLoaded', | ||
| 'fooLoaded', | ||
| 'barStarted' | ||
| ]); | ||
|
|
||
| // bar finished happens in the next tick | ||
| // barSync executed after bar finished | ||
| setTimeout(function() { | ||
| expect(process.bootFlags).to.eql([ | ||
| 'barLoaded', | ||
| 'barSyncLoaded', | ||
| 'fooLoaded', | ||
| 'barStarted', | ||
| 'barFinished', | ||
| 'barSyncExecuted' | ||
| ]); | ||
| done(); | ||
| }, 10); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with boot with callback', function() { | ||
| beforeEach(function() { | ||
| process.bootFlags = process.bootFlags || []; | ||
| }); | ||
|
|
||
| afterEach(function() { | ||
| delete process.bootFlags; | ||
| }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move the hook to the top, right after |
||
|
|
||
| it('should run `boot/*` files asynchronously', function(done) { | ||
| boot.execute(app, simpleAppInstructions(), function() { | ||
| expect(process.bootFlags).to.eql([ | ||
| 'barLoaded', | ||
| 'barSyncLoaded', | ||
| 'fooLoaded', | ||
| 'barStarted', | ||
| 'barFinished', | ||
| 'barSyncExecuted' | ||
| ]); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| }); | ||
|
|
||
| describe('with PaaS and npm env variables', function() { | ||
|
|
@@ -299,5 +349,7 @@ function someInstructions(values) { | |
| } | ||
|
|
||
| function simpleAppInstructions() { | ||
| return boot.compile(SIMPLE_APP); | ||
| // Copy it so that require will happend again | ||
| fs.copySync(SIMPLE_APP, appdir.PATH); | ||
| return boot.compile(appdir.PATH); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there is no async app anymore, it would be better to get rid of |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| process.bootFlags.push('barLoaded'); | ||
| module.exports = function(app, callback) { | ||
| process.bootFlags.push('barStarted'); | ||
| process.nextTick(function() { | ||
| process.bootFlags.push('barFinished'); | ||
| callback(); | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| process.bootFlags.push('barSyncLoaded'); | ||
| module.exports = function(app) { | ||
| process.bootFlags.push('barSyncExecuted'); | ||
| }; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| process.loadedFooJS = true; | ||
| process.bootFlags.push('fooLoaded'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If one of these asserts fails, the error message will be very unhelpful.
Solution A:
Solution B:
The latter provides most context, as the assert library has all four properties available to print them in the error message.