-
-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test suite for getWebpackResolver
Because `getWebpackResolver` is now part of `utils.js`' public API, we should test it separately so that we have some protection against its API changing drastically from potential future refactors.
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { fileURLToPath } from 'url'; | ||
|
||
import enhanced from 'enhanced-resolve'; | ||
|
||
import { getWebpackResolver } from '../src/utils'; | ||
|
||
/** | ||
* Because `getWebpackResolver` is a public function that can be imported by | ||
* external packages, we want to test it separately to ensure its API does not | ||
* change unexpectedly. | ||
*/ | ||
describe('getWebpackResolver', () => { | ||
const resolve = (request, ...options) => | ||
getWebpackResolver(enhanced.create, ...options)(__filename, request); | ||
|
||
it('should resolve .scss from node_modules', async () => { | ||
expect(await resolve('scss/style')).toMatch(/style\.scss$/); | ||
}); | ||
|
||
it('should resolve from passed `includePaths`', async () => { | ||
expect(await resolve('empty', null, [`${__dirname }/scss`])).toMatch( | ||
/empty\.scss$/ | ||
); | ||
}); | ||
|
||
it('should reject when file cannot be resolved', async () => { | ||
await expect(resolve('foo/bar/baz')).rejects.toBe(); | ||
}); | ||
|
||
it('should strip an invalid file URL of its scheme', async () => { | ||
const invalidFileURL = 'file://scss/empty'; | ||
|
||
expect(() => fileURLToPath(invalidFileURL)).toThrow(); | ||
expect(await resolve(invalidFileURL)).toMatch(/empty\.scss$/); | ||
}); | ||
}); |