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

Fix/test runner#55

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 3 commits intomasterfromfix/test-runner
Nov 16, 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
2 changes: 1 addition & 1 deletionsrc/editor/commands.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,7 @@ export const createCommands = ({ extensionPath, workspaceState, workspaceRoot }:
},
onFail: (payload: Payload, message: string) => {
// send test fail message back to client
vscode.window.showWarningMessage(`FAIL: ${message}`)
vscode.window.showWarningMessage(`FAIL ${message}`)
webview.send({ type: 'TEST_FAIL', payload })
},
onError: (payload: Payload) => {
Expand Down
45 changes: 20 additions & 25 deletionssrc/services/testRunner/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import node from '../../services/node'
import { getOutputChannel } from '../../editor/outputChannel'
import parser from './parser'
import { setLatestProcess, isLatestProcess } from './throttle'
//import { setLatestProcess, isLatestProcess } from './throttle'

export interface Payload {
stepId: string
Expand All@@ -22,7 +22,7 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
const outputChannelName = 'TEST_OUTPUT'

return async (payload: Payload, onSuccess?: () => void): Promise<void> => {
console.log('-------------------run test------------------')
console.log('-------------------RUN TEST -------------------')

// flag as running
callbacks.onRun(payload)
Expand All@@ -31,41 +31,36 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
try {
result = await node.exec(config.command)
} catch (err) {
result = err
result ={ stdout:err.stdout, stderr: err.stack }
}
const { stdout, stderr } = result

// simple way to throttle requests
if (!stdout) {
return
}

const tap = parser(stdout || '')
if (stderr) {
callbacks.onError(payload)

// open terminal with error string
const channel = getOutputChannel(outputChannelName)
channel.show(false)
channel.appendLine(stderr)
return
// failures also trigger stderr
if (stdout && stdout.length && !tap.ok) {
const message = tap.message ? tap.message : ''
callbacks.onFail(payload, message)
return
} else {
callbacks.onError(payload)
// open terminal with error string
const channel = getOutputChannel(outputChannelName)
channel.show(false)
channel.appendLine(stderr)
return
}
}

// pass or fail?
const tap = parser(stdout)
// success!
if (tap.ok) {
callbacks.onSuccess(payload)
if (onSuccess) {
onSuccess()
}
} else {
// TODO: consider logging output to channel
// open terminal with failed test string
// const channel = getOutputChannel(outputChannelName)
// channel.show(false)
// channel.appendLine(tap.message)

const message = tap.message ? tap.message : ''
callbacks.onFail(payload, message)
// should never get here
callbacks.onError(payload)
}
}
}
Expand Down
11 changes: 11 additions & 0 deletionssrc/services/testRunner/parser.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,17 @@ ok 2 - Should also pass
ok 1 - Should pass
not ok 2 - This one fails
ok 3 - Also passes
`
expect(parser(example).ok).toBe(false)
})
test('should detect failure if no tests passed', () => {
const example = `
# Starting...
# 1 test suites found.

# FAIL __tests__/sum.test.js

not ok 1 ● sum › should add two numbers together
`
expect(parser(example).ok).toBe(false)
})
Expand Down
21 changes: 16 additions & 5 deletionssrc/services/testRunner/parser.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,16 +3,27 @@ interface ParserOutput {
message?: string
}

const fail = /^not ok \d+ .{1} (.+)+$/
const ok = /^ok \d+ .{1} /

const parser = (text: string): ParserOutput => {
const lines = text.split('\n')
let hasPass = false
for (const line of lines) {
// parse failed test
const match = line.match(/^not ok \d+ - (.+)+/)
if (!!match) {
return { ok: false, message: match[1] }
if (line.length) {
// parse failed test
const failRegex = fail.exec(line)
if (!!failRegex) {
return { ok: false, message: failRegex[1] }
}
if (!hasPass) {
if (!!ok.exec(line)) {
hasPass = true
}
}
}
}
return { ok:true }
return { ok:hasPass }
}

export default parser

[8]ページ先頭

©2009-2025 Movatter.jp