Skip to content

Commit fddcef7

Browse files
committed
chore: add error logging to loadConfig
1 parent e7f9fa0 commit fddcef7

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

lib/loadConfig.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ const searchPlaces = [
1919
'lint-staged.config.cjs',
2020
]
2121

22-
const dynamicImport = (path) => import(path).then((module) => module.default)
22+
/** exported for tests */
23+
export const dynamicImport = (path) =>
24+
import(path)
25+
.then((module) => module.default)
26+
.catch((error) => {
27+
console.error(error)
28+
throw error
29+
})
2330

2431
const jsonParse = (path, content) => JSON.parse(content)
2532

package-lock.json

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"fs-extra": "^10.0.0",
5959
"husky": "^7.0.4",
6060
"jest": "^27.3.1",
61-
"jest-mock-console": "^1.2.3",
6261
"jest-snapshot-serializer-ansi": "^1.0.0",
6362
"prettier": "^2.4.1"
6463
},

test/loadConfig.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import makeConsoleMock from 'consolemock'
2+
3+
import { dynamicImport } from '../lib/loadConfig.js'
4+
5+
describe('dynamicImport', () => {
6+
const globalConsoleTemp = console
7+
8+
beforeEach(() => {
9+
console = makeConsoleMock()
10+
})
11+
12+
afterAll(() => {
13+
console = globalConsoleTemp
14+
})
15+
16+
it('should log errors into console', () => {
17+
expect(() => dynamicImport('not-found.js')).rejects.toMatchInlineSnapshot(
18+
`[Error: Cannot find module 'not-found.js' from 'lib/loadConfig.js']`
19+
)
20+
})
21+
})

0 commit comments

Comments
 (0)