How to get grunt.js to start an express app for testing

后端 未结 2 736
一生所求
一生所求 2021-02-15 15:56

My current situation is that I use grunt to make a production version of my express app (minimize and merge all the js/css, copy all the files in place) and then I have to run a

2条回答
  •  情书的邮戳
    2021-02-15 16:19

    If you check grunt-express which is a plugin for express web-server tasks via grunt.

    express-keepalive

    Note that this server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops. This behavior can be changed by appending a express-keepalive task at the end of your task list like so

    grunt.registerTask('myServer', ['express', 'express-keepalive']);
    Now when you run grunt myServer, your express server will be kept alive until you manually terminate it.

    Such feature can also be enabled ad-hoc by running the task like grunt express express-keepalive.

    This design gives you the flexibility to use grunt-express in conjunction with another task that is run immediately afterwards, like the grunt-contrib-qunit plugin qunit task. If we force express task to be always async, such use case can no longer happen.

    From the guide grunt-contrib-qunit package is used to run QUnit unit tests in a headless PhantomJS instance. Also mind the last line, if you force express to be always async it would be of no use.

    npm link for grunt-express.

提交回复
热议问题