@neurodevs/node-tdd 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -86,9 +86,10 @@ export default class TestReporter {
86
86
  public setWatchMode(watchMode: WatchMode) {
87
87
  this.watchMode = watchMode
88
88
  if (!this.countDownTimeInterval) {
89
- let label = watchMode === 'smart' ? 'Smart Watch' : 'Standard Watch'
89
+ let label =
90
+ watchMode === 'smart' ? 'Smart Watch ' : 'Standard Watch'
90
91
  if (watchMode === 'off') {
91
- label = 'Not Watching'
92
+ label = 'Not Watching '
92
93
  }
93
94
  this.setWatchLabel(label)
94
95
  }
@@ -221,7 +222,7 @@ export default class TestReporter {
221
222
  value: 'toggleDebug',
222
223
  },
223
224
  {
224
- label: 'Not Watching ',
225
+ label: 'Not Watching ',
225
226
  value: 'watchDropdown',
226
227
  items: [
227
228
  {
@@ -255,6 +256,7 @@ export default class TestReporter {
255
256
  this.setStatusLabel('Starting...')
256
257
  } else if (this.status === 'stopped') {
257
258
  this.refreshResults()
259
+ this.testLog?.scrollToTop()
258
260
  this.setStatusLabel('')
259
261
  } else if (this.status === 'running') {
260
262
  this.setStatusLabel('Running tests...')
@@ -331,22 +333,21 @@ export default class TestReporter {
331
333
  }
332
334
 
333
335
  private dropInTestLog() {
334
- const parent = this.bottomLayout.getChildById('results')
336
+ const parent = this.bottomLayout.getChildById('results')!
335
337
 
336
- if (parent) {
337
- this.testLog = this.widgets.Widget('text', {
338
- parent,
339
- isScrollEnabled: true,
340
- left: 0,
341
- top: 0,
342
- height: '100%',
343
- width: '100%',
344
- shouldLockHeightWithParent: true,
345
- shouldLockWidthWithParent: true,
346
- })
338
+ this.testLog = this.widgets.Widget('text', {
339
+ parent,
340
+ isScrollEnabled: true,
341
+ wordWrap: false,
342
+ left: 0,
343
+ top: 0,
344
+ height: '100%',
345
+ width: '100%',
346
+ shouldLockHeightWithParent: true,
347
+ shouldLockWidthWithParent: true,
348
+ })
347
349
 
348
- void this.testLog.on('click', this.handleClickTestLog.bind(this))
349
- }
350
+ void this.testLog.on('click', this.handleClickTestLog.bind(this))
350
351
  }
351
352
 
352
353
  private async handleClickTestLog(payload: { row: number; column: number }) {
@@ -437,7 +438,7 @@ export default class TestReporter {
437
438
  top: 1,
438
439
  height: 4,
439
440
  width: this.selectTestPopup.getFrame().width - 2,
440
- text: `What do you wanna do with:\n\n${testFile}`,
441
+ text: `Selected file:\n\n${testFile}`,
441
442
  })
442
443
 
443
444
  const open = this.widgets.Widget('button', {
@@ -481,13 +482,17 @@ export default class TestReporter {
481
482
 
482
483
  for (const file of this.lastResults.testFiles ?? []) {
483
484
  const minRow = line
484
- const maxRow = line + (file.tests ?? []).length
485
+ const lineCount =
486
+ 1 +
487
+ (file.tests ?? []).length +
488
+ (file.status === 'running' ? 1 : 0)
489
+ const maxRow = line + lineCount - 1
485
490
 
486
491
  if (row >= minRow && row <= maxRow) {
487
492
  return file.path
488
493
  }
489
494
 
490
- line = maxRow
495
+ line = maxRow + 1
491
496
  }
492
497
 
493
498
  return undefined
@@ -657,7 +662,17 @@ export default class TestReporter {
657
662
  let logContent = ''
658
663
  let errorContent = ''
659
664
 
660
- results.testFiles?.forEach((file) => {
665
+ const files = [...(results.testFiles ?? [])]
666
+
667
+ if (this.status === 'stopped') {
668
+ files.sort((a, b) => {
669
+ const aFailed = a.status === 'failed' ? 0 : 1
670
+ const bFailed = b.status === 'failed' ? 0 : 1
671
+ return aFailed - bFailed
672
+ })
673
+ }
674
+
675
+ files.forEach((file) => {
661
676
  logContent += this.errorLogItemGenerator.generateLogItemForFile(
662
677
  file,
663
678
  this.status
@@ -50,7 +50,7 @@ export default class TkTextWidget extends TkBaseWidget implements TextWidget {
50
50
 
51
51
  const line = this.text.content.split('\n')[y]
52
52
 
53
- await (this as TextWidget).emit('click', {
53
+ this.emit('click', {
54
54
  text: line,
55
55
  row: y,
56
56
  column: x,
@@ -71,7 +71,12 @@ export default class TkTextWidget extends TkBaseWidget implements TextWidget {
71
71
  width: newFrame.width ?? oldFrame.width,
72
72
  height: newFrame.height ?? oldFrame.height,
73
73
  })
74
- this.text.draw()
74
+
75
+ if (this.text.scrollable) {
76
+ this.text.scrollTo(null, this.text.scrollY)
77
+ } else {
78
+ this.text.draw()
79
+ }
75
80
  }
76
81
 
77
82
  public getText(): string {
@@ -93,6 +98,10 @@ export default class TkTextWidget extends TkBaseWidget implements TextWidget {
93
98
  return this.text.scrollY
94
99
  }
95
100
 
101
+ public scrollToTop() {
102
+ this.text.scrollTo(null, 0)
103
+ }
104
+
96
105
  public getScrollX() {
97
106
  return this.text.scrollX
98
107
  }
@@ -1,4 +1,5 @@
1
1
  import chokidar from 'chokidar'
2
+ import { spawn } from 'child_process'
2
3
  import path from 'path'
3
4
  import CommandServiceImpl from './CommandService.js'
4
5
  import TestReporter from './TestReporter.js'
@@ -64,6 +65,12 @@ const reporter = new TestReporter({
64
65
  currentWatchMode = currentWatchMode === 'smart' ? 'off' : 'smart'
65
66
  reporter.setWatchMode(currentWatchMode)
66
67
  },
68
+ handleOpenTestFile: (filePath: string) => {
69
+ const fullPath = path.isAbsolute(filePath)
70
+ ? filePath
71
+ : path.join(cwd, 'src', '__tests__', filePath)
72
+ spawn('code', [fullPath], { detached: true, stdio: 'ignore' }).unref()
73
+ },
67
74
  })
68
75
 
69
76
  async function runTests() {
@@ -23,4 +23,5 @@ export interface TextWidget extends BaseWidget<TextEventContract> {
23
23
  setText(content: string): void
24
24
  getScrollX(): number
25
25
  getScrollY(): number
26
+ scrollToTop(): void
26
27
  }