summaryrefslogtreecommitdiff
path: root/test/async-hooks/test-embedder.api.async-resource-no-type.js
blob: 69b6667edb674cd6acf08e8144874a5f9f4423a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';

const common = require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');
const { AsyncResource } = async_hooks;
const { spawn } = require('child_process');

const initHooks = require('./init-hooks');

if (process.argv[2] === 'child') {
  initHooks().enable();

  class Foo extends AsyncResource {
    constructor(type) {
      super(type, async_hooks.executionAsyncId());
    }
  }

  [null, undefined, 1, Date, {}, []].forEach((i) => {
    common.expectsError(() => new Foo(i), {
      code: 'ERR_INVALID_ARG_TYPE',
      type: TypeError
    });
  });

} else {
  const args = process.argv.slice(1).concat('child');
  spawn(process.execPath, args)
    .on('close', common.mustCall((code) => {
      // No error because the type was defaulted
      assert.strictEqual(code, 0);
    }));
}