Repository: nodejs/node
File: test/parallel/test-runner-run.mjs (JavaScript)

Code before:
      'suites 0',
      'pass 0',
      'fail 0',
      'cancelled 0',
      'skipped 0',
      'todo 0',
    ]
    ) {
      assert.strictEqual(diagnostics.includes(entry), true);
    }
  });
});

describe('env', () => {
  it('should allow env variables to be configured', async () => {
    // Set a variable on main process env and test it does not exist within test env.
    process.env.ABC = 'XYZ';
    const env = { FOOBAR: 'FUZZBUZZ' };
    // When Node.js is built as a shared library, the child process needs
    // library paths set so the dynamic linker can find libnode.so
    addLibraryPath(env);
    const stream = run({ files: [join(testFixtures, 'process-env.js')], env });
    stream.on('test:fail', common.mustNotCall());
    stream.on('test:pass', common.mustCall(1));
    // eslint-disable-next-line no-unused-vars
    for await (const _ of stream);
    delete process.env.ABC;
  });

  it('should throw error when env is specified with isolation=none', async () => {
    assert.throws(() => run({ env: { foo: 'bar' }, isolation: 'none' }), {
      code: 'ERR_INVALID_ARG_VALUE',
      message: /The property 'options\.env' is not supported with isolation='none'\. Received { foo: 'bar' }/
    });
  });
});

describe('forceExit', () => {
  it('throws for non-boolean values', () => {
    [Symbol(), {}, 0, 1, '1', Promise.resolve([])].forEach((forceExit) => {
      assert.throws(() => run({ forceExit }), {
        code: 'ERR_INVALID_ARG_TYPE',
        message: /The "options\.forceExit" property must be of type boolean\./
      });
    });
  });

  it('throws if enabled with watch mode', () => {
    assert.throws(() => run({ forceExit: true, watch: true }), {
      code: 'ERR_INVALID_ARG_VALUE',
      message: /The property 'options\.forceExit' is not supported with watch mode\./

Review comment (bug):
```suggestion
it('should allow env variables to be configured', async () => {
  const env = { ...process.env, FOOBAR: 'FUZZBUZZ' };

  process.env.ABC = 'XYZ';

  const stream = run({
    files: [join(testFixtures, 'process-env.js')],
    env,
  });

  stream.on('test:fail', common.mustNotCall());
  stream.on('test:pass', common.mustCall(1));

  for await (const _ of stream);

  delete process.env.ABC;
});
```

As some envs are injected by the testing environment I would just suggest this approach!

Code after:
      'pass 0',
      'fail 0',
      'cancelled 0',
      'skipped 0',
      'todo 0',
    ]
    ) {
      assert.strictEqual(diagnostics.includes(entry), true);
    }
  });
});

describe('env', () => {
  it('should allow env variables to be configured', async () => {
    // Need to inherit some process.env variables so it runs reliably across different environments.
    const env = { ...process.env, FOOBAR: 'FUZZBUZZ' };
    // Set a variable on main process env and test it does not exist within test env.
    process.env.ABC = 'XYZ';

    const stream = run({ files: [join(testFixtures, 'process-env.js')], env });
    stream.on('test:fail', common.mustNotCall());
    stream.on('test:pass', common.mustCall(1));
    // eslint-disable-next-line no-unused-vars
    for await (const _ of stream);
    delete process.env.ABC;
  });

  it('should throw error when env is specified with isolation=none', async () => {
    assert.throws(() => run({ env: { foo: 'bar' }, isolation: 'none' }), {
      code: 'ERR_INVALID_ARG_VALUE',
      message: /The property 'options\.env' is not supported with isolation='none'\. Received { foo: 'bar' }/
    });
  });
});

describe('forceExit', () => {
  it('throws for non-boolean values', () => {
    [Symbol(), {}, 0, 1, '1', Promise.resolve([])].forEach((forceExit) => {
      assert.throws(() => run({ forceExit }), {
        code: 'ERR_INVALID_ARG_TYPE',
        message: /The "options\.forceExit" property must be of type boolean\./
      });
    });
  });

  it('throws if enabled with watch mode', () => {
    assert.throws(() => run({ forceExit: true, watch: true }), {
      code: 'ERR_INVALID_ARG_VALUE',
      message: /The property 'options\.forceExit' is not supported with watch mode\./
    });
  });