-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1018 from ckeditor/i/17191-pacote
Other (release-tools): We do not spawn an npm process to download a package manifest from the npm registry. Instead, we send an HTTP request using the `pacote` package. Closes ckeditor/ckeditor5#17191.
- Loading branch information
Showing
12 changed files
with
172 additions
and
238 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
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
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 |
---|---|---|
|
@@ -3,61 +3,23 @@ | |
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import { tools } from '@ckeditor/ckeditor5-dev-utils'; | ||
import shellEscape from 'shell-escape'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import pacote from 'pacote'; | ||
import checkVersionAvailability from '../../lib/utils/checkversionavailability.js'; | ||
|
||
vi.mock( 'shell-escape' ); | ||
vi.mock( '@ckeditor/ckeditor5-dev-utils' ); | ||
vi.mock( 'pacote' ); | ||
|
||
describe( 'checkVersionAvailability()', () => { | ||
beforeEach( () => { | ||
vi.mocked( shellEscape ).mockImplementation( v => v[ 0 ] ); | ||
} ); | ||
|
||
it( 'should resolve to true if version does not exist (npm >= 8.13.0 && npm < 10.0.0)', async () => { | ||
vi.mocked( tools ).shExec.mockRejectedValue( new Error( 'npm ERR! code E404' ) ); | ||
|
||
const result = await checkVersionAvailability( '1.0.1', 'stub-package' ); | ||
|
||
expect( vi.mocked( tools ).shExec ).toHaveBeenCalledExactlyOnceWith( 'npm show [email protected] version', expect.any( Object ) ); | ||
expect( result ).toBe( true ); | ||
} ); | ||
|
||
it( 'should resolve to true if version does not exist (npm >= 10.0.0)', async () => { | ||
vi.mocked( tools ).shExec.mockRejectedValue( new Error( 'npm error code E404' ) ); | ||
|
||
const result = await checkVersionAvailability( '1.0.1', 'stub-package' ); | ||
expect( vi.mocked( tools ).shExec ).toHaveBeenCalledExactlyOnceWith( 'npm show [email protected] version', expect.any( Object ) ); | ||
expect( result ).toBe( true ); | ||
} ); | ||
|
||
it( 'should resolve to true if version does not exist (npm < 8.13.0)', async () => { | ||
vi.mocked( tools ).shExec.mockResolvedValue( '' ); | ||
it( 'should resolve to true if version does not exist', async () => { | ||
vi.mocked( pacote.manifest ).mockRejectedValue( 'E404' ); | ||
|
||
await expect( checkVersionAvailability( '1.0.1', 'stub-package' ) ).resolves.toBe( true ); | ||
} ); | ||
|
||
expect( pacote.manifest ).toHaveBeenCalledExactlyOnceWith( '[email protected]' ); | ||
} ); | ||
it( 'should resolve to false if version exists', async () => { | ||
vi.mocked( tools ).shExec.mockResolvedValue( '1.0.1' ); | ||
pacote.manifest.mockResolvedValue( '1.0.1' ); | ||
|
||
await expect( checkVersionAvailability( '1.0.1', 'stub-package' ) ).resolves.toBe( false ); | ||
} ); | ||
|
||
it( 'should re-throw an error if unknown error occurred', async () => { | ||
vi.mocked( tools ).shExec.mockRejectedValue( new Error( 'Unknown error.' ) ); | ||
|
||
await expect( checkVersionAvailability( '1.0.1', 'stub-package' ) ) | ||
.rejects.toThrow( 'Unknown error.' ); | ||
} ); | ||
|
||
it( 'should escape arguments passed to a shell command', async () => { | ||
vi.mocked( tools ).shExec.mockRejectedValue( new Error( 'npm ERR! code E404' ) ); | ||
|
||
await checkVersionAvailability( '1.0.1', 'stub-package' ); | ||
expect( vi.mocked( shellEscape ) ).toHaveBeenCalledTimes( 2 ); | ||
expect( vi.mocked( shellEscape ) ).toHaveBeenCalledWith( [ 'stub-package' ] ); | ||
expect( vi.mocked( shellEscape ) ).toHaveBeenCalledWith( [ '1.0.1' ] ); | ||
} ); | ||
} ); |
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
Oops, something went wrong.