|
|
@@ -23,109 +23,150 @@ describe( 'dev-install', () => {
|
|
|
const workspaceAbsolutePath = path.join( ckeditor5Path, workspacePath );
|
|
|
|
|
|
let toRestore;
|
|
|
- beforeEach( () => toRestore = [] );
|
|
|
+ const spies = {};
|
|
|
+
|
|
|
+ beforeEach( () => {
|
|
|
+ toRestore = [];
|
|
|
+
|
|
|
+ spies.parseUrl = sinon.spy( git, 'parseRepositoryUrl' );
|
|
|
+ spies.isDirectory = sinon.stub( tools, 'isDirectory' );
|
|
|
+ spies.cloneRepository = sinon.stub( git, 'cloneRepository' );
|
|
|
+ spies.linkDirectories = sinon.stub( tools, 'linkDirectories' );
|
|
|
+ spies.updateJSON = sinon.stub( tools, 'updateJSONFile' );
|
|
|
+ spies.npmInstall = sinon.stub( tools, 'npmInstall' );
|
|
|
+ spies.checkout = sinon.stub( git, 'checkout' );
|
|
|
+ spies.getGitUrlFromNpm = sinon.stub( tools, 'getGitUrlFromNpm' );
|
|
|
+ spies.readPackageName = sinon.stub( tools, 'readPackageName' );
|
|
|
+ } );
|
|
|
|
|
|
afterEach( () => {
|
|
|
toRestore.forEach( item => item.restore() );
|
|
|
+ Object.keys( spies ).forEach( ( spy ) => spies[ spy ].restore() );
|
|
|
} );
|
|
|
|
|
|
- it( 'should use GitHub url if provided', () => {
|
|
|
- const parseUrlSpy = sinon.spy( git, 'parseRepositoryUrl' );
|
|
|
- const isDirectoryStub = sinon.stub( tools, 'isDirectory' ).returns( false );
|
|
|
- const cloneRepositoryStub = sinon.stub( git, 'cloneRepository' );
|
|
|
- const linkDirectoriesStub = sinon.stub( tools, 'linkDirectories' );
|
|
|
- const updateJSONstub = sinon.stub( tools, 'updateJSONFile' );
|
|
|
- const npmInstallStub = sinon.stub( tools, 'npmInstall' );
|
|
|
- const checkoutStub = sinon.stub( git, 'checkout' );
|
|
|
-
|
|
|
- toRestore.push( parseUrlSpy, isDirectoryStub, cloneRepositoryStub, linkDirectoriesStub, updateJSONstub,
|
|
|
- npmInstallStub, checkoutStub );
|
|
|
+ it( 'should use GitHub URL', () => {
|
|
|
+ spies.isDirectory.onFirstCall().returns( false );
|
|
|
+ spies.isDirectory.onSecondCall().returns( false );
|
|
|
|
|
|
- installTask( ckeditor5Path, workspacePath, repositoryUrl, () => {}, () => {} );
|
|
|
+ installTask( ckeditor5Path, workspacePath, repositoryUrl, () => {} );
|
|
|
|
|
|
- sinon.assert.calledOnce( parseUrlSpy );
|
|
|
- sinon.assert.calledWithExactly( parseUrlSpy, repositoryUrl );
|
|
|
+ sinon.assert.calledTwice( spies.isDirectory );
|
|
|
+ sinon.assert.calledOnce( spies.parseUrl );
|
|
|
+ sinon.assert.calledWithExactly( spies.parseUrl, repositoryUrl );
|
|
|
|
|
|
- const urlInfo = parseUrlSpy.firstCall.returnValue;
|
|
|
+ const urlInfo = spies.parseUrl.firstCall.returnValue;
|
|
|
const repositoryPath = path.join( workspaceAbsolutePath, urlInfo.name );
|
|
|
|
|
|
- sinon.assert.calledOnce( isDirectoryStub );
|
|
|
- sinon.assert.calledWithExactly( isDirectoryStub, repositoryPath );
|
|
|
+ sinon.assert.calledWithExactly( spies.isDirectory.secondCall, repositoryPath );
|
|
|
+ sinon.assert.calledOnce( spies.cloneRepository );
|
|
|
+ sinon.assert.calledWithExactly( spies.cloneRepository, urlInfo, workspaceAbsolutePath );
|
|
|
+ sinon.assert.calledOnce( spies.checkout );
|
|
|
+ sinon.assert.calledWithExactly( spies.checkout, repositoryPath, urlInfo.branch );
|
|
|
+
|
|
|
+ const linkPath = path.join( ckeditor5Path, 'node_modules', urlInfo.name );
|
|
|
+
|
|
|
+ sinon.assert.calledOnce( spies.linkDirectories );
|
|
|
+ sinon.assert.calledWithExactly( spies.linkDirectories, repositoryPath, linkPath );
|
|
|
+
|
|
|
+ const packageJsonPath = path.join( ckeditor5Path, 'package.json' );
|
|
|
|
|
|
- sinon.assert.calledOnce( cloneRepositoryStub );
|
|
|
- sinon.assert.calledWithExactly( cloneRepositoryStub, urlInfo, workspaceAbsolutePath );
|
|
|
+ sinon.assert.calledOnce( spies.updateJSON );
|
|
|
+ expect( spies.updateJSON.firstCall.args[ 0 ] ).to.equal( packageJsonPath );
|
|
|
+ const updateFn = spies.updateJSON.firstCall.args[ 1 ];
|
|
|
+ const json = updateFn( {} );
|
|
|
+ expect( json.dependencies ).to.be.a( 'object' );
|
|
|
+ expect( json.dependencies[ urlInfo.name ] ).to.equal( repositoryPath );
|
|
|
|
|
|
- sinon.assert.calledOnce( checkoutStub );
|
|
|
- sinon.assert.calledWithExactly( checkoutStub, repositoryPath, urlInfo.branch );
|
|
|
+ sinon.assert.calledOnce( spies.npmInstall );
|
|
|
+ sinon.assert.calledWithExactly( spies.npmInstall, ckeditor5Path );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should use npm module name', () => {
|
|
|
+ spies.isDirectory.onFirstCall().returns( false );
|
|
|
+ spies.isDirectory.onSecondCall().returns( true );
|
|
|
+ spies.getGitUrlFromNpm.returns( repositoryUrl );
|
|
|
+
|
|
|
+ installTask( ckeditor5Path, workspacePath, moduleName, () => {} );
|
|
|
+
|
|
|
+ sinon.assert.calledTwice( spies.isDirectory );
|
|
|
+ sinon.assert.calledTwice( spies.parseUrl );
|
|
|
+ sinon.assert.calledWithExactly( spies.parseUrl.firstCall, moduleName );
|
|
|
+ expect( spies.parseUrl.firstCall.returnValue ).to.equal( null );
|
|
|
+ sinon.assert.calledOnce( spies.getGitUrlFromNpm );
|
|
|
+ sinon.assert.calledWithExactly( spies.getGitUrlFromNpm, moduleName );
|
|
|
+ sinon.assert.calledWithExactly( spies.parseUrl.secondCall, repositoryUrl );
|
|
|
+ const urlInfo = spies.parseUrl.secondCall.returnValue;
|
|
|
+ const repositoryPath = path.join( workspaceAbsolutePath, urlInfo.name );
|
|
|
+
|
|
|
+ sinon.assert.calledWithExactly( spies.isDirectory.secondCall, repositoryPath );
|
|
|
+ sinon.assert.notCalled( spies.cloneRepository );
|
|
|
+ sinon.assert.calledOnce( spies.checkout );
|
|
|
+ sinon.assert.calledWithExactly( spies.checkout, repositoryPath, urlInfo.branch );
|
|
|
|
|
|
const linkPath = path.join( ckeditor5Path, 'node_modules', urlInfo.name );
|
|
|
|
|
|
- sinon.assert.calledOnce( linkDirectoriesStub );
|
|
|
- sinon.assert.calledWithExactly( linkDirectoriesStub, repositoryPath, linkPath );
|
|
|
+ sinon.assert.calledOnce( spies.linkDirectories );
|
|
|
+ sinon.assert.calledWithExactly( spies.linkDirectories, repositoryPath, linkPath );
|
|
|
|
|
|
const packageJsonPath = path.join( ckeditor5Path, 'package.json' );
|
|
|
- sinon.assert.calledOnce( updateJSONstub );
|
|
|
- expect( updateJSONstub.firstCall.args[ 0 ] ).to.equal( packageJsonPath );
|
|
|
- const updateFn = updateJSONstub.firstCall.args[ 1 ];
|
|
|
+
|
|
|
+ sinon.assert.calledOnce( spies.updateJSON );
|
|
|
+ expect( spies.updateJSON.firstCall.args[ 0 ] ).to.equal( packageJsonPath );
|
|
|
+ const updateFn = spies.updateJSON.firstCall.args[ 1 ];
|
|
|
const json = updateFn( {} );
|
|
|
expect( json.dependencies ).to.be.a( 'object' );
|
|
|
expect( json.dependencies[ urlInfo.name ] ).to.equal( repositoryPath );
|
|
|
|
|
|
- sinon.assert.calledOnce( npmInstallStub );
|
|
|
- sinon.assert.calledWithExactly( npmInstallStub, ckeditor5Path );
|
|
|
+ sinon.assert.calledOnce( spies.npmInstall );
|
|
|
+ sinon.assert.calledWithExactly( spies.npmInstall, ckeditor5Path );
|
|
|
} );
|
|
|
|
|
|
- it( 'should use npm module name if provided', () => {
|
|
|
- const parseUrlSpy = sinon.spy( git, 'parseRepositoryUrl' );
|
|
|
- const isDirectoryStub = sinon.stub( tools, 'isDirectory' ).returns( true );
|
|
|
- const getUrlFromNpmSpy = sinon.stub( tools, 'getGitUrlFromNpm' ).returns( repositoryUrl );
|
|
|
- const cloneRepositoryStub = sinon.stub( git, 'cloneRepository' );
|
|
|
- const linkDirectoriesStub = sinon.stub( tools, 'linkDirectories' );
|
|
|
- const updateJSONstub = sinon.stub( tools, 'updateJSONFile' );
|
|
|
- const npmInstallStub = sinon.stub( tools, 'npmInstall' );
|
|
|
- const checkoutStub = sinon.stub( git, 'checkout' );
|
|
|
+ it( 'should use local relative path', () => {
|
|
|
+ spies.isDirectory.onFirstCall().returns( true );
|
|
|
+ spies.isDirectory.onSecondCall().returns( true );
|
|
|
+ spies.readPackageName.returns( moduleName );
|
|
|
|
|
|
- toRestore.push( parseUrlSpy, isDirectoryStub, getUrlFromNpmSpy, cloneRepositoryStub, linkDirectoriesStub,
|
|
|
- updateJSONstub, npmInstallStub, checkoutStub );
|
|
|
+ installTask( ckeditor5Path, workspacePath, '../ckeditor5-core', () => {} );
|
|
|
|
|
|
- installTask( ckeditor5Path, workspacePath, moduleName, () => {}, () => {} );
|
|
|
+ sinon.assert.calledTwice( spies.isDirectory );
|
|
|
+ sinon.assert.calledOnce( spies.readPackageName );
|
|
|
+ } );
|
|
|
|
|
|
- sinon.assert.calledTwice( parseUrlSpy );
|
|
|
- sinon.assert.calledWithExactly( parseUrlSpy.firstCall, moduleName );
|
|
|
- expect( parseUrlSpy.firstCall.returnValue ).to.equal( null );
|
|
|
+ it( 'should use local absolute path if provided', () => {
|
|
|
+ spies.isDirectory.onFirstCall().returns( true );
|
|
|
+ spies.isDirectory.onSecondCall().returns( true );
|
|
|
+ spies.readPackageName.returns( moduleName );
|
|
|
|
|
|
- sinon.assert.calledOnce( getUrlFromNpmSpy );
|
|
|
- sinon.assert.calledWithExactly( getUrlFromNpmSpy, moduleName );
|
|
|
+ installTask( ckeditor5Path, workspacePath, '/ckeditor5-core', () => {} );
|
|
|
|
|
|
- sinon.assert.calledWithExactly( parseUrlSpy.secondCall, repositoryUrl );
|
|
|
- const urlInfo = parseUrlSpy.secondCall.returnValue;
|
|
|
- const repositoryPath = path.join( workspaceAbsolutePath, urlInfo.name );
|
|
|
+ sinon.assert.calledTwice( spies.isDirectory );
|
|
|
+ sinon.assert.calledOnce( spies.readPackageName );
|
|
|
+ } );
|
|
|
|
|
|
- sinon.assert.calledOnce( isDirectoryStub );
|
|
|
- sinon.assert.calledWithExactly( isDirectoryStub, repositoryPath );
|
|
|
+ it( 'should throw an exception when invalid name is provided', () => {
|
|
|
+ spies.isDirectory.onFirstCall().returns( false );
|
|
|
+ spies.isDirectory.onSecondCall().returns( true );
|
|
|
|
|
|
- sinon.assert.notCalled( cloneRepositoryStub );
|
|
|
+ expect( () => {
|
|
|
+ installTask( ckeditor5Path, workspacePath, moduleName, () => {} );
|
|
|
+ } ).to.throw();
|
|
|
+
|
|
|
+ sinon.assert.calledOnce( spies.parseUrl );
|
|
|
+ sinon.assert.calledWithExactly( spies.parseUrl.firstCall, moduleName );
|
|
|
+ expect( spies.parseUrl.firstCall.returnValue ).to.equal( null );
|
|
|
} );
|
|
|
|
|
|
- it( 'should throw an exception when invalid name is provided', () => {
|
|
|
- const parseUrlSpy = sinon.spy( git, 'parseRepositoryUrl' );
|
|
|
- const isDirectoryStub = sinon.stub( tools, 'isDirectory' ).returns( true );
|
|
|
- const getUrlFromNpmSpy = sinon.stub( tools, 'getGitUrlFromNpm' ).returns( null );
|
|
|
- const cloneRepositoryStub = sinon.stub( git, 'cloneRepository' );
|
|
|
- const linkDirectoriesStub = sinon.stub( tools, 'linkDirectories' );
|
|
|
- const updateJSONstub = sinon.stub( tools, 'updateJSONFile' );
|
|
|
- const npmInstallStub = sinon.stub( tools, 'npmInstall' );
|
|
|
- const checkoutStub = sinon.stub( git, 'checkout' );
|
|
|
-
|
|
|
- toRestore.push( parseUrlSpy, isDirectoryStub, getUrlFromNpmSpy, cloneRepositoryStub, linkDirectoriesStub,
|
|
|
- updateJSONstub, npmInstallStub, checkoutStub );
|
|
|
+ it( 'should throw an exception when package.json is not present', () => {
|
|
|
+ spies.isDirectory.onFirstCall().returns( true );
|
|
|
+ spies.isDirectory.onSecondCall().returns( true );
|
|
|
+ spies.readPackageName.returns( null );
|
|
|
|
|
|
expect( () => {
|
|
|
- installTask( ckeditor5Path, workspacePath, moduleName, () => {}, () => {} );
|
|
|
+ installTask( ckeditor5Path, workspacePath, moduleName, () => {} );
|
|
|
} ).to.throw();
|
|
|
|
|
|
- sinon.assert.calledOnce( parseUrlSpy );
|
|
|
- sinon.assert.calledWithExactly( parseUrlSpy.firstCall, moduleName );
|
|
|
- expect( parseUrlSpy.firstCall.returnValue ).to.equal( null );
|
|
|
+ sinon.assert.calledOnce( spies.parseUrl );
|
|
|
+ sinon.assert.calledWithExactly( spies.parseUrl.firstCall, moduleName );
|
|
|
+ expect( spies.parseUrl.firstCall.returnValue ).to.equal( null );
|
|
|
} );
|
|
|
} );
|