-
Notifications
You must be signed in to change notification settings - Fork 67
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 #2 from calibreapp/overall-metrics
Add overall metrics for processing
- Loading branch information
Showing
15 changed files
with
4,912 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
workflow "Test" { | ||
on = "push" | ||
resolves = ["npm test"] | ||
} | ||
|
||
action "npm ci" { | ||
uses = "./" | ||
runs = "npm" | ||
args = "ci" | ||
} | ||
|
||
action "npm test" { | ||
needs = "npm ci" | ||
uses = "./" | ||
runs = "npm" | ||
args = "test" | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const results = { | ||
images: [ | ||
{ | ||
name: "icon.png", | ||
path: "__tests__/test-images/icon.png", | ||
beforeStats: 8914, | ||
afterStats: 3361, | ||
percentChange: -62.29526587390622, | ||
compressionWasSignificant: true | ||
}, | ||
{ | ||
name: "optimised-image.png", | ||
path: "__tests__/test-images/optimised-image.png", | ||
beforeStats: 3361, | ||
afterStats: 3361, | ||
percentChange: 0, | ||
compressionWasSignificant: false | ||
}, | ||
{ | ||
name: "roo.jpg", | ||
path: "__tests__/test-images/roo.jpg", | ||
beforeStats: 468895, | ||
afterStats: 485742, | ||
percentChange: 3.592915258213452, | ||
compressionWasSignificant: false | ||
} | ||
], | ||
metrics: { | ||
bytesSaved: 5553, | ||
percentChange: -62.29526587390622 | ||
} | ||
}; | ||
|
||
const markdown = require("../src/github-markdown"); | ||
|
||
const referenceMarkdown = ` | ||
Images automagically compressed by [Calibre](https://calibreapp.com)'s [image-actions](https://github.com/marketplace/actions/image-actions) ✨ | ||
Compression reduced images by 62.3%, saving 5.42 KB | ||
| Filename | Before | After | Improvement | | ||
| --- | --- | --- | --- | | ||
| \`icon.png\` | 8.71 KB | 3.28 KB | -62.3% | | ||
<details> | ||
<summary>Some images were already optimised</summary> | ||
* \`optimised-image.png\` | ||
* \`roo.jpg\` | ||
</details>`; | ||
|
||
test("writes the markdown", async () => { | ||
const markdownResult = await markdown(results); | ||
expect(markdownResult).toEqual(referenceMarkdown); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const path = require("path"); | ||
const fs = require("fs").promises; | ||
|
||
const EXAMPLE_IMAGES_DIR = `${process.cwd()}/__tests__/example-images`; | ||
const TMP_TEST_IMAGES_DIR = `${process.cwd()}/__tests__/test-images`; | ||
|
||
const EXAMPLE_IMAGES = ["roo.jpg", "icon.png", "optimised-image.png"]; | ||
|
||
beforeEach(async () => { | ||
await fs.mkdir(TMP_TEST_IMAGES_DIR); | ||
|
||
// Copy in reference images for stats | ||
for await (const image of EXAMPLE_IMAGES) { | ||
await fs.copyFile( | ||
path.join(EXAMPLE_IMAGES_DIR, image), | ||
path.join(TMP_TEST_IMAGES_DIR, image) | ||
); | ||
} | ||
}); | ||
|
||
afterEach(async () => { | ||
for await (const image of EXAMPLE_IMAGES) { | ||
await fs.unlink(path.join(TMP_TEST_IMAGES_DIR, image)); | ||
} | ||
await fs.rmdir(TMP_TEST_IMAGES_DIR); | ||
}); | ||
|
||
const imageProcessing = require("../src/image-processing"); | ||
|
||
test("returns metrics for images", async () => { | ||
const results = await imageProcessing(); | ||
|
||
expect(results.metrics).toEqual({ | ||
bytesSaved: 5553, | ||
percentChange: -62.29526587390622 | ||
}); | ||
}); | ||
|
||
test("returns images with stats", async () => { | ||
const results = await imageProcessing(); | ||
|
||
expect(results.images).toEqual([ | ||
{ | ||
afterStats: 3361, | ||
beforeStats: 8914, | ||
compressionWasSignificant: true, | ||
name: "icon.png", | ||
path: "__tests__/test-images/icon.png", | ||
percentChange: -62.29526587390622 | ||
}, | ||
{ | ||
afterStats: 3361, | ||
beforeStats: 3361, | ||
compressionWasSignificant: false, | ||
name: "optimised-image.png", | ||
path: "__tests__/test-images/optimised-image.png", | ||
percentChange: 0 | ||
}, | ||
{ | ||
afterStats: 485759, | ||
beforeStats: 468895, | ||
compressionWasSignificant: false, | ||
name: "roo.jpg", | ||
path: "__tests__/test-images/roo.jpg", | ||
percentChange: 3.596540803378147 | ||
} | ||
]); | ||
}); |
This file was deleted.
Oops, something went wrong.
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.