11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// Regression test for https://github.com/nodejs/node/issues/13237
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst common = require('../common');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciif (!common.isMainThread)
91cb0ef41Sopenharmony_ci  common.skip('Worker bootstrapping works differently -> different timing');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst async_hooks = require('async_hooks');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst seenEvents = [];
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst p = new Promise((resolve) => resolve(1));
161cb0ef41Sopenharmony_cip.then(() => seenEvents.push('then'));
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciconst hooks = async_hooks.createHook({
191cb0ef41Sopenharmony_ci  init: common.mustNotCall(),
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  before: common.mustCall((id) => {
221cb0ef41Sopenharmony_ci    assert.ok(id > 1);
231cb0ef41Sopenharmony_ci    seenEvents.push('before');
241cb0ef41Sopenharmony_ci  }),
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  after: common.mustCall((id) => {
271cb0ef41Sopenharmony_ci    assert.ok(id > 1);
281cb0ef41Sopenharmony_ci    seenEvents.push('after');
291cb0ef41Sopenharmony_ci    hooks.disable();
301cb0ef41Sopenharmony_ci  })
311cb0ef41Sopenharmony_ci});
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_cisetImmediate(() => {
341cb0ef41Sopenharmony_ci  assert.deepStrictEqual(seenEvents, ['before', 'then', 'after']);
351cb0ef41Sopenharmony_ci});
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_cihooks.enable(); // After `setImmediate` in order to not catch its init event.
38