Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/hooks/tests/use-import-export.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ beforeEach( () => {
} );
( useSiteDetails as jest.Mock ).mockReturnValue( {
updateSite: jest.fn(),
startServer: jest.fn(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think if we add a new test or at least a new assert to check we called the startServer after an import?

Something like: expect( useSiteDetails().startServer ).toHaveBeenCalledTimes( 1 );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for testing and reviewing the PR, Antonio!

What do you think if we add a new test or at least a new assert to check we called the startServer after an import?
Something like: expect( useSiteDetails().startServer ).toHaveBeenCalledTimes( 1 );

I like the idea! I have made a change in cd93a5f and also added testing whether startServer was called with the correct site ID.

stopServer: jest.fn(),
} );
} );
Expand Down Expand Up @@ -219,6 +220,8 @@ describe( 'useImportExport hook', () => {
body: 'Import completed',
} )
);
expect( useSiteDetails().startServer ).toHaveBeenCalledTimes( 1 );
expect( useSiteDetails().startServer ).toHaveBeenCalledWith( SITE_ID );
} );

it( 'shows error message when import fails', async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/use-import-export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ export const ImportExportProvider = ( { children }: { children: React.ReactNode
} catch ( error ) {
await handleImportError( error );
} finally {
if ( wasSiteRunning ) {
await startServer( selectedSite.id );
}
await startServer( selectedSite.id );
}
},
[ importState, startServer, stopServer, updateSite ]
Expand Down