Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Add run-package-specs atom-script and shell script
Browse files Browse the repository at this point in the history
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
zertosh authored and facebook-github-bot committed Jan 21, 2017
1 parent 8e61b9e commit c31fb27
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
57 changes: 57 additions & 0 deletions pkg/nuclide-atom-script/samples/run-package-specs.js
@@ -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;
}
19 changes: 19 additions & 0 deletions scripts/run-package-specs.sh
@@ -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" "$@"

0 comments on commit c31fb27

Please sign in to comment.