Skip to content
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

Generated mocha.global.js assumes Express will start before unit tests complete #2440

Open
1 task done
nstuyvesant opened this issue Jan 1, 2017 · 2 comments
Open
1 task done

Comments

@nstuyvesant
Copy link
Contributor

  • I understand that GitHub issues are not for tech support, but for questions specific to this generator, bug reports, and feature requests.
Item Version
generator-angular-fullstack 4.1.1
Node 6.9.2
npm 4.0.5
Operating System OS X 10
Item Answer
Transpiler Babel
Markup Pug
CSS SCSS
Router ui-router
Client Tests Mocha
DB SQL
Auth N

The generated mocha.global.js:

import app from './';

after(function(done) {
  app.angularFullstack.on('close', () => done());
  app.angularFullstack.close();
});

seems to assume that Express started before the unit tests invoked by the Gulp task "mocha:unit" finish. In my case, the tests finished too early so I got:

  1)  "after all" hook:
     TypeError: Cannot read property 'on' of undefined
    at Context.<anonymous> (mocha.global.js:9:10)

The function startServer in app.js didn't complete in time so app.angularFullstack was undefined.

I worked around it but was wondering if anyone else ran into this.

@CatBakun
Copy link

CatBakun commented Jan 17, 2017

+1
How did you work around this?

For me this failed the first time, ruining it again did not show the message.

@nstuyvesant
Copy link
Contributor Author

Sorry for the long delay in my reply. What I did was modify startServer() in app.js to this:

function startServer() {
  app.shy = server.listen(config.port, config.ip, () => {
    console.log(`Express listening on port ${config.port}, env = ${app.get('env')}`);
    app.emit('appStarted'); // So mocha.global.js doesn't try to complete after all until Express starts
  });
}

Here are the contents of my mocha.global.js:

/* global after */
import app from './';

after(function(done) {
  // Unit tests are completing before /server/app.js:25 is executed causing an error
  // Set the close handler after app.shy starts
  app.on('appStarted', () => {
    app.shy.on('close', () => done());
    app.shy.close();
  });
});

While this workaround is effective, I think the issue is with angular-fullstack not adding the done() callback to generated unit tests. See this posting on StackOverflow.

I'm guessing that you had angular-fullstack scaffold out an authentication boilerplate for you. If so, can you try renaming the user.model.spec.js file to something like user.model.disabled.js then re-run gulp test? I'm going to log a separate issue for that particular unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants