-
Notifications
You must be signed in to change notification settings - Fork 795
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 ri…
…ght (#3346) 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
ad1b68a
commit b7adc33
Showing
7 changed files
with
182 additions
and
44 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
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
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,68 @@ | ||
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', () => { | ||
describe('ensure', () => { | ||
let readFSMock: jest.SpyInstance<ReturnType<typeof fs.readFileSync>, Parameters<typeof fs.readFileSync>>; | ||
|
||
beforeEach(() => { | ||
readFSMock = jest.spyOn(fs, 'readFileSync').mockReturnValue(mockPackageJson('10.10.10')); | ||
}); | ||
|
||
afterEach(() => { | ||
readFSMock.mockClear(); | ||
}); | ||
|
||
function setup() { | ||
const resolveModule = new NodeResolveModule(); | ||
const nodeLazyRequire = new NodeLazyRequire(resolveModule, { | ||
jest: ['2.0.7', '38.0.1'], | ||
}); | ||
return nodeLazyRequire; | ||
} | ||
|
||
it.each(['2.0.7', '10.10.10', '38.0.1', '38.0.2', '38.5.17'])( | ||
'should not error if installed package has a suitable major version (%p)', | ||
async (testVersion) => { | ||
const nodeLazyRequire = 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 = 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.each(['100.1.1', '38.0.1-alpha.0'])( | ||
'should error if the installed version of a package is too high (%p)', | ||
async (version) => { | ||
const nodeLazyRequire = setup(); | ||
readFSMock.mockReturnValue(mockPackageJson(version)); | ||
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', | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
}); |