Git Product home page Git Product logo

foreground-child's Introduction

@tapjs

Workspace for node-tap development.

Dev Commands

Do this at least once to get everything set up and ready to go:

npm run bootstrap

(Note: npm install will not work until you do this, because the generated TypeScript eats its own tail.)


Build the test class (required after any plugin or core changes):

npm run build

Any other builds:

npm run prepare -w src/{whatever}

After adding or removing workspaces:

npm i

Run all tests in all workspaces:

npm test

Run all tests, saving snapshots:

npm run snap

Build and serve docs:

npm start

Contents

  • tap The main entry point module, which sets up the root test runner and exposes an alias to the cli runner.
  • tap-parser The module that parses TAP
  • @tapjs/core Most of the basic moving parts of tap
  • tap-yaml Thin wrapper around YAML and yaml-types for consistent handling of JavaScript values in YAML diagnostics.
  • @tapjs/test The plugin-ified Test class.
  • @tapjs/config Handling config files, command line interface parsing, environment variables, and validation
  • @tapjs/run The command line runner
  • tcompare The library that does comparison and object formatting (use heavily by @tapjs/asserts methods).
  • @tapjs/stack Library for capturing stack frames, the descendant of stack-utils.
  • @tapjs/processinfo The library that tracks process information and code coverage (hosted outside the monorepo, because it can't be tested by a version of tap that uses itself without bootstrap paradoxes)
  • default plugins:
  • optional plugins:
  • other stuff:
    • npm-init-template A library for more easily creating npm init packages. This will move out as soon as this version of tap is published.
    • @tapjs/create-plugin An npm init library facilitating npm init @tapjs/plugin to create new plugins.

Bootstrap and skipLibCheck

Run npm run bootstrap to build the @tapjs/test module with the default set of plugins, so that the other libraries can build properly. (This only has to be done once, unless the build script or set of default plugins are changed, of course.)

Because there's a bootstrapping cycle between @tapjs/core, @tapjs/test, and all of the plugins, they MUST use skipLibCheck: true in their tsconfigs. It should not be used in other packages.

foreground-child's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

foreground-child's Issues

it would be useful to have a beforeExit event, for the parent process.

It would be useful to be able to have an asynchronous beforeExit event that the parent process can hook into.

@Raynos has requested that nyc combine the reporting and instrumenting step, which I agree is a nice simplification, to do this I would need to be able to execute the reporter when foreground-child exits.

v2 throws with invalid arg type

Context

As part of an effort to augment mocha toolchains with standard posix exit codes, we found a key component of our toolchain (nyc) use [email protected] which manifests this issue.

the error

[email protected] can throw an invalid arg type error under certain conditions:

throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
^

TypeError: The "code" argument must be of type number. Received type string ('128SIGABRT')
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at ChildProcess.<anonymous> (/Users/foo/bar/node_modules/nyc/node_modules/foreground-child/index.js:63:22)
    at ChildProcess.emit (node:events:514:28)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}

root cause

This line assigns a value 128 + signal, resulting in a string eg. "128SIGABRT" instead of a numeric value.

process.exitCode = signal ? 128 + signal : code;

suggested fix

Use os.constants.signals for numerical values of signal strings; eg.

if (typeof signal === 'string') {
    process.exitCode = signal ? 128 + require('os').constants.signals[signal] : code;
} else {
    process.exitCode = signal ? 128 + signal : code;
}

reason to back-patch

Since foreground-child: ^2.0.0 is used by the latest version of nyc it would be helpful to patch v2.0.0 to fix the issue for projects that won't upgrade to [email protected] right away.

steps to reproduce

Given the test file oom.unit.js

describe('OOM error', () => {
  it('should cause an oom error', async () => {
    const x = [];
    while (true) {
      x.push({a: '123'.repeat(1000000) });
    }
  });
});

Running the following command reproduces the error

nyc mocha src/test/server/oom.unit.js

No longer compatible with Node < 14.16 since v3.x, update engines.node

Since the use of the node: import prefix at https://github.com/tapjs/foreground-child/blob/v3.0.0/src/all-signals.ts#L1 this library has become incompatible with Node.js < 16. Found this through using c8 in a failed automated test run at https://github.com/metalsmith/metalsmith/actions/runs/7854693798/job/21435716699.

Error: Cannot find module 'node:constants'

Even though npm view c8@latest engines.node returns >=14.14.0
Please revert to importing from constants OR update engines.node to >=16

[email protected] breaks tests on Windows

I tried upgrading to the newest foreground-child in nyc tonight, but it broke yargs' and node_redis' test-suite on Windows:

screen shot 2016-01-20 at 8 25 08 pm

It seems as though something broke between 1.3.3 and 1.3.4 that does not allow nyc to directly invoke mocha, .e.g.,

nyc mocha

SIGHUP is not supported on Windows

Windows 10
Node.js 18.0.0
foreground-child 2.0.0


When the parent process terminates, it sends a SIGHUP signal to kill the child:

child.kill('SIGHUP')

This is failing on Windows, apparently because SIGHUP is not supported:

     Error: kill ENOSYS
      at ChildProcess.kill (node:internal/child_process:501:13)

The error message is not helpful, but a comment line in the source code of child_process explains it:

https://github.com/nodejs/node/blob/v18.0.0/lib/internal/child_process.js#L500-L501

      /* The underlying platform doesn't support this signal. */
      throw errnoException(err, 'kill');

Maybe send SIGTERM on Windows and SIGHUP on other platforms?

sometimes dead loop

Version

When

  • sometimes, not reproducible

Error

  • 100% CPU, guess somehow dead loop

  • After Ctrl-C

TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('128SIGINT')
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at ChildProcess.<anonymous> (/home/vscode/.yarn/berry/cache/foreground-child-npm-2.0.0-80c976b61e-8.zip/node_modules/foreground-child/index.js:63:22)
    at ChildProcess.emit (node:events:514:28)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v20.8.0

Related

Maybe caused by below line.

process.exitCode = signal ? 128 + signal : code

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/39359c8466846541b5b3298165ef79c509f0cd09/types/node/child_process.d.ts#L532

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/39359c8466846541b5b3298165ef79c509f0cd09/types/node/v16/process.d.ts#L63-L100

The signal should be null or some const string.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.