diff --git a/packager/__tests__/launchPackagerCLIMock.js.mock b/packager/__tests__/launchPackagerCLIMock.js.mock new file mode 100644 index 00000000000000..547431726ba44c --- /dev/null +++ b/packager/__tests__/launchPackagerCLIMock.js.mock @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +'use strict'; + +// Remove the first two elements, we only want the arguments +process.argv.splice(0, 2); + +// Print out the arguments to be used in the test +console.log(process.argv.join(';;')); diff --git a/packager/__tests__/launchPackagerMock.bat b/packager/__tests__/launchPackagerMock.bat new file mode 100644 index 00000000000000..9349b5a75ef94e --- /dev/null +++ b/packager/__tests__/launchPackagerMock.bat @@ -0,0 +1,12 @@ +:: Copyright (c) 2015-present, Facebook, Inc. +:: All rights reserved. +:: +:: This source code is licensed under the BSD-style license found in the +:: LICENSE file in the root directory of this source tree. An additional grant +:: of patent rights can be found in the PATENTS file in the same directory. + +@echo off +title React Packager +node "$THIS_DIR/launchPackagerCLIMock.js.mock" start %* +pause +exit diff --git a/packager/__tests__/launchPackagerMock.sh b/packager/__tests__/launchPackagerMock.sh new file mode 100755 index 00000000000000..3a19b64f43f91a --- /dev/null +++ b/packager/__tests__/launchPackagerMock.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# Copyright (c) 2015-present, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +THIS_DIR=$(dirname "$0") +node "$THIS_DIR/launchPackagerCLIMock.js.mock" start "$@" diff --git a/packager/__tests__/packagerLauncher.spec.js b/packager/__tests__/packagerLauncher.spec.js new file mode 100644 index 00000000000000..46503410951a49 --- /dev/null +++ b/packager/__tests__/packagerLauncher.spec.js @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +'use strict'; + +jest.autoMockOff(); + +const onWindows = /^win/.test(process.platform); +const { spawnSync } = require('child_process'); + +describe('packager launcher', () => { + it('should be able to pass all arguments to the command-line script', () => { + // Determine the appropriate script to test based on the host OS + const cmd = `./packager/__tests__/launchPackagerMock.${onWindows ? 'bat' : 'sh'}`; + + // Let's try to pass some args + const args = ['--arg1', '--arg2']; + const proc = spawnSync(cmd, args); + + // We should've gotten the args from the mock script + const outArgs = proc.stdout.toString().trim().split(";;"); + + // We account for an extra arg in the mock scripts + expect(outArgs[1]).toEqual(args[0]); + expect(outArgs[2]).toEqual(args[1]); + }); +}); diff --git a/packager/launchPackager.bat b/packager/launchPackager.bat index b0c395b985fd03..826105912411df 100644 --- a/packager/launchPackager.bat +++ b/packager/launchPackager.bat @@ -7,6 +7,6 @@ @echo off title React Packager -node "%~dp0..\local-cli\cli.js" start +node "%~dp0..\local-cli\cli.js" start %* pause exit