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

ipetinate / clingon / 9651901754

24 Jun 2024 08:21PM UTC coverage: 94.098% (-4.8%) from 98.875%
9651901754

push

github

web-flow
Merge pull request #52 from ipetinate/feat/advanced-command

feat: Advanced command

427 of 440 branches covered (97.05%)

Branch coverage included in aggregate %.

979 of 1128 new or added lines in 15 files covered. (86.79%)

35 existing lines in 4 files now uncovered.

3033 of 3237 relevant lines covered (93.7%)

2.36 hits per line

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

88.28
/src/utils/file.test.js
1
import fs from 'node:fs'
1✔
2

1✔
3
import assert from 'node:assert/strict'
1✔
4
import { describe, it, todo, mock } from 'node:test'
1✔
5

1✔
6
import {
1✔
7
  checkFileExists,
1✔
8
  createFileWithContent,
1✔
9
  getFiles,
1✔
10
  readFileContent
1✔
11
} from './file.js'
1✔
12

1✔
13
const accesSync = mock.method(fs, 'accessSync')
1✔
14
const mockFsReadDirSync = mock.method(fs, 'readdirSync')
1✔
15
const mockFsReadFileSync = mock.method(fs, 'readFileSync')
1✔
16
const mockFsWriteFileSync = mock.method(fs, 'writeFileSync')
1✔
17

1✔
18
const mockFolderFiles = ['mockFile.json', 'mocks.js', 'fakeFile.ts']
1✔
19

1✔
20
describe('File Util', () => {
1✔
21
  describe('getFiles', () => {
1✔
22
    it('get files from root dir', () => {
1✔
23
      mockFsReadDirSync.mock.mockImplementation(() => mockFolderFiles)
1✔
24

1✔
25
      const files = getFiles()
1✔
26

1✔
27
      for (const [index, filePath] of files) {
1✔
28
        assert.match(filePath, new RegExp(mockFolderFiles[index]))
3✔
29
      }
3✔
30
    })
1✔
31

1✔
32
    it('get files content error flow', () => {
1✔
33
      mockFsReadDirSync.mock.mockImplementation(() => {
1✔
34
        throw new Error('fake error')
1✔
35
      })
1✔
36

1✔
37
      assert.throws(getFiles, Error)
1✔
38
    })
1✔
39
  })
1✔
40

1✔
41
  describe('readFileContent', () => {
1✔
42
    it('get file content', () => {
1✔
43
      mockFsReadFileSync.mock.mockImplementation((fileName) => {
1✔
44
        const files = {
1✔
45
          'clingon.json': '{"exportDefault":false}'
1✔
46
        }
1✔
47

1✔
48
        return files[fileName]
1✔
49
      })
1✔
50

1✔
51
      const fileContent = readFileContent('clingon.json')
1✔
52

1✔
53
      assert.deepEqual(JSON.parse(fileContent), { exportDefault: false })
1✔
54
    })
1✔
55

1✔
56
    it('get file content error flow', () => {
1✔
57
      const expectToThrowError = () => {
1✔
UNCOV
58
        const fileContent = readFileContent('/clingon.blabla')
×
UNCOV
59

×
UNCOV
60
        assert.strictEqual(fileContent, undefined)
×
UNCOV
61
        assert.throws(expectToThrowError, Error)
×
UNCOV
62
      }
×
63
    })
1✔
64
  })
1✔
65

1✔
66
  describe('createFileWithContent', () => {
1✔
67
    it('create a file with content', () => {
1✔
68
      mockFsWriteFileSync.mock.mockImplementation(() => true)
1✔
69

1✔
70
      const success = createFileWithContent('test.json', 'content')
1✔
71

1✔
72
      assert.strictEqual(success, true)
1✔
73
    })
1✔
74

1✔
75
    it('create a file with content should throw error', () => {
1✔
76
      mockFsWriteFileSync.mock.mockImplementation(() => {
1✔
77
        throw new Error('wrong file format')
1✔
78
      })
1✔
79

1✔
80
      const success = createFileWithContent('test.json', {
1✔
81
        invalid: 'content'
1✔
82
      })
1✔
83

1✔
84
      assert.strictEqual(success, false)
1✔
85
    })
1✔
86
  })
1✔
87

1✔
88
  describe('checkFileExists', () => {
1✔
89
    it('return true if the file exists', () => {
1✔
90
      accesSync.mock.mockImplementation(() => true)
1✔
91

1✔
92
      const fileExists = checkFileExists('./myDirectory/myFile.txt')
1✔
93

1✔
94
      assert.strictEqual(fileExists, true)
1✔
95
    })
1✔
96

1✔
97
    it.skip('return false if the file does not exist', () => {
1✔
UNCOV
98
      accesSync.mock.mockImplementation(() => false)
×
UNCOV
99

×
UNCOV
100
      const fileExists = checkFileExists('./myDirectory/nonExistentFile.txt')
×
UNCOV
101

×
UNCOV
102
      assert.strictEqual(fileExists, false)
×
103
    })
1✔
104

1✔
105
    it('return true for an existing nested file', () => {
1✔
106
      accesSync.mock.mockImplementation(() => true)
1✔
107

1✔
108
      const fileExists = checkFileExists('./myDirectory/nested/nestedFile.txt')
1✔
109

1✔
110
      assert.strictEqual(fileExists, true)
1✔
111
    })
1✔
112

1✔
113
    it.skip('return false for a non-existing nested file', () => {
1✔
UNCOV
114
      accesSync.mock.mockImplementation(() => false)
×
UNCOV
115

×
UNCOV
116
      const fileExists = checkFileExists(
×
UNCOV
117
        './myDirectory/nested/nonExistentFile.txt'
×
UNCOV
118
      )
×
UNCOV
119

×
UNCOV
120
      assert.strictEqual(fileExists, false)
×
121
    })
1✔
122
  })
1✔
123
})
1✔
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