Skip to content

Commit

Permalink
Merge pull request #1 from prashaantt/wip
Browse files Browse the repository at this point in the history
Wip
  • Loading branch information
prashaantt authored Jan 15, 2017
2 parents a7101c7 + e347e99 commit d896874
Show file tree
Hide file tree
Showing 17 changed files with 556 additions and 92 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Change Log
All notable changes to the "node-tdd" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
- Initial release
## 0.1.0
- Initial release
83 changes: 35 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,52 @@
# node-tdd README
# node-tdd

This is the README for your extension "node-tdd". After writing up a brief description, we recommend including the following sections.
> A [Visual Studio Code](http://code.visualstudio.com/) extension to ease [test-driven development](https://en.wikipedia.org/wiki/Test-driven_development) in Node/JavaScript
## Features

Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
![feature X](images/node-tdd.gif)

For example if there is an image subfolder under your extension project workspace:
- Activates when a workspace containing `package.json` is opened.
- Triggers an automatic test build whenever source files are updated.
- Shows a colour-coded build summary.
- Shows the average test coverage (experimental).

\!\[feature X\]\(images/feature-x.png\)

> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
## Requirements

If you have any requirements or dependencies, add a section describing those and how to install and configure them.

## Extension Settings

Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.

For example:
## Settings

This extension contributes the following settings:

* `myExtension.enable`: enable/disable this extension
* `myExtension.thing`: set to `blah` to do something

## Known Issues

Calling out known issues can help limit users opening duplicate issues against your extension.

## Release Notes

Users appreciate release notes as you update your extension.

### 1.0.0

Initial release of ...

### 1.0.1

Fixed issue #.

### 1.1.0
| Setting | Type | Default | Description |
| --------------------------- | -------------- | --------------------------------- | --------------------------------------------------------------- |
| `nodeTdd.activateOnStartup` | boolean | `true` | Activate TDD mode when workspace is opened |
| `nodeTdd.testScript` | string | `test` | The npm script to run tests |
| `nodeTdd.glob` | string | `{test,src}/**/*.{js,ts,jsx,tsx}` | Glob pattern for files to watch, relative to the workspace root |
| `nodeTdd.runOnActivation` | boolean | `false` | Run tests as soon as TDD mode gets (re-)activated |
| `nodeTdd.verbose` | boolean | `false` | Show (more intrusive) build status dialogs |
| `nodeTdd.buildOnCreate` | boolean | `false` | Run tests when matching files are created |
| `nodeTdd.buildOnDelete` | boolean | `false` | Run tests when matching files are deleted |
| `nodeTdd.showCoverage` | boolean | `false` | Show the average test coverage if reported (experimental) |
| `nodeTdd.coverageThreshold` | number \| null | `null` | The threshold percentage, used to colour-code the coverage |

Added features X, Y, and Z.
## Commands

-----------------------------------------------------------------------------------------------------------
The following commands are available from the commands menu as well as convenience status bar buttons:

## Working with Markdown
| Command | Action |
| -------------- | ------------------------------------- |
| `activate` | Activate `node-tdd` in a workspace |
| `deactivate` | De-activate `node-tdd` in a workspace |
| `toggleOutput` | Toggle detailed test results output |
| `stopBuild` | Stop a running build |

**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
## Limitations and known issues

* Split the editor (`Cmd+\` on OSX or `Ctrl+\` on Windows and Linux)
* Toggle preview (`Shift+CMD+V` on OSX or `Shift+Ctrl+V` on Windows and Linux)
* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (OSX) to see a list of Markdown snippets
- The extension doesn't get activated if `package.json` was not initially present when the workspace was opened; a window restart will be required to detect a change.
- It doesn't work with watch mode/incremental test builds. The build process used for running tests must exit on each execution, otherwise it will never report the status.
- `showCoverage` is an experimental setting, only tested with [Lab](https://github.com/hapijs/lab) and [Istanbul](https://github.com/gotwarlost/istanbul). Disable it if its output looks funny.
- Ironically for a TDD extension, it has very few tests of its own because I don't yet know how to test UI elements in VS Code. :/

### For more information
Suggestions and PRs are welcome.

* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
## License

**Enjoy!**
MIT License.
Binary file added images/emojione-rocket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/node-tdd.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
{
"name": "node-tdd",
"version": "0.1.0",
"displayName": "Node TDD",
"description": "A simple TDD extension for Node.",
"version": "0.1.0",
"description": "A Visual Studio Code extension to ease test-driven development in Node/JavaScript",
"main": "./out/src/extension",
"repository": "https://github.com/prashaantt/node-tdd.git",
"repository": {
"type": "git",
"url": "https://github.com/prashaantt/node-tdd.git"
},
"bugs": {
"url": "https://github.com/prashaantt/node-tdd/issues"
},
"author": "Prashant Tiwari <[email protected]>",
"publisher": "prashaantt",
"license": "MIT",
"engines": {
"vscode": "^1.8.0"
},
"icon": "images/emojione-rocket.png",
"galleryBanner": {
"color": "#607d8b"
},
"categories": [
"Other"
],
Expand All @@ -22,12 +32,14 @@
"@types/mocha": "^2.2.37",
"@types/node": "^7.0.0",
"mocha": "^3.2.0",
"tslint": "^4.3.1",
"typescript": "^2.1.5",
"vscode": "^1.0.3"
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"lint": "tslint -c tslint.json './{src,test}/**/*.ts'",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
},
Expand Down Expand Up @@ -72,7 +84,7 @@
"default": false
},
"nodeTdd.testScript": {
"description": "The npm script to run (if other than `test`)",
"description": "The npm script to run tests",
"type": "string",
"default": "test"
},
Expand All @@ -92,12 +104,12 @@
"default": false
},
"nodeTdd.showCoverage": {
"description": "Show the test coverage if available (experimental)",
"description": "Show the test coverage if reported (experimental)",
"type": "boolean",
"default": false
},
"nodeTdd.coverageThreshold": {
"description": "The coverage threshold (if applicable)",
"description": "The coverage threshold",
"type": [
"number",
"null"
Expand Down
8 changes: 4 additions & 4 deletions src/NodeTDD.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StatusBarItem, window, workspace, OutputChannel, StatusBarAlignment, Disposable } from 'vscode';
import { StatusBarItem, window, workspace, OutputChannel, StatusBarAlignment } from 'vscode';

import { TestRunner } from './TestRunner';
import { messages, config } from './constants';
Expand All @@ -10,7 +10,7 @@ interface Config<T> {
defaultValue: T;
}

export class NodeTDD implements Disposable {
export class NodeTDD {
private enabled = false;
private outputShown = false;
private extensionStatusBar: StatusBarItem;
Expand Down Expand Up @@ -119,11 +119,11 @@ export class NodeTDD implements Disposable {

if (code === 0) {
clicked = await window.showInformationMessage(
messages.PASSING_DIALOG, messages.SHOW_OUTPUT_DIALOG).then();
messages.PASSING_DIALOG, messages.SHOW_OUTPUT_DIALOG);
}
else if (code === 1) {
clicked = await window.showErrorMessage(
messages.FAILING_DIALOG, messages.SHOW_OUTPUT_DIALOG).then();
messages.FAILING_DIALOG, messages.SHOW_OUTPUT_DIALOG);
}
else if (code === null) {
window.showWarningMessage(messages.STOPPED_DIALOG);
Expand Down
19 changes: 16 additions & 3 deletions src/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,21 @@ export class TestRunner {
packageObj = JSON.parse(packageJSON);
}
catch (err) {
const selection = await window.showErrorMessage(
messages.PACKAGE_JSON_NOT_FOUND, messages.DEACTIVATE_DIALOG);

if (selection === messages.DEACTIVATE_DIALOG) {
NodeTDD.getInstance().deactivate();
}

return;
}

const scriptName = NodeTDD.getConfig<string>(config.TEST_SCRIPT).trim();

if (!packageObj.scripts[scriptName]) {
const selection = await window.showErrorMessage(
messages.scriptNotFound(scriptName), messages.OPEN_PACKAGE_JSON).then();
messages.scriptNotFound(scriptName), messages.OPEN_PACKAGE_JSON);

if (selection === messages.OPEN_PACKAGE_JSON) {
workspace.openTextDocument(workspace.rootPath + '/package.json')
Expand All @@ -102,9 +109,13 @@ export class TestRunner {

NodeTDD.getInstance().showBuildStatusBar();

this.execProcess(clearInterval.bind(null, this.animateBuilding()));
}

private animateBuilding() {
let count = 1;

const interval = setInterval(() => {
return setInterval(() => {

const dots = count++ % 4;
const spaces = 4 - dots;
Expand All @@ -113,7 +124,9 @@ export class TestRunner {
text: messages.BUILDING.text + '.'.repeat(dots) + ' '.repeat(spaces)
});
}, config.BUILDING_ANIMATION_SPEED);
}

private execProcess(callback: Function) {
this.process = exec(this.testCommand, { cwd: workspace.rootPath });

const showCoverage = NodeTDD.getConfig<boolean>(config.SHOW_COVERAGE);
Expand All @@ -136,7 +149,7 @@ export class TestRunner {

this.process.on('close', (code, signal) => {

clearInterval(interval);
callback();
this.process = null;

if (signal === 'SIGTERM') {
Expand Down
14 changes: 9 additions & 5 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const commands = {
DEACTIVATE: 'nodeTdd.deactivate',
TOGGLE_OUTPUT: 'nodeTdd.toggleOutput',
STOP_BUILD: 'nodeTdd.stopBuild',
}
};

export const config = {
CONFIG_SECTION_KEY: 'nodeTdd',
Expand All @@ -23,7 +23,7 @@ export const config = {
BUILD_ON_DELETE: { name: 'buildOnDelete', defaultValue: false },
SHOW_COVERAGE: { name: 'showCoverage', defaultValue: false },
COVERAGE_THRESHOLD: { name: 'coverageThreshold', defaultValue: null }
}
};

export const messages = {
ACTIVATE_EXTENSION: {
Expand Down Expand Up @@ -76,16 +76,20 @@ export const messages = {

OPEN_PACKAGE_JSON: 'Open package.json',

PACKAGE_JSON_NOT_FOUND: 'Node TDD: package.json was not found',

DEACTIVATE_DIALOG: 'Deactivate TDD mode',

coverage: function (coverage: number, threshold: number | null) {
return {
text: `$(dashboard) ${coverage}%`,
tooltip: 'Test coverage',
color: threshold ? (coverage >= threshold ?
config.PASSING_COLOUR : config.FAILING_COLOUR) : 'inherit'
}
};
},

scriptNotFound: function (scriptName: string) {
return `Node TDD: npm script \`${scriptName}\` was not found`;
return `Node TDD: The npm script \`${scriptName}\` was not found`;
}
}
};
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function activate(context: Code.ExtensionContext) {
nodeTdd.stopBuild();
});

