• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TotalTechGeek / pineapple / 5214826938

pending completion
5214826938

Pull #26

github

web-flow
Merge 738aa6380 into 5bafc7bbf
Pull Request #26: Add more arbitraries and omissions

2032 of 2187 branches covered (92.91%)

Branch coverage included in aggregate %.

108 of 108 new or added lines in 8 files covered. (100.0%)

9000 of 9336 relevant lines covered (96.4%)

1404.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.36
/inputs.js
1
import chalk from 'chalk'
12✔
2
import { serialize } from './snapshot.js'
12✔
3
import { diff } from './utils.js'
12✔
4
import { flush } from './run.js'
12✔
5
import { getDiff } from 'json-difference'
12✔
6

12✔
7
async function getConfirmation (message, choices = ['Yes', 'No ']) {
×
8
  if (typeof prompt !== 'undefined') {
×
9
    const result = prompt(`${message} (Y/N)`).toLowerCase()
×
10
    console.log()
×
11
    return result === 'y' || result === 'yes' ? 'Yes' : 'No '
×
12
  }
×
13
  return new Promise(resolve => {
×
14
    const currentMode = process.stdin.isRaw
×
15
    if (process.stdin.setRawMode) process.stdin.setRawMode(true)
×
16

×
17
    process.stdout.write(message + ' ')
×
18
    let choice = choices[0]
×
19
    process.stdout.write(choices[0])
×
20

×
21
    let position = 0
×
22

×
23
    const func = data => {
×
24
      if (data[0] === 13) {
×
25
        if (process.stdin.setRawMode) process.stdin.setRawMode(currentMode)
×
26
        process.stdin.removeListener('data', func)
×
27
        console.log()
×
28
        return resolve(choice)
×
29
      }
×
30

×
31
      data = data.toString()
×
32

×
33
      if (data === '\x1B[B') {
×
34
        process.stdout.write('\r')
×
35
        process.stdout.write(message + ' ')
×
36
        position++
×
37
        if (position >= choices.length) position = 0
×
38
        process.stdout.write(choices[position])
×
39
        choice = choices[position]
×
40
      }
×
41

×
42
      if (data === '\x1B[A') {
×
43
        process.stdout.write('\r')
×
44
        process.stdout.write(message + ' ')
×
45
        position--
×
46
        if (position < 0) position = choices.length - 1
×
47
        process.stdout.write(choices[position])
×
48
        choice = choices[position]
×
49
      }
×
50
    }
×
51

×
52
    process.stdin.on('data', func)
×
53
  })
×
54
}
×
55

12✔
56
/**
12✔
57
 * It asks the user if they want to accept the snapshot
12✔
58
 * @param {{ item: any, rule: string, id: string, file: string }} data
12✔
59
 * @returns A function that returns a boolean.
12✔
60
 */
12✔
61
export async function askSnapshot ({ item, rule, id, file }) {
3✔
62
  if (process.env.CI) return false
×
63
  if (process.env.ACCEPT_ALL) return true
×
64
  if (process.env.OUTPUT_FORMAT === 'JSON') {
×
65
    console.log(JSON.stringify({
×
66
      type: 'Request Snapshot',
×
67
      item: serialize(item),
×
68
      input: rule,
×
69
      id,
×
70
      file
×
71
    }))
×
72
    return false
×
73
  }
×
74
  console.log(`On test (${id.split('(')[0]}):`, rule)
×
75
  flush()
×
76

×
77
  console.log(chalk.green(serialize(item)))
×
78
  const result = await getConfirmation(`${chalk.magenta('?')} Accept this snapshot?`).catch(err => console.log(err))
×
79
  return result
×
80
}
×
81

12✔
82
/**
12✔
83
 * It asks the user if they want to update the snapshot
12✔
84
 * @param {{ item: any, rule: string, id: string, value: any, file: string }} data
12✔
85
 * @returns A function that returns a boolean.
12✔
86
 */
12✔
87
export async function askSnapshotUpdate ({ item, value, rule, id, file }) {
3✔
88
  if (process.env.CI) return false
×
89
  if (process.env.UPDATE_ALL) return true
×
90
  if (process.env.OUTPUT_FORMAT === 'JSON') {
×
91
    console.log(JSON.stringify({
×
92
      type: 'Request Snapshot Update',
×
93
      new: serialize(item),
×
94
      old: serialize(value),
×
95
      input: rule,
×
96
      id,
×
97
      file
×
98
    }))
×
99
    return false
×
100
  }
×
101
  console.log(`On test (${id.split('(')[0]}):`, rule)
×
102
  flush()
×
103

×
104
  console.log(diff(value, item))
×
105

×
106
  if (typeof value === typeof item && value && item && typeof value === 'object') {
×
107
    const differences = getDiff(value, item, true)
×
108
    if (differences.added.length === 0 && differences.removed.length === 0) {
×
109
      // This means that fields were modified, which means we can offer to omit the fields
×
110
      console.log(chalk.yellow('\nSome of the fields have been modified, you can choose to omit them.'))
×
111

×
112
      const result = await getConfirmation(`${chalk.magenta('?')} Do you wish to update to this snapshot?`, ['Yes ', 'No  ', 'Omit'])
×
113
      if (result === 'Omit') return { omitDeep: [{ var: '' }, differences.edited.map(i => i[0])] }
×
114
      return result === 'Yes '
×
115
    }
×
116
  }
×
117

×
118
  const result = await getConfirmation(`${chalk.magenta('?')} Do you wish to update to this snapshot?`)
×
119
  return result === 'Yes'
×
120
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc