Repository: nodejs/node
File: test/parallel/test-fs-promises-watch.js (JavaScript)

Code before:
    for await (const _ of watch('', { persistent: 1 })) { }
  },
  { code: 'ERR_INVALID_ARG_TYPE' }).then(common.mustCall());

assert.rejects(
  async () => {
    // eslint-disable-next-line no-unused-vars, no-empty
    for await (const _ of watch('', { recursive: 1 })) { }
  },
  { code: 'ERR_INVALID_ARG_TYPE' }).then(common.mustCall());

assert.rejects(
  async () => {
    // eslint-disable-next-line no-unused-vars, no-empty
    for await (const _ of watch('', { encoding: 1 })) { }
  },
  { code: 'ERR_INVALID_ARG_VALUE' }).then(common.mustCall());

assert.rejects(
  async () => {
    // eslint-disable-next-line no-unused-vars, no-empty
    for await (const _ of watch('', { signal: 1 })) { }
  },
  { code: 'ERR_INVALID_ARG_TYPE' }).then(common.mustCall());

assert.throws(() => watch('', { maxQueue: 'silly' }), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => watch('', { overflow: 1 }), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => watch('', { overflow: 'barf' }), { code: 'ERR_INVALID_ARG_TYPE' });
(async () => {
  const ac = new AbortController();
  const { signal } = ac;
  setImmediate(() => ac.abort());
  try {
    // eslint-disable-next-line no-unused-vars, no-empty
    for await (const _ of watch(__filename, { signal })) { }
  } catch (err) {
    assert.strictEqual(err.name, 'AbortError');
  }
})().then(common.mustCall());


Review comment (bug):
oops, actually I was wrong, this is rejected because the function is overall an async function. So it needs to be reverted to the previous version. Sorry for the noise ;)

Code after:
    for await (const _ of watch('', { persistent: 1 })) { }
  },
  { code: 'ERR_INVALID_ARG_TYPE' }).then(common.mustCall());

assert.rejects(
  async () => {
    // eslint-disable-next-line no-unused-vars, no-empty
    for await (const _ of watch('', { recursive: 1 })) { }
  },
  { code: 'ERR_INVALID_ARG_TYPE' }).then(common.mustCall());

assert.rejects(
  async () => {
    // eslint-disable-next-line no-unused-vars, no-empty
    for await (const _ of watch('', { encoding: 1 })) { }
  },
  { code: 'ERR_INVALID_ARG_VALUE' }).then(common.mustCall());

assert.rejects(
  async () => {
    // eslint-disable-next-line no-unused-vars, no-empty
    for await (const _ of watch('', { signal: 1 })) { }
  },
  { code: 'ERR_INVALID_ARG_TYPE' }).then(common.mustCall());

assert.rejects(
  async () => {
    // eslint-disable-next-line no-unused-vars, no-empty
    for await (const _ of watch('', { maxQueue: 'silly' })) { }
  },
  { code: 'ERR_INVALID_ARG_TYPE' }).then(common.mustCall());
assert.rejects(
  async () => {
    // eslint-disable-next-line no-unused-vars, no-empty
    for await (const _ of watch('', { overflow: 1 })) { }
  },
  { code: 'ERR_INVALID_ARG_VALUE' }).then(common.mustCall());
assert.rejects(
  async () => {
    // eslint-disable-next-line no-unused-vars, no-empty
    for await (const _ of watch('', { overflow: 'barf' })) { }
  },
  { code: 'ERR_INVALID_ARG_VALUE' }).then(common.mustCall());

(async () => {
  const ac = new AbortController();
  const { signal } = ac;
  setImmediate(() => ac.abort());
  try {
    // eslint-disable-next-line no-unused-vars, no-empty
    for await (const _ of watch(__filename, { signal })) { }