This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add run-package-specs atom-script and shell script
Summary: This adds an `atom-script` script that opens a spec file in the spec window without having to load all of Nuclide. Also added a shortcut script as `scripts/run-package-specs.sh`. To use it, just run `scripts/run-package-specs.sh` with a path to a spec file, then it'll open up the spec window with that test loaded. Example: ``` ./scripts/run-package-specs.sh spec/quick-open-provider-cycle-integration-spec.js ./scripts/run-package-specs.sh pkg/nuclide-quick-open/spec/SearchResultManager-spec.js ``` Reviewed By: AsyncDBConnMarkedDownDBException Differential Revision: D4444976 fbshipit-source-id: fab986eb9b6df5751b4844ef8a14f134572f68ae
- Loading branch information
1 parent
8e61b9e
commit c31fb27
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the LICENSE file in | ||
* the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
/* eslint-disable no-console */ | ||
|
||
import type {ExitCode} from '../lib/types'; | ||
|
||
import invariant from 'assert'; | ||
import electron from 'electron'; | ||
// eslint-disable-next-line nuclide-internal/prefer-nuclide-uri | ||
import path from 'path'; | ||
|
||
const {ipcRenderer, remote} = electron; | ||
invariant(ipcRenderer != null && remote != null); | ||
|
||
export default async function runCommand(args: Array<string>): Promise<ExitCode> { | ||
if (typeof args[0] !== 'string') { | ||
console.error(`Usage: atom-script ${__filename} <spec file>`); | ||
return 1; | ||
} | ||
|
||
const initialWindows = remote.BrowserWindow.getAllWindows(); | ||
|
||
const packageSpecPath = path.resolve(args[0]); | ||
ipcRenderer.send('run-package-specs', packageSpecPath); | ||
|
||
// Wait for the window to load | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
|
||
const testWindow = remote.BrowserWindow.getAllWindows().find(browserWindow => { | ||
return !initialWindows.includes(browserWindow) && | ||
// $FlowFixMe: Missing def | ||
browserWindow.getURL().includes('initialize-test-window.js'); | ||
}); | ||
|
||
if (testWindow == null) { | ||
console.error('Could not find spec browser window.'); | ||
return 1; | ||
} | ||
|
||
// If we don't wait for the spec window to close before finishing, we cause | ||
// the window to close. | ||
await new Promise(resolve => { | ||
testWindow.once('close', () => { | ||
resolve(); | ||
}); | ||
}); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (c) 2015-present, Facebook, Inc. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the license found in the LICENSE file in | ||
# the root directory of this source tree. | ||
|
||
# This script opens a spec file in the spec window without loading all of Nuclide. | ||
# Example: | ||
# ./scripts/run-package-specs.sh spec/quick-open-provider-cycle-integration-spec.js | ||
# ./scripts/run-package-specs.sh pkg/nuclide-quick-open/spec/SearchResultManager-spec.js | ||
|
||
THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
||
ATOM_SCRIPT_PATH="$THIS_DIR/../pkg/nuclide-atom-script/bin/atom-script" | ||
RUN_PACKAGE_SPECS_JS="$THIS_DIR/../pkg/nuclide-atom-script/samples/run-package-specs.js" | ||
|
||
"$ATOM_SCRIPT_PATH" "$RUN_PACKAGE_SPECS_JS" "$@" |