Skip to content

Commit

Permalink
fixed facebook#13445 - the Windows package launcher script can now pa…
Browse files Browse the repository at this point in the history
…ss all arguments to the cli
  • Loading branch information
idancali committed Apr 11, 2017
1 parent abd148f commit 8b81495
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packager/__tests__/launchPackagerCLIMock.js.mock
Original file line number Diff line number Diff line change
@@ -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(';;'));
12 changes: 12 additions & 0 deletions packager/__tests__/launchPackagerMock.bat
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions packager/__tests__/launchPackagerMock.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
33 changes: 33 additions & 0 deletions packager/__tests__/packagerLauncher.spec.js
Original file line number Diff line number Diff line change
@@ -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]);
});
});
2 changes: 1 addition & 1 deletion packager/launchPackager.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8b81495

Please sign in to comment.