-
Notifications
You must be signed in to change notification settings - Fork 66
Remove getSiteFiles function to simplify and speed up the export process #1457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sejas
merged 14 commits into
trunk
from
update/STU-536-remove-get-site-files-function-and-speed-up-export
Jun 4, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0941617
Start refactoring can handle
sejas 0c959ce
add tests
sejas 499aae4
skipped temporarly some tests
sejas ecccfd0
Undo tests to make easier the merge
sejas 451a5aa
Merge branch 'trunk' of github.com:Automattic/studio into update/STU-…
sejas 848f1fd
Remove wpContent list of files object and type
sejas 3ada796
Simplify the logic to include wp-config.php file
sejas 55a9772
Remove getBackupContents
sejas 8de7e19
Update tests
sejas d748f48
add test case to check if wp-config.php file doesn't exist
sejas e31c840
Remove unnecessary siteFiles and the second initialization of this.ba…
sejas c9b99a1
Remove unecessary type
sejas aa24b1f
add test case to check backup internal object
sejas 4feba4c
Update test to affect less tests
sejas 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
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -134,17 +134,30 @@ platformTestSuite( 'DefaultExporter', ( { normalize } ) => { | |
|
|
||
| ( fsPromises.readdir as jest.Mock ).mockResolvedValue( mockFiles ); | ||
|
|
||
| // Mock fsPromises.stat for canHandle method | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about cleaning up these comments as they seem self-explanatory? |
||
| ( fsPromises.stat as jest.Mock ).mockImplementation( async ( filePath: string ) => { | ||
| const normalizedPath = normalize( filePath ); | ||
| if ( normalizedPath.endsWith( 'wp-content' ) || normalizedPath.endsWith( 'wp-includes' ) ) { | ||
| return { isDirectory: () => true, isFile: () => false }; | ||
| } | ||
| if ( | ||
| normalizedPath.endsWith( 'wp-load.php' ) || | ||
| normalizedPath.endsWith( 'wp-config.php' ) | ||
| ) { | ||
| return { isDirectory: () => false, isFile: () => true }; | ||
| } | ||
| throw new Error( 'File not found' ); | ||
| } ); | ||
|
|
||
| // Mock fs.existsSync for addWpConfig method | ||
| ( fs.existsSync as jest.Mock ).mockImplementation( ( filePath: string ) => { | ||
| const normalizedPath = normalize( filePath ); | ||
| return normalizedPath.endsWith( 'wp-config.php' ); | ||
| } ); | ||
|
|
||
| mockBackup = { | ||
| backupFile: normalize( '/path/to/backup.tar.gz' ), | ||
| wpConfigFile: normalize( '/path/to/wp-config.php' ), | ||
| sqlFiles: [ normalize( '/tmp/studio_export_123/file.sql' ) ], | ||
| wpContent: { | ||
| uploads: [ normalize( '/path/to/wp-content/uploads/file1.jpg' ) ], | ||
| plugins: [ normalize( '/path/to/wp-content/plugins/plugin1' ) ], | ||
| themes: [ normalize( '/path/to/wp-content/themes/theme1' ) ], | ||
| muPlugins: [ normalize( '/path/to/wp-content/mu-plugins/custom-mu-plugin.php' ) ], | ||
| fonts: [ normalize( '/path/to/wp-content/fonts/custom-font.woff2' ) ], | ||
| }, | ||
| }; | ||
|
|
||
| mockOptions = { | ||
|
|
@@ -247,9 +260,17 @@ platformTestSuite( 'DefaultExporter', ( { normalize } ) => { | |
| const exporter = new DefaultExporter( options ); | ||
| await exporter.export(); | ||
|
|
||
| expect( mockArchiver.file ).toHaveBeenCalledWith( normalize( '/path/to/site/wp-config.php' ), { | ||
| name: 'wp-config.php', | ||
| } ); | ||
| // wp-config.php should be called first, then meta.json | ||
| expect( mockArchiver.file ).toHaveBeenNthCalledWith( | ||
| 1, | ||
| normalize( '/path/to/site/wp-config.php' ), | ||
| { name: 'wp-config.php' } | ||
| ); | ||
| expect( mockArchiver.file ).toHaveBeenNthCalledWith( | ||
| 2, | ||
| normalize( '/tmp/studio_export_123/meta.json' ), | ||
| { name: 'meta.json' } | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'should add meta.json to the archive', async () => { | ||
|
|
@@ -281,12 +302,19 @@ platformTestSuite( 'DefaultExporter', ( { normalize } ) => { | |
|
|
||
| const exporter = new DefaultExporter( options ); | ||
| await exporter.export(); | ||
| // Check each expected call individually | ||
|
|
||
| // Check that wp-config.php and meta.json are both added | ||
| expect( mockArchiver.file ).toHaveBeenNthCalledWith( | ||
| 1, | ||
| normalize( '/path/to/site/wp-config.php' ), | ||
| { name: 'wp-config.php' } | ||
| ); | ||
| expect( mockArchiver.file ).toHaveBeenNthCalledWith( | ||
| 2, | ||
| normalize( '/tmp/studio_export_123/meta.json' ), | ||
| { name: 'meta.json' } | ||
| ); | ||
|
|
||
| expect( mockArchiver.directory ).toHaveBeenNthCalledWith( | ||
| 1, | ||
| normalize( '/path/to/site/wp-content/uploads' ), | ||
|
|
@@ -334,6 +362,11 @@ platformTestSuite( 'DefaultExporter', ( { normalize } ) => { | |
| normalize( '/path/to/site/wp-config.php' ), | ||
| { name: 'wp-config.php' } | ||
| ); | ||
| expect( mockArchiver.file ).toHaveBeenNthCalledWith( | ||
| 2, | ||
| normalize( '/tmp/studio_export_123/meta.json' ), | ||
| { name: 'meta.json' } | ||
| ); | ||
| expect( mockArchiver.directory ).toHaveBeenNthCalledWith( | ||
| 1, | ||
| normalize( '/path/to/site/wp-content/mu-plugins' ), | ||
|
|
@@ -369,6 +402,11 @@ platformTestSuite( 'DefaultExporter', ( { normalize } ) => { | |
| normalize( '/tmp/studio_export_123/studio-backup-db-export-2023-07-31-12-00-00.sql' ), | ||
| { name: 'sql/studio-backup-db-export-2023-07-31-12-00-00.sql' } | ||
| ); | ||
| expect( mockArchiver.file ).toHaveBeenNthCalledWith( | ||
| 3, | ||
| normalize( '/tmp/studio_export_123/meta.json' ), | ||
| { name: 'meta.json' } | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'should add a multiple SQL dumps to the archive when `splitDatabaseDumpByTable` is true', async () => { | ||
|
|
@@ -401,6 +439,12 @@ platformTestSuite( 'DefaultExporter', ( { normalize } ) => { | |
| { name: `sql/${ tableName }.sql` } | ||
| ); | ||
| } | ||
|
|
||
| expect( mockArchiver.file ).toHaveBeenNthCalledWith( | ||
| defaultTableNames.length + 2, | ||
| normalize( '/tmp/studio_export_123/meta.json' ), | ||
| { name: 'meta.json' } | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'should finalize the archive', async () => { | ||
|
|
@@ -486,11 +530,62 @@ platformTestSuite( 'DefaultExporter', ( { normalize } ) => { | |
| normalize( '/path/to/site/wp-config.php' ), | ||
| { name: 'wp-config.php' } | ||
| ); | ||
| expect( mockArchiver.file ).toHaveBeenNthCalledWith( | ||
| 2, | ||
| normalize( '/tmp/studio_export_123/meta.json' ), | ||
| { name: 'meta.json' } | ||
| ); | ||
| expect( mockArchiver.directory ).toHaveBeenNthCalledWith( | ||
| 1, | ||
| normalize( '/path/to/site/wp-content/fonts' ), | ||
| normalize( 'wp-content/fonts' ), | ||
| expect.any( Function ) | ||
| ); | ||
| } ); | ||
|
|
||
| it( "should not add wp-config if it doesn't exists", async () => { | ||
| ( fs.existsSync as jest.Mock ).mockImplementation( ( filePath: string ) => { | ||
| const normalizedPath = normalize( filePath ); | ||
| return ! normalizedPath.endsWith( 'wp-config.php' ); | ||
| } ); | ||
|
|
||
| await exporter.export(); | ||
|
|
||
| expect( mockArchiver.file ).not.toHaveBeenCalledWith( | ||
| normalize( '/path/to/site/wp-config.php' ), | ||
| { name: 'wp-config.php' } | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'should initialize backup object with correct structure when creating a new exporter', () => { | ||
| const testOptions: ExportOptions = { | ||
| site: { | ||
| running: false, | ||
| id: 'test-site', | ||
| name: 'Test Site', | ||
| path: normalize( '/path/to/test/site' ), | ||
| port: 8080, | ||
| phpVersion: '8.3', | ||
| }, | ||
| backupFile: normalize( '/path/to/test-backup.tar.gz' ), | ||
| includes: { | ||
| uploads: true, | ||
| plugins: true, | ||
| themes: true, | ||
| database: true, | ||
| muPlugins: true, | ||
| fonts: true, | ||
| }, | ||
| phpVersion: '8.4', | ||
| }; | ||
|
|
||
| const testExporter = new DefaultExporter( testOptions ); | ||
|
|
||
| const { backup } = testExporter as unknown as { backup: BackupContents }; | ||
|
|
||
| expect( backup ).toEqual( { | ||
| backupFile: normalize( '/path/to/test-backup.tar.gz' ), | ||
| sqlFiles: [], | ||
| } ); | ||
| } ); | ||
| } ); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love it!

😄