context.subscriptions.push(activateCommand, deactivateCommand, toggleOutputCommand, nodeTdd);
context.subscriptions.push(activateCommand, deactivateCommand,
toggleOutputCommand, stopBuildCommand, nodeTdd);
}

export function deactivate() { }
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function readFileAsync(path: string) {

readFile(path, 'utf8', (err, data) => {
if (err) {
return reject(err);
return reject(err.message);
}

return resolve(data);
Expand Down
2 changes: 1 addition & 1 deletion test/NodeTDD.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from 'assert';
import { NodeTDD } from '../src/NodeTDD';
import { config } from '../src/constants';

suite("The extension manager NodeTDD", () => {
suite('The extension manager NodeTDD', () => {

test('correctly returns a singleton instance', () => {
assert.equal(NodeTDD.getInstance(), NodeTDD.getInstance());
Expand Down
8 changes: 4 additions & 4 deletions test/constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as assert from 'assert';

import { messages, config } from '../src/constants';

suite("Constants", () => {
suite('Constants', () => {

test("return correct coverage", () => {
test('return correct coverage', () => {

const message = messages.coverage(84, null);
assert.deepEqual(message, {
Expand All @@ -14,7 +14,7 @@ suite("Constants", () => {
});
});

test("return correct coverage with threshold", () => {
test('return correct coverage with threshold', () => {

const message = messages.coverage(84, 100);
assert.deepEqual(message, {
Expand All @@ -24,7 +24,7 @@ suite("Constants", () => {
});
});

test("correctly return scriptNotFound message", () => {
test('correctly return scriptNotFound message', () => {

const message = messages.scriptNotFound('test');
assert.equal(message, 'Node TDD: npm script `test` was not found');
Expand Down
4 changes: 2 additions & 2 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// to report the results back to the caller. When the tests are finished, return
// a possible error to the callback or null if none.

var testRunner = require('vscode/lib/testrunner');
const testRunner = require('vscode/lib/testrunner');

// You can directly control Mocha options by uncommenting the following lines
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
Expand All @@ -19,4 +19,4 @@ testRunner.configure({
useColors: true // colored output from test results
});

module.exports = testRunner;
module.exports = testRunner;
Loading

0 comments on commit d896874

Please sign in to comment.