How to use the jest-worker.default function in jest-worker

To help you get started, we’ve selected a few jest-worker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gridsome / gridsome / packages / plugin-critical / index.js View on Github external
api.afterBuild(async ({ queue, config }) => {
    const { outputDir: base, pathPrefix, publicPath } = config
    const patterns = options.paths.map(p => normalize(p))

    const pages = queue.filter(page => {
      return micromatch(page.path, patterns).length
    })

    const worker = new Worker(require.resolve('./lib/worker'))

    console.log(`Extract critical CSS (${pages.length} pages)`)

    await Promise.all(pages.map(async ({ htmlOutput }) => {
      try {
        await worker.generate(htmlOutput, {
          ignore: options.ignore,
          width: options.width,
          height: options.height,
          // TODO: remove pathPrefix fallback
          pathPrefix: publicPath || pathPrefix || '/',
          polyfill: options.polyfill,
          base
        })
      } catch (err) {
        worker.end()
github FormidableLabs / serverless-jetpack / index.js View on Github external
numLayers = layersPkgsToPackage.length;
      tasks = tasks.concat(layersPkgsToPackage.map((obj) => () =>
        this.packageLayer({ ...obj, worker, report })
      ));
    }

    // Run all packaging work.
    this._log(
      `Packaging ${numFns} functions, ${shouldPackageService ? 1 : 0} services, and `
      + `${numLayers} layers with concurrency ${concurrency}`
    );

    let results;
    if (concurrency > 1) {
      // Run concurrently.
      worker = new Worker(require.resolve("./util/bundle"), {
        numWorkers: concurrency
      });
      results = await Promise.all(tasks.map((fn) => fn()));
      worker.end();
    } else {
      // Run serially in-band.
      const limit = pLimit(1);
      results = await Promise.all(tasks.map(limit));
    }

    // Report.
    if (report) {
      this._report({ results });
    }

    return results;
github facebook / metro / packages / metro / src / DeltaBundler / WorkerFarm.js View on Github external
_makeFarm(
    workerPath: string,
    exposedMethods: $ReadOnlyArray,
    numWorkers: number,
  ) {
    const env = {
      ...process.env,
      // Force color to print syntax highlighted code frames.
      FORCE_COLOR: 1,
    };

    return new JestWorker(workerPath, {
      computeWorkerKey: this._config.stickyWorkers
        ? this._computeWorkerKey
        : undefined,
      exposedMethods,
      forkOptions: {env},
      numWorkers,
    });
  }
github vincentriemer / addimated / scripts / build.js View on Github external
function createWorker(path) {
  if (process.env.CI == null) {
    return new Worker(path);
  }
  return require(path);
}
github rtsao / create-universal-package / packages / create-universal-package / build.js View on Github external
module.exports = async function build(argv /*: BuildOpts */) {
  const worker = new Worker(path.join(__dirname, 'worker.js'));
  worker.getStdout().pipe(process.stdout);
  worker.getStderr().pipe(process.stderr);

  if (!argv.skipPreflight) {
    const preflight = require('./preflight.js');
    try {
      await preflight(path.join(argv.dir, 'package.json'));
    } catch (err) {
      worker.end();
      throw err;
    }
  }

  const files = await glob('src/**/*.js', {
    cwd: argv.dir,
    filesOnly: true,
github rtsao / create-universal-package / packages / create-universal-package / lib / build.js View on Github external
function build(opts, variants = {}, preflight) {
  const worker = new Worker(require.resolve('./worker.js'), {
    exposedMethods: ['build', 'preflight', 'buildBrowser', 'genFlowLibdef'],
  });

  const baseInputOptions = {
    input: path.join(opts.dir, 'src/index.js'),
    pureExternalModules: true,
  };
  const browserInputOptions = {
    ...baseInputOptions,
  };
  const nodeInputOptions = {
    ...baseInputOptions,
  };

  const generateFlowLibdef =
    !opts.separateEntries &&
github gridsome / gridsome / gridsome / lib / app / createWorker.js View on Github external
module.exports = (config, numWorkers) => {
  const workerPath = require.resolve('./worker')

  return new Worker(workerPath, {
    numWorkers,
    forkOptions: {
      stdio: ['pipe', 'pipe', process.stderr, 'ipc']
    }
  })
}
github kentcdodds / js-mocking-fundamentals / other / create-node-runner / node-runner.js View on Github external
module.exports = async ({testPath}) => {
  const worker = new Worker(require.resolve('./require-module'))
  worker.getStdout().pipe(process.stdout)
  worker.getStderr().pipe(process.stderr)
  process.stdout.write('\n')
  const start = +new Date()
  try {
    await worker.require(testPath)
    return pass({
      start,
      end: +new Date(),
      test: {path: testPath}
    })
  } catch (error) {
    return fail({
      start,
      end: +new Date(),
      test: {
github fusionjs / fusionjs / fusion-cli / build / compiler.js View on Github external
function createWorker() {
  if (require('os').cpus().length < 2) return void 0;
  return new Worker(require.resolve('./loaders/babel-worker.js'), {
    exposedMethods: ['runTransformation'],
    forkOptions: {stdio: 'inherit'},
  });
}

jest-worker

Module for executing heavy tasks under forked processes in parallel, by providing a `Promise` based interface, minimum overhead, and bound workers.

MIT
Latest version published 1 year ago

Package Health Score

88 / 100
Full package analysis

Popular jest-worker functions

Similar packages