Skip to content

Commit

Permalink
fix: fix Windows JS config loading by using file:// URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Nov 22, 2021
1 parent e96b6d9 commit f20ddf9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/loadConfig.js
@@ -1,3 +1,5 @@
import { pathToFileURL } from 'url'

import { lilconfig } from 'lilconfig'
import YAML from 'yaml'

Expand All @@ -21,7 +23,7 @@ const searchPlaces = [

/** exported for tests */
export const dynamicImport = (path) =>
import(path)
import(pathToFileURL(path))
.then((module) => module.default)
.catch((error) => {
console.error(error)
Expand Down
8 changes: 8 additions & 0 deletions test/index.spec.js
Expand Up @@ -18,6 +18,14 @@ const mockLilConfig = (result) => {
}))
}

/**
* This converts paths into `file://` urls, but this doesn't
* work with `import()` when using babel + jest.
*/
jest.mock('url', () => ({
pathToFileURL: (path) => path,
}))

jest.mock('../lib/getStagedFiles')
jest.mock('../lib/gitWorkflow')
jest.mock('../lib/validateOptions', () => ({
Expand Down
4 changes: 1 addition & 3 deletions test/loadConfig.spec.js
Expand Up @@ -14,8 +14,6 @@ describe('dynamicImport', () => {
})

it('should log errors into console', () => {
expect(() => dynamicImport('not-found.js')).rejects.toMatchInlineSnapshot(
`[Error: Cannot find module 'not-found.js' from 'lib/loadConfig.js']`
)
expect(() => dynamicImport('not-found.js')).rejects.toThrowError(`Cannot find module`)
})
})

0 comments on commit f20ddf9

Please sign in to comment.