sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

Context merging in hooks #1761

Closed antoniomuso closed 3 years ago

antoniomuso commented 3 years ago

Describe the bug

I expect that the context will be merged, but in the following code only startTime is printed.

const got = require('got');
const {performance} = require('perf_hooks');

const http = got.extend({
    hooks: {
        beforeRequest: [
            (options) => {
                console.log(options.url)
                options.context.test = 10;
            },
            (options) => {
                options.context = {
                    startTime: performance.now(),
                };
            },
            (options) => {
                console.log(options.context.test, options.context.startTime );
            }
        ],

    }
})

http('http://google.com')

...

Checklist

sindresorhus commented 3 years ago

Mergeable context has not yet been released: https://github.com/sindresorhus/got/commit/2b8ed1f5a185f30603d24e2ceb8181782de3bc5a

Remember to read the docs for the version you're using, not the main branch.

antoniomuso commented 3 years ago

Thanks for the answer. I have supposed that was integrated because MR was on 21 October 2020. and version 11.8.2 was of 26 February 2021.