-
Notifications
You must be signed in to change notification settings - Fork 13
Added ability for an inner folder name of a zip to be specified. #17
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
Open
jeesonjohnson
wants to merge
1
commit into
jsantell:master
Choose a base branch
from
jeesonjohnson:adding_inner_folder_names
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
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
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 |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ var xpiPath = path.join(__dirname, "my.xpi"); | |
| var outputPath = path.join(__dirname, "myxpi/"); | ||
| var emptyDirPath = path.join(sampleZipPath, "emptyDir"); | ||
| var emptyDirOutputPath = path.join(outputPath, "emptyDir"); | ||
| const innerFolderName = "exampleOfAnInnerFolderName"; | ||
|
|
||
| describe("zip-dir", function () { | ||
| describe("creates a zip buffer", function () { | ||
|
|
@@ -99,6 +100,86 @@ describe("zip-dir", function () { | |
| }); | ||
| }); | ||
|
|
||
| describe("Ensures that inner folder names can be defined", function () { | ||
| afterEach(cleanUp); | ||
|
|
||
| function customCompareMethod(file, customFilePath = "", combineCustomFilePathOrReplace = true) { | ||
| const zipBuffer = fs.readFileSync(path.join(sampleZipPath, file)); | ||
| const combinedFilePath = path.join(customFilePath, file); | ||
| // Compare the different file buffers. | ||
| const fileBuffer = fs.readFileSync( | ||
| path.join( | ||
| outputPath, | ||
| combineCustomFilePathOrReplace ? combinedFilePath : customFilePath | ||
| ) | ||
| ); | ||
|
|
||
| expect(bufferEqual(zipBuffer, fileBuffer)).to.be.ok; | ||
| } | ||
|
|
||
| //Had to do the below, since otherwise the file did not zip in enough time. | ||
| function customZippingFunction(options, customFilePath) { | ||
| return new Promise((resolve, reject) => { | ||
| zipDir( | ||
| customFilePath || sampleZipPath, | ||
| options, | ||
| async function (err, buffer) { | ||
| if (err) { | ||
| reject(err); | ||
| return; | ||
| } | ||
| await fs | ||
| .createReadStream(xpiPath) | ||
| .pipe(unzip.Extract({ path: outputPath })) | ||
| .on("entry", (entry) => entry.autodrain()) | ||
| .promise() | ||
| .then(() => resolve()) | ||
| .catch(e=>reject(e)); | ||
| } | ||
| ); | ||
| }); | ||
| } | ||
|
Comment on lines
+120
to
+141
Author
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. Had to wrap the zipping command into its own promise since it was being flaky when running tests, since the zipping often took way too long, and zipDir cannot directly be awaited. |
||
|
|
||
| it("Ensure inner folder name is not changed unless specified ", function (done) { | ||
| zipAndUnzip({ saveTo: xpiPath }, function () { | ||
| var files = [ | ||
| "file1.json", | ||
| "tiny.gif", | ||
| "dir/file2.json", | ||
| "dir/file3.json", | ||
| "dir/deepDir/deeperDir/file4.json", | ||
| ]; | ||
| files.forEach((file) => customCompareMethod(file)); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it("Ensure that with multiple files the inner folder name is changed.", function (done) { | ||
| zipAndUnzip({ saveTo: xpiPath, innerFolderName }, function () { | ||
| var files = [ | ||
| "file1.json", | ||
| "tiny.gif", | ||
| "dir/file2.json", | ||
| "dir/file3.json", | ||
| "dir/deepDir/deeperDir/file4.json", | ||
| ]; | ||
| files.forEach((file) => customCompareMethod(file, innerFolderName)); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it("compresses and unpacks and all files into ", async function () { | ||
| const fileFolderPath = "dir/deepDir/deeperDir"; | ||
|
|
||
| const singleFileToBeZipped = path.join(sampleZipPath, fileFolderPath); | ||
| addEmpty(await customZippingFunction({ saveTo: xpiPath, innerFolderName },singleFileToBeZipped)); | ||
|
|
||
| const fileName = "file4.json"; | ||
| const fileToBeZippedPath = path.join(fileFolderPath, fileName); | ||
| const fileToBeComparedTo = path.join(innerFolderName, fileName); | ||
| customCompareMethod(fileToBeZippedPath, fileToBeComparedTo, false); | ||
| }); | ||
| }); | ||
| describe("uses `filter` to select items", function () { | ||
| afterEach(cleanUp); | ||
|
|
||
|
|
||
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 can move the this function to the global def, but thought i would ask before changing the other aspects. :)