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

Improved Test Logging#217

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 2 commits intomasterfromlogs
Apr 6, 2020
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
8 changes: 5 additions & 3 deletionssrc/services/testRunner/formatOutput.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,10 +4,12 @@ import { ParserOutput, Fail } from './parser'
// export const formatSuccessOutput = (tap: ParserOutput): string => {}

export const formatFailOutput = (tap: ParserOutput): string => {
let output = `'TESTSFAILED\n`
let output = `FAILED TESTS\n`
tap.failed.forEach((fail: Fail) => {
const details = fail.details ? `\n${fail.details}\n\n` : ''
output += ` ✘ ${fail.message}\n${details}`
const details = fail.details ? `\n${fail.details}\n` : ''
const logs = fail.logs ? `\n${fail.logs.join('\n')}\n` : ''
const result = `${logs} ✘ ${fail.message}\n${details}`
output += result
})
return output
}
12 changes: 9 additions & 3 deletionssrc/services/testRunner/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,9 @@ interface TestRunnerConfig {
command:string
}

constfailChannelName='CodeRoad (Tests)'
constlogChannelName='CodeRoad (Logs)'

constcreateTestRunner=(config:TestRunnerConfig,callbacks:Callbacks)=>{
returnasync(payload:Payload,onSuccess?:()=>void):Promise<void>=>{
conststartTime=throttle()
Expand DownExpand Up@@ -52,25 +55,28 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
const{ stdout, stderr}=result

consttap=parser(stdout||'')

displayOutput({channel:logChannelName,text:tap.logs.join('\n'),show:false})

if(stderr){
// FAIL also trigger stderr
if(stdout&&stdout.length&&!tap.ok){
constfirstFailMessage=tap.failed[0].message
callbacks.onFail(payload,firstFailMessage)
constoutput=formatFailOutput(tap)
displayOutput(output)
displayOutput({channel:failChannelName,text:output,show:true})
return
}else{
callbacks.onError(payload)
// open terminal with error string
displayOutput(stderr)
displayOutput({channel:failChannelName,text:stderr,show:true})
return
}
}

// PASS
if(tap.ok){
clearOutput()
clearOutput(failChannelName)
callbacks.onSuccess(payload)
if(onSuccess){
onSuccess()
Expand Down
26 changes: 15 additions & 11 deletionssrc/services/testRunner/output.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
import * as vscode from 'vscode'

let channel:vscode.OutputChannel
const channels: { key: string; value:vscode.OutputChannel } | {} = {}

const getOutputChannel = (name: string): vscode.OutputChannel => {
if (!channel) {
channel = vscode.window.createOutputChannel(name)
if (!channels[name]) {
channels[name] = vscode.window.createOutputChannel(name)
}
returnchannel
returnchannels[name]
}

const outputChannelName = 'CodeRoad Output'
interface DisplayOutput {
channel: string
text: string
show?: boolean
}

export const displayOutput = (text: string) => {
const channel = getOutputChannel(outputChannelName)
export const displayOutput = (params: DisplayOutput) => {
const channel = getOutputChannel(params.channel)
channel.clear()
channel.show(true)
channel.append(text)
channel.show(params.show || false)
channel.append(params.text)
}

export const clearOutput = () => {
const channel = getOutputChannel(outputChannelName)
export const clearOutput = (channelName: string) => {
const channel = getOutputChannel(channelName)
channel.show(false)
channel.clear()
channel.hide()
Expand Down
33 changes: 32 additions & 1 deletionsrc/services/testRunner/parser.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ describe('parser', () => {
1..1
ok 1 - Should pass
`
expect(parser(example)).toEqual({ ok: true, passed: [{ message: 'Should pass' }], failed: [] })
expect(parser(example)).toEqual({ ok: true, passed: [{ message: 'Should pass' }], failed: [], logs: [] })
})
test('should detect multiple successes', () => {
const example = `
Expand All@@ -19,6 +19,7 @@ ok 2 - Should also pass
ok: true,
passed: [{ message: 'Should pass' }, { message: 'Should also pass' }],
failed: [],
logs: [],
})
})
test('should detect failure if no tests passed', () => {
Expand DownExpand Up@@ -141,4 +142,34 @@ at processImmediate (internal/timers.js:439:21)`)
expect(result.failed[1].message).toBe('package.json should have a valid "description" key')
expect(result.failed[1].details).toBe(`AssertionError [ERR_ASSERTION]: no "description" key provided`)
})
test('should capture logs', () => {
const example = `
1..2
ok 1 package.json should have "express" installed
log 1
log 2
not ok 2 server should log "Hello World"
# AssertionError [ERR_ASSERTION]: "Hello World was not logged
# at Context.<anonymous> (test/server.test.js:15:12)
# at processImmediate (internal/timers.js:439:21)
# tests 2
# pass 1
# fail 1
# skip 0
`
expect(parser(example)).toEqual({
ok: false,
passed: [{ message: 'package.json should have "express" installed' }],
failed: [
{
message: 'server should log "Hello World"',
details: `AssertionError [ERR_ASSERTION]: \"Hello World was not logged
at Context.<anonymous> (test/server.test.js:15:12)
at processImmediate (internal/timers.js:439:21)`,
logs: ['log 1', 'log 2'],
},
],
logs: ['log 1', 'log 2'],
})
})
})
41 changes: 36 additions & 5 deletionssrc/services/testRunner/parser.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
export interface Fail {
message: string
details?: string
logs?: string[]
}

export interface Pass {
message: string
logs?: string[]
}

export interface ParserOutput {
ok: boolean
passed: Array<{ message: string }>
failed: Array<Fail>
passed: Pass[]
failed: Fail[]
logs: string[]
}

const r = {
start: /^1\.\.[0-9]+$/,
fail: /^not ok \d+\s(\-\s)?(.+)+$/,
pass: /^ok \d+\s(\-\s)?(.+)+$/,
details: /^#\s{2}(.+)$/,
ignore: /^#\s+(tests|pass|fail|skip)\s+[0-9]+$/,
}

const detect = (type: 'fail' | 'pass' | 'details', text: string) => r[type].exec(text)

const parser = (text: string): ParserOutput => {
const lines = text.split('\n')
const lineList = text.split('\n')
// start after 1..n output
const startingPoint = lineList.findIndex((t) => t.match(r.start))
const lines = lineList.slice(startingPoint + 1)

const result: ParserOutput = {
ok: true,
passed: [],
failed: [],
logs: [],
}

// temporary holder of error detail strings
let currentDetails: string | null = null
let logs: string[] = []

const addCurrentDetails = () => {
const failLength: number = result.failed.length
Expand All@@ -44,7 +58,12 @@ const parser = (text: string): ParserOutput => {
// be optimistic! check for success
const isPass = detect('pass', line)
if (!!isPass) {
result.passed.push({ message: isPass[2].trim() })
const pass: Pass = { message: isPass[2].trim() }
if (logs.length) {
pass.logs = logs
logs = []
}
result.passed.push(pass)
addCurrentDetails()
continue
}
Expand All@@ -54,7 +73,12 @@ const parser = (text: string): ParserOutput => {
if (!!isFail) {
result.ok = false
addCurrentDetails()
result.failed.push({ message: isFail[2].trim() })
const fail: Fail = { message: isFail[2].trim() }
if (logs.length) {
fail.logs = logs
logs = []
}
result.failed.push(fail)
continue
}

Expand All@@ -68,6 +92,13 @@ const parser = (text: string): ParserOutput => {
// @ts-ignore ignore as it must be a string
currentDetails += `\n${lineDetails}`
}
continue
}

if (!r.ignore.exec(line)) {
// must be a log, associate with the next test
logs.push(line)
result.logs.push(line)
}
}
addCurrentDetails()
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp