Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feature/refactor test runner#53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 6 commits intomasterfromfeature/refactor-test-runner
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 0 additions & 138 deletionssrc/actions/runTest.ts
View file
Open in desktop

This file was deleted.

61 changes: 41 additions & 20 deletionssrc/actions/setupActions.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,34 +4,34 @@ import * as vscode from 'vscode'
import * as git from '../services/git'
import node from '../services/node'

interface ErrorMessageFilter {
[lang: string]: {
[key: string]: string
}
}
//interface ErrorMessageFilter {
//[lang: string]: {
//[key: string]: string
//}
//}

// TODO: should be loaded on startup based on language
const commandErrorMessageFilter: ErrorMessageFilter = {
#"988df5f6726e51589d340b504265b1889b2b005fede487b6517e8eeb50e40047">'node-gyp': 'Error running npm setup command'
}
}
//const commandErrorMessageFilter: ErrorMessageFilter = {
//#"988df5f6726e51589d340b504265b1889b2b005fede487b6517e8eeb50e40047">//'node-gyp': 'Error running npm setup command'
//}
//}


// TODO: pass command and command name down for filtering. Eg. JAVASCRIPT, 'npm install'
const runCommands = async (commands: string[], language: string = 'JAVASCRIPT') => {
const runCommands = async (commands: string[]) => {
for (const command of commands) {
const {stdout, stderr} = await node.exec(command)
if (stderr) {
console.error(stderr)
// language specific error messages from running commands
const filteredMessages = Object.keys(commandErrorMessageFilter[language])
for (const message of filteredMessages) {
if (stderr.match(message)) {
// ignored error
throw new Error('Error running setup command')
}
}
//const filteredMessages = Object.keys(commandErrorMessageFilter[language])
//for (const message of filteredMessages) {
//if (stderr.match(message)) {
//// ignored error
//throw new Error('Error running setup command')
//}
//}
}
console.log(`run command: ${command}`, stdout)
}
Expand All@@ -45,7 +45,8 @@ const disposeWatcher = (listener: string) => {
delete watchers[listener]
}

const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, commits, files, listeners}: G.StepActions): Promise<void> => {
const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, actions: G.StepActions): Promise<void> => {
const {commands, commits, files, listeners} = actions
// run commits
if (commits) {
for (const commit of commits) {
Expand All@@ -55,16 +56,36 @@ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, co

// run file watchers (listeners)
if (listeners) {
console.log('listeners')
for (const listener of listeners) {
if (!watchers[listener]) {
const pattern = new vscode.RelativePattern(
vscode.workspace.getWorkspaceFolder(workspaceRoot.uri)!,
listener
)
watchers[listener] = vscode.workspace.createFileSystemWatcher(
console.log(pattern)
const listen = vscode.workspace.createFileSystemWatcher(
pattern
)
watchers[listener] = listen
watchers[listener].onDidChange(() => {
console.log('onDidChange')
// trigger save
vscode.commands.executeCommand('coderoad.run_test', null, () => {
// cleanup watcher on success
disposeWatcher(listener)
})
})
watchers[listener].onDidCreate(() => {
console.log('onDidCreate')
// trigger save
vscode.commands.executeCommand('coderoad.run_test', null, () => {
// cleanup watcher on success
disposeWatcher(listener)
})
})
watchers[listener].onDidDelete(() => {
console.log('onDidDelete')
// trigger save
vscode.commands.executeCommand('coderoad.run_test', null, () => {
// cleanup watcher on success
Expand Down
26 changes: 23 additions & 3 deletionssrc/actions/tutorialConfig.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
import * as G from 'typings/graphql'
import * as vscode from 'vscode'
import * as git from '../services/git'
import langaugeMap from '../editor/languageMap'
import languageMap from '../editor/languageMap'
import {COMMANDS} from '../editor/commands'

interface TutorialConfigParams {
config: G.TutorialConfig,
Expand All@@ -19,10 +20,29 @@ const tutorialConfig = async ({config, alreadyConfigured, }: TutorialConfigParam
await git.setupRemote(config.repo.uri)
}

vscode.commands.executeCommand(COMMANDS.CONFIG_TEST_RUNNER, config.testRunner)

const fileFormats = config.testRunner.fileFormats

// verify if file test should run based on document saved
const shouldRunTest = (document: vscode.TextDocument): boolean => {
// must be a file
if (document.uri.scheme !== 'file') {
return false
}
// must configure with file formatss
if (fileFormats && fileFormats.length) {
const fileFormat: G.FileFormat = languageMap[document.languageId]
if (!fileFormats.includes(fileFormat)) {
return false
}
}
return true
}

// setup onSave hook
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
const fileFormat: G.FileFormat = langaugeMap[document.languageId]
if (document.uri.scheme === 'file' && config.fileFormats.includes(fileFormat)) {
if (shouldRunTest(document)) {
vscode.commands.executeCommand('coderoad.run_test')
}
})
Expand Down
1 change: 0 additions & 1 deletionsrc/editor/ReactWebView.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,7 +161,6 @@ class ReactWebView {
}
}


// set CSP (content security policy) to grant permission to local files
const cspMeta: HTMLMetaElement = document.createElement('meta')
cspMeta.httpEquiv = 'Content-Security-Policy'
Expand Down
43 changes: 23 additions & 20 deletionssrc/editor/commands.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
import * as G from 'typings/graphql'
import * as vscode from 'vscode'
import ReactWebView from './ReactWebView'
importrunTestfrom '../actions/runTest'
importcreateTestRunner, {Payload}from '../services/testRunner'

const COMMANDS = {
exportconst COMMANDS = {
START: 'coderoad.start',
OPEN_WEBVIEW: 'coderoad.open_webview',
CONFIG_TEST_RUNNER: 'coderoad.config_test_runner',
RUN_TEST: 'coderoad.run_test',
SET_CURRENT_STEP: 'coderoad.set_current_step',
}
Expand All@@ -19,6 +21,7 @@ export const createCommands = ({extensionPath, workspaceState, workspaceRoot}: C
// React panel webview
let webview: any
let currentStepId = ''
let testRunner: any

return {
// initialize
Expand DownExpand Up@@ -49,37 +52,37 @@ export const createCommands = ({extensionPath, workspaceState, workspaceRoot}: C
// setup 1x1 horizontal layout
webview.createOrShow()
},
[COMMANDS.SET_CURRENT_STEP]: ({stepId}: {stepId: string}) => {
// NOTE: as async, may sometimes be inaccurate
// set from last setup stepAction
currentStepId = stepId
},
[COMMANDS.RUN_TEST]: (current: {stepId: string} | undefined, onSuccess: () => void) => {
console.log('-------- command.run_test ------ ')
// use stepId from client, or last set stepId
const payload = {stepId: current ? current.stepId : currentStepId}
runTest({
onSuccess: () => {
[COMMANDS.CONFIG_TEST_RUNNER]: (config: G.TutorialTestRunner) => {
testRunner = createTestRunner(config, {
onSuccess: (payload: Payload) => {
// send test pass message back to client
webview.send({type: 'TEST_PASS', payload})
onSuccess()
vscode.window.showInformationMessage('PASS')
webview.send({type: 'TEST_PASS', payload})
},
onFail: () => {
onFail: (payload: Payload) => {
// send test fail message back to client
webview.send({type: 'TEST_FAIL', payload})
vscode.window.showWarningMessage('FAIL')
webview.send({type: 'TEST_FAIL', payload})
},
onError: () => {
console.log('COMMAND TEST_ERROR')
onError: (payload: Payload) => {
// send test error message back to client
webview.send({type: 'TEST_ERROR', payload})
},
onRun: () => {
onRun: (payload: Payload) => {
// send test run message back to client
webview.send({type: 'TEST_RUNNING', payload})
}
})
},
[COMMANDS.SET_CURRENT_STEP]: ({stepId}: Payload) => {
// NOTE: as async, may sometimes be inaccurate
// set from last setup stepAction
currentStepId = stepId
},
[COMMANDS.RUN_TEST]: (current: Payload | undefined, onSuccess: () => void) => {
// use stepId from client, or last set stepId
const payload: Payload = {stepId: current ? current.stepId : currentStepId}
testRunner(payload, onSuccess)
},
}
}
1 change: 0 additions & 1 deletionsrc/editor/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,6 @@ class Editor {
}

private activateCommands = (): void => {

// set workspace root for node executions
const workspaceRoots: vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders
if (!workspaceRoots || !workspaceRoots.length) {
Expand Down
10 changes: 10 additions & 0 deletionssrc/editor/outputChannel.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
import * as vscode from 'vscode'

let channel: vscode.OutputChannel

export const getOutputChannel = (name: string): vscode.OutputChannel => {
if (!channel) {
channel = vscode.window.createOutputChannel(name)
}
return channel
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp