forked from g3offrey/javascript-test-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🏗️ refactor architecture of extension
- Loading branch information
Geoffrey
authored
Jul 20, 2018
1 parent
240c473
commit f68f468
Showing
23 changed files
with
1,608 additions
and
274 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
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 |
---|---|---|
@@ -1,72 +1,91 @@ | ||
{ | ||
"name": "javascript-test-runner", | ||
"displayName": "JavaScript Test Runner", | ||
"description": "Run JavaScript tests easily using CodeLens", | ||
"version": "0.2.0", | ||
"publisher": "legfrey", | ||
"engines": { | ||
"vscode": "^1.18.0" | ||
}, | ||
"license": "MIT", | ||
"categories": [ | ||
"Other" | ||
"name": "javascript-test-runner", | ||
"displayName": "JavaScript Test Runner", | ||
"description": "Run JavaScript tests easily using CodeLens", | ||
"version": "0.2.0", | ||
"publisher": "legfrey", | ||
"engines": { | ||
"vscode": "^1.18.0" | ||
}, | ||
"license": "MIT", | ||
"categories": [ | ||
"Other" | ||
], | ||
"keywords": [ | ||
"mocha", | ||
"jest", | ||
"test", | ||
"unit" | ||
], | ||
"preview": true, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/g3offrey/javascript-test-runner" | ||
}, | ||
"icon": "ressources/icon.png", | ||
"main": "./out/extension", | ||
"activationEvents": [ | ||
"*" | ||
], | ||
"contributes": { | ||
"commands": [ | ||
{ | ||
"command": "javascript-test-runner.run.test", | ||
"title": "Run Test" | ||
} | ||
], | ||
"keywords": [ | ||
"mocha", | ||
"jest", | ||
"test", | ||
"unit" | ||
"configuration": [ | ||
{ | ||
"properties": { | ||
"javascript-test-runner.additionalArgs": { | ||
"type": "string", | ||
"default": "", | ||
"description": "CLI args to pass to test runner. Example : --watch" | ||
}, | ||
"javascript-test-runner.envVars": { | ||
"type": "object", | ||
"default": { | ||
"NODE_ENV": "test" | ||
}, | ||
"description": "Environment variables to set before running a test." | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "npm run compile", | ||
"compile": "tsc -p ./", | ||
"watch": "tsc -watch -p ./", | ||
"postinstall": "node ./node_modules/vscode/bin/install", | ||
"test": "npm run compile && node ./node_modules/vscode/bin/test", | ||
"lint": "tslint -c tslint.json src/**/*.ts", | ||
"format": "prettier --write src/**/*.{ts,json} package.json", | ||
"precommit": "lint-staged" | ||
}, | ||
"lint-staged": { | ||
"*.{json}": [ | ||
"prettier --write", | ||
"git add" | ||
], | ||
"preview": true, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/g3offrey/javascript-test-runner" | ||
}, | ||
"icon": "ressources/icon.png", | ||
"main": "./out/extension", | ||
"activationEvents": [ | ||
"*" | ||
], | ||
"contributes": { | ||
"commands": [ | ||
{ | ||
"command": "javascript-test-runner.run.test", | ||
"title": "Run Test" | ||
} | ||
], | ||
"configuration": [ | ||
{ | ||
"properties": { | ||
"javascript-test-runner.additionalArgs": { | ||
"type": "string", | ||
"default": "", | ||
"description": "CLI args to pass to test runner. Example : --watch" | ||
}, | ||
"javascript-test-runner.envVars": { | ||
"type": "object", | ||
"default": { | ||
"NODE_ENV": "test" | ||
}, | ||
"description": "Environment variables to set before running a test." | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "npm run compile", | ||
"compile": "tsc -p ./", | ||
"watch": "tsc -watch -p ./", | ||
"postinstall": "node ./node_modules/vscode/bin/install", | ||
"test": "npm run compile && node ./node_modules/vscode/bin/test" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^2.2.42", | ||
"@types/node": "^7.0.43", | ||
"typescript": "^2.6.1", | ||
"vscode": "^1.1.6" | ||
}, | ||
"dependencies": { | ||
"acorn": "^5.3.0" | ||
} | ||
} | ||
"*.{ts}": [ | ||
"tslint -c tslint.json", | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^2.2.42", | ||
"@types/node": "^7.0.43", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^7.2.0", | ||
"prettier": "1.13.7", | ||
"tslint": "^5.10.0", | ||
"tslint-config-prettier": "^1.13.0", | ||
"typescript": "^2.6.1", | ||
"vscode": "^1.1.6" | ||
}, | ||
"dependencies": { | ||
"acorn": "^5.3.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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import { CodeLens, Range, Command } from 'vscode' | ||
import { CodeLens, Range } from "vscode"; | ||
|
||
export default class TestDebugRunnerCodeLens extends CodeLens { | ||
constructor(range: Range, testName: string, rootPath: string, fileName: string) { | ||
super(range, { | ||
title: 'Debug Test', | ||
command: 'javascript-test-runner.debug.test', | ||
arguments: [testName, rootPath, fileName, true] | ||
}) | ||
} | ||
constructor( | ||
rootPath: string, | ||
fileName: string, | ||
testName: string, | ||
range: Range | ||
) { | ||
super(range, { | ||
arguments: [rootPath, fileName, testName], | ||
command: "javascript-test-runner.debug.test", | ||
title: "Debug Test" | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import { CodeLens, Range, Command } from 'vscode' | ||
import { CodeLens, Range } from "vscode"; | ||
|
||
export default class TestRunnerCodeLens extends CodeLens { | ||
constructor(range: Range, testName: string, rootPath: string, fileName: string) { | ||
super(range, { | ||
title: 'Run Test', | ||
command: 'javascript-test-runner.run.test', | ||
arguments: [testName, rootPath, fileName] | ||
}) | ||
} | ||
constructor( | ||
rootPath: string, | ||
fileName: string, | ||
testName: string, | ||
range: Range | ||
) { | ||
super(range, { | ||
arguments: [rootPath, fileName, testName], | ||
command: "javascript-test-runner.run.test", | ||
title: "Run Test" | ||
}); | ||
} | ||
} |
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,9 @@ | ||
import { getTestRunner } from "../runners/TestRunnerFactory"; | ||
|
||
async function debugTest(rootPath, fileName, testName) { | ||
const testRunner = await getTestRunner(rootPath); | ||
|
||
testRunner.debugTest(testName, fileName); | ||
} | ||
|
||
export default debugTest; |
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 |
---|---|---|
@@ -1,59 +1,9 @@ | ||
import { window, workspace, Terminal, TerminalOptions, debug } from 'vscode' | ||
import { getTestRunner } from "../runners/TestRunnerFactory"; | ||
|
||
import { getTestRunner } from '../utils/runner' | ||
import { TestRunner } from '../types/TestRunner' | ||
async function runTest(rootPath, fileName, testName) { | ||
const testRunner = await getTestRunner(rootPath); | ||
|
||
let term: Terminal = null | ||
|
||
function _getNewTerminal(envVars: {}): Terminal { | ||
const terminalOptions: TerminalOptions = { | ||
env: envVars | ||
} | ||
|
||
if (term) { | ||
term.dispose() | ||
} | ||
|
||
term = window.createTerminal(terminalOptions) | ||
|
||
return term | ||
testRunner.runTest(testName, fileName); | ||
} | ||
|
||
async function runTest (testName, rootPath, fileName, isDebug = false) { | ||
const testRunner = await getTestRunner(rootPath) | ||
const additionalArgs: string = workspace.getConfiguration("javascript-test-runner").get("additionalArgs") | ||
const envVars = workspace.getConfiguration("javascript-test-runner").get("envVars") | ||
const term = _getNewTerminal(envVars) | ||
|
||
if (isDebug) { | ||
debug.startDebugging(rootPath, { | ||
name: 'Debug Test', | ||
type: "node", | ||
request: "launch", | ||
program: testRunner === TestRunner.jest | ||
? "${workspaceFolder}/node_modules/.bin/jest" | ||
: "${workspaceFolder}/node_modules/.bin/mocha", | ||
args: [ | ||
fileName, | ||
testRunner === TestRunner.jest ? "--testNamePattern" : "--grep", | ||
testName, | ||
testRunner === TestRunner.jest ? "--runInBand" : "--no-timeouts", | ||
...additionalArgs.split(' ') | ||
], | ||
internalConsoleOptions: "openOnSessionStart", | ||
env: envVars, | ||
}) | ||
} else { | ||
const commandLine = testRunner === TestRunner.jest | ||
? `${rootPath}/node_modules/.bin/jest ${fileName} --testNamePattern="${testName}" ${additionalArgs}` | ||
: `${rootPath}/node_modules/.bin/mocha ${fileName} --grep="${testName}" ${additionalArgs}` | ||
|
||
|
||
term.sendText(commandLine, true) | ||
term.show(true) | ||
} | ||
|
||
} | ||
|
||
|
||
export default runTest | ||
export default runTest; |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
export default [ | ||
{ | ||
language: "typescript", | ||
scheme: "file" | ||
}, | ||
{ | ||
language: "javascript", | ||
scheme: "file" | ||
} | ||
] | ||
{ | ||
language: "typescript", | ||
scheme: "file" | ||
}, | ||
{ | ||
language: "javascript", | ||
scheme: "file" | ||
} | ||
]; |
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 |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import { ExtensionContext, window, languages, commands } from 'vscode' | ||
import { ExtensionContext, window, languages, commands } from "vscode"; | ||
|
||
import FILE_SELECTOR from './constants/fileSelector' | ||
import TestRunnerCodeLensProvider from './providers/TestRunnerCodeLensProvider' | ||
import runTestCommand from './commands/runTestCommand' | ||
import FILE_SELECTOR from "./constants/fileSelector"; | ||
import TestRunnerCodeLensProvider from "./providers/TestRunnerCodeLensProvider"; | ||
import runTestCommand from "./commands/runTestCommand"; | ||
import debugTestCommand from "./commands/debugTestCommand"; | ||
|
||
export function activate(context: ExtensionContext) { | ||
context.subscriptions.push( | ||
languages.registerCodeLensProvider(FILE_SELECTOR, new TestRunnerCodeLensProvider()) | ||
context.subscriptions.push( | ||
languages.registerCodeLensProvider( | ||
FILE_SELECTOR, | ||
new TestRunnerCodeLensProvider() | ||
) | ||
); | ||
|
||
commands.registerCommand('javascript-test-runner.run.test', runTestCommand) | ||
commands.registerCommand('javascript-test-runner.debug.test', runTestCommand) | ||
commands.registerCommand("javascript-test-runner.run.test", runTestCommand); | ||
commands.registerCommand( | ||
"javascript-test-runner.debug.test", | ||
debugTestCommand | ||
); | ||
} | ||
|
||
// this method is called when your extension is deactivated | ||
export function deactivate() { | ||
} | ||
export function deactivate() {} |
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,14 @@ | ||
import { WorkspaceFolder } from "vscode"; | ||
import { ConfigurationProvider } from "../providers/ConfigurationProvider"; | ||
import { TerminalProvider } from "../providers/TerminalProvider"; | ||
|
||
export interface ITestRunnerInterface { | ||
name: string; | ||
binPath: string; | ||
rootPath: WorkspaceFolder; | ||
terminalProvider: TerminalProvider; | ||
configurationProvider: ConfigurationProvider; | ||
|
||
runTest(testName: string, fileName: string): void; | ||
debugTest(testName: string, fileName: string): void; | ||
} |
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,9 @@ | ||
import { WorkspaceFolder } from "vscode"; | ||
import { ConfigurationProvider } from "../providers/ConfigurationProvider"; | ||
import { TerminalProvider } from "../providers/TerminalProvider"; | ||
|
||
export interface ITestRunnerOptions { | ||
rootPath: WorkspaceFolder; | ||
terminalProvider: TerminalProvider; | ||
configurationProvider: ConfigurationProvider; | ||
} |
Oops, something went wrong.