-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sys): make NodeLazyRequire complain if package versions aren't right
This updates a bit of logic in `NodeLazyRequire.ensure` to check that the installed versions of packages are within the specified version range, i.e. that `minVersion <= installedVersion <= maxVersion`. This commit also adds tests for that module. STENCIL-391: bug: @stencil/core does not throw error when missing jest/jest-cli deps in a rush/pnpm monorepo
- Loading branch information
1 parent
cb8eebc
commit 24eb9d2
Showing
5 changed files
with
91 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,58 @@ | ||
import { NodeLazyRequire } from '../node-lazy-require'; | ||
import { buildError } from '@utils'; | ||
import { NodeResolveModule } from '../node-resolve-module'; | ||
import fs from 'graceful-fs'; | ||
|
||
const mockPackageJson = (version: string) => | ||
JSON.stringify({ | ||
version, | ||
}); | ||
|
||
describe('node-lazy-require', () => { | ||
describe('NodeLazyRequire', () => { | ||
function setup() { | ||
const resolveModule = new NodeResolveModule(); | ||
const readFSMock = jest.spyOn(fs, 'readFileSync').mockReturnValue(mockPackageJson('10.10.10')); | ||
|
||
const nodeLazyRequire = new NodeLazyRequire(resolveModule, { | ||
jest: ['2.0.7', '38.0.1'], | ||
}); | ||
return { | ||
nodeLazyRequire, | ||
readFSMock, | ||
}; | ||
} | ||
|
||
it.each(['2.0.7', '10.10.10', '38.0.1'])( | ||
'should not error if a package of suitable version (%p) is installed', | ||
async (testVersion) => { | ||
const { nodeLazyRequire, readFSMock } = setup(); | ||
readFSMock.mockReturnValue(mockPackageJson(testVersion)); | ||
let diagnostics = await nodeLazyRequire.ensure('.', ['jest']); | ||
expect(diagnostics.length).toBe(0); | ||
} | ||
); | ||
|
||
it('should error if the installed version of a package is too low', async () => { | ||
const { nodeLazyRequire, readFSMock } = setup(); | ||
readFSMock.mockReturnValue(mockPackageJson('1.1.1')); | ||
let [error] = await nodeLazyRequire.ensure('.', ['jest']); | ||
expect(error).toEqual({ | ||
...buildError([]), | ||
header: 'Please install supported versions of dev dependencies with either npm or yarn.', | ||
messageText: 'npm install --save-dev jest@38.0.1', | ||
}); | ||
}); | ||
|
||
it('should error if the installed version of a package is too high', async () => { | ||
const { nodeLazyRequire, readFSMock } = setup(); | ||
readFSMock.mockReturnValue(mockPackageJson('100.1.1')); | ||
let [error] = await nodeLazyRequire.ensure('.', ['jest']); | ||
expect(error).toEqual({ | ||
...buildError([]), | ||
header: 'Please install supported versions of dev dependencies with either npm or yarn.', | ||
messageText: 'npm install --save-dev jest@38.0.1', | ||
}); | ||
}); | ||
}); | ||
}); |