Best JavaScript code snippet using storybook-test-runner
ChildProcessWorker.test.js
Source:ChildProcessWorker.test.js
1/**2 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 */7import EventEmitter from 'events';8import {PassThrough} from 'stream';9import getStream from 'get-stream';10import supportsColor from 'supports-color';11import {12 CHILD_MESSAGE_CALL,13 CHILD_MESSAGE_INITIALIZE,14 PARENT_MESSAGE_CLIENT_ERROR,15 PARENT_MESSAGE_CUSTOM,16 PARENT_MESSAGE_OK,17} from '../../types';18jest.useFakeTimers();19let Worker;20let forkInterface;21let childProcess;22let originalExecArgv;23beforeEach(() => {24 jest.mock('child_process');25 originalExecArgv = process.execArgv;26 childProcess = require('child_process');27 childProcess.fork.mockImplementation(() => {28 forkInterface = Object.assign(new EventEmitter(), {29 kill: jest.fn(),30 send: jest.fn(),31 stderr: new PassThrough(),32 stdout: new PassThrough(),33 });34 return forkInterface;35 });36 Worker = require('../ChildProcessWorker').default;37});38afterEach(() => {39 jest.resetModules();40 process.execArgv = originalExecArgv;41});42it('passes fork options down to child_process.fork, adding the defaults', () => {43 const child = require.resolve('../processChild');44 process.execArgv = ['--inspect', '-p'];45 // eslint-disable-next-line no-new46 new Worker({47 forkOptions: {48 cwd: '/tmp',49 execPath: 'hello',50 },51 maxRetries: 3,52 workerId: process.env.JEST_WORKER_ID - 1,53 workerPath: '/tmp/foo/bar/baz.js',54 });55 expect(childProcess.fork.mock.calls[0][0]).toBe(child);56 expect(childProcess.fork.mock.calls[0][2]).toEqual({57 cwd: '/tmp', // Overridden default option.58 env: {...process.env, FORCE_COLOR: supportsColor.stdout ? '1' : undefined}, // Default option.59 execArgv: ['-p'], // Filtered option.60 execPath: 'hello', // Added option.61 silent: true, // Default option.62 });63});64it('passes workerId to the child process and assign it to 1-indexed env.JEST_WORKER_ID', () => {65 // eslint-disable-next-line no-new66 new Worker({67 forkOptions: {},68 maxRetries: 3,69 workerId: 2,70 workerPath: '/tmp/foo',71 });72 expect(childProcess.fork.mock.calls[0][2].env.JEST_WORKER_ID).toEqual('3');73});74it('initializes the child process with the given workerPath', () => {75 // eslint-disable-next-line no-new76 new Worker({77 forkOptions: {},78 maxRetries: 3,79 setupArgs: ['foo', 'bar'],80 workerPath: '/tmp/foo/bar/baz.js',81 });82 expect(forkInterface.send.mock.calls[0][0]).toEqual([83 CHILD_MESSAGE_INITIALIZE,84 false,85 '/tmp/foo/bar/baz.js',86 ['foo', 'bar'],87 ]);88});89it('stops initializing the worker after the amount of retries is exceeded', () => {90 const worker = new Worker({91 forkOptions: {},92 maxRetries: 3,93 workerPath: '/tmp/foo/bar/baz.js',94 });95 const request = [CHILD_MESSAGE_CALL, false, 'foo', []];96 const onProcessStart = jest.fn();97 const onProcessEnd = jest.fn();98 worker.send(request, onProcessStart, onProcessEnd);99 // We fail four times (initial + three retries).100 forkInterface.emit('exit', 1);101 forkInterface.emit('exit', 1);102 forkInterface.emit('exit', 1);103 forkInterface.emit('exit', 1);104 expect(childProcess.fork).toHaveBeenCalledTimes(5);105 expect(onProcessStart).toBeCalledWith(worker);106 expect(onProcessEnd).toHaveBeenCalledTimes(1);107 expect(onProcessEnd.mock.calls[0][0]).toBeInstanceOf(Error);108 expect(onProcessEnd.mock.calls[0][0].type).toBe('WorkerError');109 expect(onProcessEnd.mock.calls[0][1]).toBe(null);110});111it('provides stdout and stderr from the child processes', async () => {112 const worker = new Worker({113 forkOptions: {},114 maxRetries: 3,115 workerPath: '/tmp/foo',116 });117 const stdout = worker.getStdout();118 const stderr = worker.getStderr();119 forkInterface.stdout.end('Hello ', 'utf8');120 forkInterface.stderr.end('Jest ', 'utf8');121 forkInterface.emit('exit', 1);122 forkInterface.stdout.end('World!', 'utf8');123 forkInterface.stderr.end('Workers!', 'utf8');124 forkInterface.emit('exit', 0);125 await expect(getStream(stdout)).resolves.toEqual('Hello World!');126 await expect(getStream(stderr)).resolves.toEqual('Jest Workers!');127});128it('sends the task to the child process', () => {129 const worker = new Worker({130 forkOptions: {},131 maxRetries: 3,132 setupArgs: [],133 workerPath: '/tmp/foo',134 });135 const request = [CHILD_MESSAGE_CALL, false, 'foo', []];136 worker.send(137 request,138 () => {},139 () => {},140 );141 // Skipping call "0" because it corresponds to the "initialize" one.142 expect(forkInterface.send.mock.calls[1][0]).toEqual(request);143});144it('resends the task to the child process after a retry', () => {145 const worker = new Worker({146 forkOptions: {},147 maxRetries: 3,148 workerPath: '/tmp/foo/bar/baz.js',149 });150 const request = [CHILD_MESSAGE_CALL, false, 'foo', []];151 worker.send(152 request,153 () => {},154 () => {},155 );156 // Skipping call "0" because it corresponds to the "initialize" one.157 expect(forkInterface.send.mock.calls[1][0]).toEqual(request);158 const previousForkInterface = forkInterface;159 forkInterface.emit('exit', 1);160 expect(forkInterface).not.toBe(previousForkInterface);161 // Skipping call "0" because it corresponds to the "initialize" one.162 expect(forkInterface.send.mock.calls[1][0]).toEqual(request);163});164it('calls the onProcessStart method synchronously if the queue is empty', () => {165 const worker = new Worker({166 forkOptions: {},167 maxRetries: 3,168 workerPath: '/tmp/foo',169 });170 const onProcessStart = jest.fn();171 const onProcessEnd = jest.fn();172 worker.send(173 [CHILD_MESSAGE_CALL, false, 'foo', []],174 onProcessStart,175 onProcessEnd,176 );177 // Only onProcessStart has been called178 expect(onProcessStart).toHaveBeenCalledTimes(1);179 expect(onProcessEnd).not.toHaveBeenCalled();180 // then first call replies...181 forkInterface.emit('message', [PARENT_MESSAGE_OK]);182 expect(onProcessEnd).toHaveBeenCalledTimes(1);183});184it('can send multiple messages to parent', () => {185 const worker = new Worker({186 forkOptions: {},187 maxRetries: 3,188 workerPath: '/tmp/foo',189 });190 const onProcessStart = jest.fn();191 const onProcessEnd = jest.fn();192 const onCustomMessage = jest.fn();193 worker.send(194 [CHILD_MESSAGE_CALL, false, 'foo', []],195 onProcessStart,196 onProcessEnd,197 onCustomMessage,198 );199 // Only onProcessStart has been called200 expect(onProcessStart).toHaveBeenCalledTimes(1);201 expect(onProcessEnd).not.toHaveBeenCalled();202 expect(onCustomMessage).not.toHaveBeenCalled();203 // then first call replies...204 forkInterface.emit('message', [205 PARENT_MESSAGE_CUSTOM,206 {message: 'foo bar', otherKey: 1},207 ]);208 expect(onProcessEnd).not.toHaveBeenCalled();209 expect(onCustomMessage).toHaveBeenCalledTimes(1);210 expect(onCustomMessage).toHaveBeenCalledWith({211 message: 'foo bar',212 otherKey: 1,213 });214});215it('creates error instances for known errors', () => {216 const worker = new Worker({217 forkOptions: {},218 maxRetries: 3,219 workerPath: '/tmp/foo',220 });221 const callback1 = jest.fn();222 const callback2 = jest.fn();223 const callback3 = jest.fn();224 // Testing a generic ECMAScript error.225 worker.send([CHILD_MESSAGE_CALL, false, 'method', []], () => {}, callback1);226 forkInterface.emit('message', [227 PARENT_MESSAGE_CLIENT_ERROR,228 'TypeError',229 'bar',230 'TypeError: bar',231 {},232 ]);233 expect(callback1.mock.calls[0][0]).toBeInstanceOf(TypeError);234 expect(callback1.mock.calls[0][0].message).toBe('bar');235 expect(callback1.mock.calls[0][0].type).toBe('TypeError');236 expect(callback1.mock.calls[0][0].stack).toBe('TypeError: bar');237 // Testing a custom error.238 worker.send([CHILD_MESSAGE_CALL, false, 'method', []], () => {}, callback2);239 forkInterface.emit('message', [240 PARENT_MESSAGE_CLIENT_ERROR,241 'RandomCustomError',242 'bar',243 'RandomCustomError: bar',244 {qux: 'extra property'},245 ]);246 expect(callback2.mock.calls[0][0]).toBeInstanceOf(Error);247 expect(callback2.mock.calls[0][0].message).toBe('bar');248 expect(callback2.mock.calls[0][0].type).toBe('RandomCustomError');249 expect(callback2.mock.calls[0][0].stack).toBe('RandomCustomError: bar');250 expect(callback2.mock.calls[0][0].qux).toBe('extra property');251 // Testing a non-object throw.252 worker.send([CHILD_MESSAGE_CALL, false, 'method', []], () => {}, callback3);253 forkInterface.emit('message', [254 PARENT_MESSAGE_CLIENT_ERROR,255 'Number',256 null,257 null,258 412,259 ]);260 expect(callback3.mock.calls[0][0]).toBe(412);261});262it('throws when the child process returns a strange message', () => {263 const worker = new Worker({264 forkOptions: {},265 maxRetries: 3,266 workerPath: '/tmp/foo',267 });268 worker.send(269 [CHILD_MESSAGE_CALL, false, 'method', []],270 () => {},271 () => {},272 );273 // Type 27 does not exist.274 expect(() => {275 forkInterface.emit('message', [27]);276 }).toThrow(TypeError);277});278it('does not restart the child if it cleanly exited', () => {279 // eslint-disable-next-line no-new280 new Worker({281 forkOptions: {},282 maxRetries: 3,283 workerPath: '/tmp/foo',284 });285 expect(childProcess.fork).toHaveBeenCalledTimes(1);286 forkInterface.emit('exit', 0);287 expect(childProcess.fork).toHaveBeenCalledTimes(1);288});289it('resolves waitForExit() after the child process cleanly exited', async () => {290 const worker = new Worker({291 forkOptions: {},292 maxRetries: 3,293 workerPath: '/tmp/foo',294 });295 expect(childProcess.fork).toHaveBeenCalledTimes(1);296 forkInterface.emit('exit', 0);297 await worker.waitForExit(); // should not timeout298});299it('restarts the child when the child process dies', () => {300 // eslint-disable-next-line no-new301 new Worker({302 workerPath: '/tmp/foo',303 });304 expect(childProcess.fork).toHaveBeenCalledTimes(1);305 forkInterface.emit('exit', 1);306 expect(childProcess.fork).toHaveBeenCalledTimes(2);307});308it('sends SIGTERM when forceExit() is called', async () => {309 const worker = new Worker({310 forkOptions: {},311 maxRetries: 3,312 workerPath: '/tmp/foo',313 });314 worker.forceExit();315 expect(forkInterface.kill.mock.calls).toEqual([['SIGTERM']]);316});317it('sends SIGKILL some time after SIGTERM', async () => {318 const worker = new Worker({319 forkOptions: {},320 maxRetries: 3,321 workerPath: '/tmp/foo',322 });323 worker.forceExit();324 jest.runAllTimers();325 expect(forkInterface.kill.mock.calls).toEqual([['SIGTERM'], ['SIGKILL']]);326});327it('does not send SIGKILL if SIGTERM exited the process', async () => {328 const worker = new Worker({329 forkOptions: {},330 maxRetries: 3,331 workerPath: '/tmp/foo',332 });333 worker.forceExit();334 forkInterface.emit('exit', 143 /* SIGTERM exit code */);335 await Promise.resolve();336 jest.runAllTimers();337 expect(forkInterface.kill.mock.calls).toEqual([['SIGTERM']]);...
NodeThreadsWorker.test.js
Source:NodeThreadsWorker.test.js
1/**2 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 */7'use strict';8import getStream from 'get-stream';9import {10 CHILD_MESSAGE_CALL,11 CHILD_MESSAGE_INITIALIZE,12 PARENT_MESSAGE_CLIENT_ERROR,13 PARENT_MESSAGE_CUSTOM,14 PARENT_MESSAGE_OK,15} from '../../types';16let Worker;17let workerThreads;18let originalExecArgv;19beforeEach(() => {20 jest.mock('worker_threads', () => {21 const fakeClass = jest.fn(() => {22 const EventEmitter = require('events');23 const {PassThrough} = require('stream');24 const thread = new EventEmitter();25 thread.postMessage = jest.fn();26 thread.terminate = jest.fn();27 thread.stdout = new PassThrough();28 thread.stderr = new PassThrough();29 return thread;30 });31 return {32 Worker: fakeClass,33 };34 });35 originalExecArgv = process.execArgv;36 workerThreads = require('worker_threads').Worker;37 workerThreads.postMessage = jest.fn();38 Worker = require('../NodeThreadsWorker').default;39});40afterEach(() => {41 jest.resetModules();42 process.execArgv = originalExecArgv;43});44it('passes fork options down to child_process.fork, adding the defaults', () => {45 const thread = require.resolve('../threadChild');46 process.execArgv = ['--inspect', '-p'];47 // eslint-disable-next-line no-new48 new Worker({49 forkOptions: {50 cwd: '/tmp',51 execPath: 'hello',52 },53 maxRetries: 3,54 workerId: process.env.JEST_WORKER_ID - 1,55 workerPath: '/tmp/foo/bar/baz.js',56 });57 expect(workerThreads.mock.calls[0][0]).toBe(thread.replace(/\.ts$/, '.js'));58 expect(workerThreads.mock.calls[0][1]).toEqual({59 eval: false,60 stderr: true,61 stdout: true,62 workerData: {63 cwd: '/tmp', // Overridden default option.64 env: process.env, // Default option.65 execArgv: ['-p'], // Filtered option.66 execPath: 'hello', // Added option.67 silent: true, // Default option.68 },69 });70});71it('passes workerId to the thread and assign it to env.JEST_WORKER_ID', () => {72 // eslint-disable-next-line no-new73 new Worker({74 forkOptions: {},75 maxRetries: 3,76 workerId: 2,77 workerPath: '/tmp/foo',78 });79 expect(workerThreads.mock.calls[0][1].workerData.env.JEST_WORKER_ID).toEqual(80 '3',81 );82});83it('initializes the thread with the given workerPath', () => {84 const worker = new Worker({85 forkOptions: {},86 maxRetries: 3,87 setupArgs: ['foo', 'bar'],88 workerPath: '/tmp/foo/bar/baz.js',89 });90 expect(worker._worker.postMessage.mock.calls[0][0]).toEqual([91 CHILD_MESSAGE_INITIALIZE,92 false,93 '/tmp/foo/bar/baz.js',94 ['foo', 'bar'],95 ]);96});97it('stops initializing the worker after the amount of retries is exceeded', () => {98 const worker = new Worker({99 forkOptions: {},100 maxRetries: 3,101 workerPath: '/tmp/foo/bar/baz.js',102 });103 const request = [CHILD_MESSAGE_CALL, false, 'foo', []];104 const onProcessStart = jest.fn();105 const onProcessEnd = jest.fn();106 worker.send(request, onProcessStart, onProcessEnd);107 // We fail four times (initial + three retries).108 worker._worker.emit('exit');109 worker._worker.emit('exit');110 worker._worker.emit('exit');111 worker._worker.emit('exit');112 expect(workerThreads).toHaveBeenCalledTimes(5);113 expect(onProcessStart).toBeCalledWith(worker);114 expect(onProcessEnd).toHaveBeenCalledTimes(1);115 expect(onProcessEnd.mock.calls[0][0]).toBeInstanceOf(Error);116 expect(onProcessEnd.mock.calls[0][0].type).toBe('WorkerError');117 expect(onProcessEnd.mock.calls[0][1]).toBe(null);118});119it('provides stdout and stderr from the threads', async () => {120 const worker = new Worker({121 forkOptions: {},122 maxRetries: 3,123 workerPath: '/tmp/foo',124 });125 const stdout = worker.getStdout();126 const stderr = worker.getStderr();127 worker._worker.stdout.end('Hello ', 'utf8');128 worker._worker.stderr.end('Jest ', 'utf8');129 worker._worker.emit('exit');130 worker._worker.stdout.end('World!', 'utf8');131 worker._worker.stderr.end('Workers!', 'utf8');132 worker._worker.emit('exit', 0);133 await expect(getStream(stdout)).resolves.toEqual('Hello World!');134 await expect(getStream(stderr)).resolves.toEqual('Jest Workers!');135});136it('sends the task to the thread', () => {137 const worker = new Worker({138 forkOptions: {},139 maxRetries: 3,140 workerPath: '/tmp/foo',141 });142 const request = [CHILD_MESSAGE_CALL, false, 'foo', []];143 worker.send(144 request,145 () => {},146 () => {},147 );148 // Skipping call "0" because it corresponds to the "initialize" one.149 expect(worker._worker.postMessage.mock.calls[1][0]).toEqual(request);150});151it('resends the task to the thread after a retry', () => {152 const worker = new Worker({153 forkOptions: {},154 maxRetries: 3,155 workerPath: '/tmp/foo/bar/baz.js',156 });157 const request = [CHILD_MESSAGE_CALL, false, 'foo', []];158 worker.send(159 request,160 () => {},161 () => {},162 );163 // Skipping call "0" because it corresponds to the "initialize" one.164 expect(worker._worker.postMessage.mock.calls[1][0]).toEqual(request);165 const previousWorker = worker._worker;166 worker._worker.emit('exit');167 expect(worker._worker).not.toBe(previousWorker);168 // Skipping call "0" because it corresponds to the "initialize" one.169 expect(worker._worker.postMessage.mock.calls[1][0]).toEqual(request);170});171it('calls the onProcessStart method synchronously if the queue is empty', () => {172 const worker = new Worker({173 forkOptions: {},174 maxRetries: 3,175 workerPath: '/tmp/foo',176 });177 const onProcessStart = jest.fn();178 const onProcessEnd = jest.fn();179 worker.send(180 [CHILD_MESSAGE_CALL, false, 'foo', []],181 onProcessStart,182 onProcessEnd,183 );184 // Only onProcessStart has been called185 expect(onProcessStart).toHaveBeenCalledTimes(1);186 expect(onProcessEnd).not.toHaveBeenCalled();187 // then first call replies...188 worker._worker.emit('message', [PARENT_MESSAGE_OK]);189 expect(onProcessEnd).toHaveBeenCalledTimes(1);190});191it('can send multiple messages to parent', () => {192 const worker = new Worker({193 forkOptions: {},194 maxRetries: 3,195 workerPath: '/tmp/foo',196 });197 const onProcessStart = jest.fn();198 const onProcessEnd = jest.fn();199 const onCustomMessage = jest.fn();200 worker.send(201 [CHILD_MESSAGE_CALL, false, 'foo', []],202 onProcessStart,203 onProcessEnd,204 onCustomMessage,205 );206 // Only onProcessStart has been called207 expect(onProcessStart).toHaveBeenCalledTimes(1);208 expect(onProcessEnd).not.toHaveBeenCalled();209 expect(onCustomMessage).not.toHaveBeenCalled();210 // then first call replies...211 worker._worker.emit('message', [212 PARENT_MESSAGE_CUSTOM,213 {message: 'foo bar', otherKey: 1},214 ]);215 expect(onProcessEnd).not.toHaveBeenCalled();216 expect(onCustomMessage).toHaveBeenCalledTimes(1);217 expect(onCustomMessage).toHaveBeenCalledWith({218 message: 'foo bar',219 otherKey: 1,220 });221});222it('creates error instances for known errors', () => {223 const worker = new Worker({224 forkOptions: {},225 maxRetries: 3,226 workerPath: '/tmp/foo',227 });228 const callback1 = jest.fn();229 const callback2 = jest.fn();230 const callback3 = jest.fn();231 // Testing a generic ECMAScript error.232 worker.send([CHILD_MESSAGE_CALL, false, 'method', []], () => {}, callback1);233 worker._worker.emit('message', [234 PARENT_MESSAGE_CLIENT_ERROR,235 'TypeError',236 'bar',237 'TypeError: bar',238 {},239 ]);240 expect(callback1.mock.calls[0][0]).toBeInstanceOf(TypeError);241 expect(callback1.mock.calls[0][0].message).toBe('bar');242 expect(callback1.mock.calls[0][0].type).toBe('TypeError');243 expect(callback1.mock.calls[0][0].stack).toBe('TypeError: bar');244 // Testing a custom error.245 worker.send([CHILD_MESSAGE_CALL, false, 'method', []], () => {}, callback2);246 worker._worker.emit('message', [247 PARENT_MESSAGE_CLIENT_ERROR,248 'RandomCustomError',249 'bar',250 'RandomCustomError: bar',251 {qux: 'extra property'},252 ]);253 expect(callback2.mock.calls[0][0]).toBeInstanceOf(Error);254 expect(callback2.mock.calls[0][0].message).toBe('bar');255 expect(callback2.mock.calls[0][0].type).toBe('RandomCustomError');256 expect(callback2.mock.calls[0][0].stack).toBe('RandomCustomError: bar');257 expect(callback2.mock.calls[0][0].qux).toBe('extra property');258 // Testing a non-object throw.259 worker.send([CHILD_MESSAGE_CALL, false, 'method', []], () => {}, callback3);260 worker._worker.emit('message', [261 PARENT_MESSAGE_CLIENT_ERROR,262 'Number',263 null,264 null,265 412,266 ]);267 expect(callback3.mock.calls[0][0]).toBe(412);268});269it('throws when the thread returns a strange message', () => {270 const worker = new Worker({271 forkOptions: {},272 maxRetries: 3,273 workerPath: '/tmp/foo',274 });275 worker.send(276 [CHILD_MESSAGE_CALL, false, 'method', []],277 () => {},278 () => {},279 );280 // Type 27 does not exist.281 expect(() => {282 worker._worker.emit('message', [27]);283 }).toThrow(TypeError);284});285it('does not restart the thread if it cleanly exited', () => {286 const worker = new Worker({287 forkOptions: {},288 maxRetries: 3,289 workerPath: '/tmp/foo',290 });291 expect(workerThreads).toHaveBeenCalledTimes(1);292 worker._worker.emit('exit', 0);293 expect(workerThreads).toHaveBeenCalledTimes(1);294});295it('resolves waitForExit() after the thread cleanly exited', async () => {296 const worker = new Worker({297 forkOptions: {},298 maxRetries: 3,299 workerPath: '/tmp/foo',300 });301 expect(workerThreads).toHaveBeenCalledTimes(1);302 worker._worker.emit('exit', 0);303 await worker.waitForExit(); // should not timeout304});305it('restarts the thread when the thread dies', () => {306 const worker = new Worker({307 workerPath: '/tmp/foo',308 });309 expect(workerThreads).toHaveBeenCalledTimes(1);310 worker._worker.emit('exit', 1);311 expect(workerThreads).toHaveBeenCalledTimes(2);312});313it('terminates the thread when forceExit() is called', () => {314 const worker = new Worker({315 forkOptions: {},316 maxRetries: 3,317 workerPath: '/tmp/foo',318 });319 worker.forceExit();320 expect(worker._worker.terminate).toHaveBeenCalled();...
release.js
Source:release.js
1// Hack for sameNameRequire bug.2var onProcessEnd;3onProcessEnd && fis.removeListener('process:end', onProcessEnd);4fis.on('process:end', (onProcessEnd = function(file) {5 if (file.isJsLike) {6 file.addSameNameRequire('.css');7 } else if (file.isHtmlLike) {8 // file.addSameNameRequire('.js');9 file.addSameNameRequire('.css');10 }...
Using AI Code Generation
1const { onProcessEnd } = require('storybook-test-runner');2onProcessEnd((code) => {3});4const { onProcessEnd } = require('storybook-test-runner');5onProcessEnd((code) => {6});7const { onProcessEnd } = require('storybook-test-runner');8onProcessEnd((code) => {9});10const { onProcessEnd } = require('storybook-test-runner');11onProcessEnd((code) => {12});13const { onProcessEnd } = require('storybook-test-runner');14onProcessEnd((code) => {15});16const { onProcessEnd } = require('storybook-test-runner');17onProcessEnd((code) => {18});19const { onProcessEnd } = require('storybook-test-runner');20onProcessEnd((code) => {21});22const { onProcessEnd } = require('storybook-test-runner');23onProcessEnd((code) => {24});25const { onProcessEnd } = require('storybook-test-runner');26onProcessEnd((code) => {27});28const { onProcessEnd } = require('storybook-test-runner');29onProcessEnd((code) => {30});31const { onProcessEnd } = require('
Using AI Code Generation
1const { onProcessEnd } = require('storybook-test-runner');2const testRunner = async () => {3 await onProcessEnd();4};5module.exports = testRunner;6"scripts": {7 }
Using AI Code Generation
1const { onProcessEnd } = require('storybook-test-runner');2onProcessEnd((exitCode) => {3 console.log('Exit code: ' + exitCode);4});5"scripts": {6 },7const { onProcessEnd } = require('storybook-test-runner');8onProcessEnd((exitCode) => {9 if (exitCode == 0) {10 }11});12"scripts": {13 },
Using AI Code Generation
1const { onProcessEnd } = require('storybook-test-runner');2onProcessEnd((exitCode) => {3 console.log('onProcessEnd callback');4});5const { onProcessEnd } = require('storybook-test-runner');6onProcessEnd((exitCode) => {7 console.log('onProcessEnd callback');8});9const { onProcessEnd } = require('storybook-test-runner');10onProcessEnd((exitCode) => {11 console.log('onProcessEnd callback');12});13const { onProcessEnd } = require('storybook-test-runner');14onProcessEnd((exitCode) => {15 console.log('onProcessEnd callback');16});17const { onProcessEnd } = require('storybook-test-runner');18onProcessEnd((exitCode) => {19 console.log('onProcessEnd callback');20});21const { onProcessEnd } = require('storybook-test-runner');22onProcessEnd((exitCode) => {23 console.log('onProcessEnd callback');24});25const { onProcessEnd } = require('storybook-test-runner');26onProcessEnd((exitCode) => {27 console.log('onProcessEnd callback');28});29const { onProcessEnd } = require('storybook-test-runner');30onProcessEnd((exitCode) => {31 console.log('onProcessEnd callback');32});33const { onProcessEnd } = require('storybook-test-runner');34onProcessEnd((exitCode) => {35 console.log('onProcessEnd callback');36});
Using AI Code Generation
1import { onProcessEnd } from 'storybook-test-runner';2onProcessEnd((exitCode) => {3});4"scripts": {5}6import { onProcessEnd } from 'storybook-test-runner';7onProcessEnd((exitCode) => {8});9"scripts": {10}11import { onProcessEnd } from 'storybook-test-runner';12onProcessEnd((exitCode) => {13});14"scripts": {15}16import { onProcessEnd } from 'storybook-test-runner';17onProcessEnd((exitCode) => {18});19"scripts": {20}21import { onProcessEnd } from 'storybook-test-runner';22onProcessEnd((exitCode) => {23});24"scripts": {25}
Using AI Code Generation
1import { onProcessEnd } from 'storybook-test-runner';2import { getStorybook } from '@storybook/react';3import { render } from 'react-dom';4import { storiesOf } from '@storybook/react';5import { action } from '@storybook/addon-actions';6import { linkTo } from '@storybook/addon-links';7import { Button, Welcome } from '@storybook/react/demo';8storiesOf('Button', module)9 .add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)10 .add('with some emoji', () => (11 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>12 ));13onProcessEnd(() => {14 const storybook = getStorybook();15 console.log(storybook);16});17import { onProcessEnd } from 'storybook-test-runner';18import { getStorybook } from '@storybook/react';19import { render } from 'react-dom';20import { storiesOf } from '@storybook/react';21import { action } from '@storybook/addon-actions';22import { linkTo } from '@storybook/addon-links';23import { Button, Welcome } from '@storybook/react/demo';24storiesOf('Button', module)25 .add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)26 .add('with some emoji', () => (27 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>28 ));29onProcessEnd(() => {30 const storybook = getStorybook();31 console.log(storybook);32});33import { onProcessEnd } from 'storybook-test-runner';34import { getStorybook } from '@storybook/react';35import { render } from 'react-dom';36import { storiesOf } from '@storybook/react';37import { action } from '@storybook/addon-actions';38import { linkTo } from '@storybook/addon-links';39import { Button, Welcome } from '@storybook/react/demo';40storiesOf('Button', module)41 .add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)42 .add('with some emoji', () => (
Using AI Code Generation
1const onProcessEnd = () => {2 console.log('storybook-test-runner process ended');3 process.exit(0);4};5module.exports = {6};7"scripts": {8}9module.exports = {10};11import 'storybook-test-runner/register';12import 'storybook-test-runner/register';13import 'storybook-test-runner/register';
Using AI Code Generation
1const { onProcessEnd } = require('storybook-test-runner');2const { exec } = require('child_process');3const run = async () => {4 await onProcessEnd(async (err, code) => {5 console.log('storybook was closed');6 exec('npm run test:log', (err, stdout, stderr) => {7 if (err) {8 console.error(err);9 return;10 }11 console.log(stdout);12 });13 });14};15run();16"scripts": {17 }
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!