Tools: prepare:webserver hook does not work how it is expected

Created on 7 Sep 2016  路  4Comments  路  Source: Polymer/tools

I am developing a plugin for WCT and I am using something like this:

wct.hook('prepare:webserver', function (app, done) {
    app.use(bodyParse.json());
    app.use('/my-url', myFunction);
});

Running WCT v4.3.1 it works well, but WCT v4.3.4 fails. It throws error "app is not found". It seems the first parameter is "done" and "app" was disappeared :S

I think this hook should receive app in any version of WCT... but I have not found any information about it.

web-component-tester Medium Available Bug wontfix

Most helpful comment

The issue here is the conflict between the promise and callback forms of emitHook.
In context.ts the arguments length is expected to be greater then 2 because it always expects to have at least 2 arguments with the done callback to be the last parameter, which is not always true in the promise form. Indeed, one of the possible signature is a name and a vararg.

In this particular case, it considers the Express application to be the done callback. The promise form is used to emit the 'prepare:webserver'

I'm not sure how to fix this since there are many solutions. Since all the hooks in wct are triggered using the Promise form, I would get rid of the callback form. Maybe @rictic has a better opinion on that.

Hopefully this will be fixed soon since web-component-tester-istanbul is broken.

All 4 comments

The issue here is the conflict between the promise and callback forms of emitHook.
In context.ts the arguments length is expected to be greater then 2 because it always expects to have at least 2 arguments with the done callback to be the last parameter, which is not always true in the promise form. Indeed, one of the possible signature is a name and a vararg.

In this particular case, it considers the Express application to be the done callback. The promise form is used to emit the 'prepare:webserver'

I'm not sure how to fix this since there are many solutions. Since all the hooks in wct are triggered using the Promise form, I would get rid of the callback form. Maybe @rictic has a better opinion on that.

Hopefully this will be fixed soon since web-component-tester-istanbul is broken.

I have the exact same issue when using the promise form:

wct.conf.js:

module.exports = {
  registerHooks: (wct) => wct.hook('prepare:webserver', (app) => {
    console.log(app, app.use)
    return Promise.resolve()
  })
}

Executing the tests shows that app is a [Function] and obviously this is not the express application as app.use is undefined. As @hypnoce said, It seems app is passed the done function whatever the arguments length is and that there is no way to access the express application.

Is any workaround other than reverting back to WCT v4.3.1 available?

This is a duplicate bug, for workaround see https://github.com/Polymer/web-component-tester/issues/373

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings