-
Notifications
You must be signed in to change notification settings - Fork 91
fix: change skia-canvas to github release #715
New issue
Have a question about this project? Sign up fo 8000 r 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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ describe('test/common/adapter/binary/GithubBinary.test.ts', () => { | |
beforeEach(async () => { | ||
binary = await app.getEggObject(GithubBinary); | ||
}); | ||
|
||
describe('fetch()', () => { | ||
it('should fetch root and subdir work', async () => { | ||
const response = await TestUtil.readJSONFile(TestUtil.getFixtures('electron-releases.json')); | ||
|
@@ -34,5 +35,60 @@ describe('test/common/adapter/binary/GithubBinary.test.ts', () => { | |
} | ||
// console.log(result.items); | ||
}); | ||
|
||
it('should fetch skia-canvas', async () => { | ||
const response = await TestUtil.readJSONFile(TestUtil.getFixtures('skia-canvas-releases.json')); | ||
app.mockHttpclient(/https:\/\/api\.github\.com\/repos\/samizdatco\/skia-canvas\/releases/, 'GET', { | ||
data: response, | ||
status: 200, | ||
}); | ||
let result = await binary.fetch('/', 'skia-canvas'); | ||
assert(result); | ||
assert(result.items.length > 0); | ||
// console.log(JSON.stringify(result.items, null, 2)); | ||
let matchDir = false; | ||
for (const item of result.items) { | ||
assert(item.isDir === true); | ||
if (item.name === 'v0.9.30/') { | ||
matchDir = true; | ||
} | ||
} | ||
assert(matchDir); | ||
|
||
result = await binary.fetch('/v0.9.24/', 'skia-canvas'); | ||
assert(result?.items.every(item => !/{.*}/.test(item.url))); | ||
|
||
result = await binary.fetch('/v0.9.30/', 'skia-canvas'); | ||
assert(result); | ||
assert(result.items.length > 0); | ||
console.log(JSON.stringify(result.items, null, 2)); | ||
let matchFile1 = false; | ||
let matchFile2 = false; | ||
let matchFile3 = false; | ||
for (const item of result.items) { | ||
assert(item.isDir === false); | ||
if (item.name === 'skia-canvas-v0.9.30-darwin-arm64.tar.gz') { | ||
assert(item.date === '2024-08-26T18:04:13Z'); | ||
assert(item.size === 7547563); | ||
assert.equal(item.url, 'https://github.com/samizdatco/skia-canvas/releases/download/v0.9.30/skia-canvas-v0.9.30-darwin-arm64.tar.gz'); | ||
matchFile1 = true; | ||
} | ||
if (item.name === 'skia-canvas-v0.9.30-linux-arm-glibc.tar.gz') { | ||
assert(item.date === '2024-08-26T18:04:17Z'); | ||
assert(item.size === 8836353); | ||
assert.equal(item.url, 'https://github.com/samizdatco/skia-canvas/releases/download/v0.9.30/skia-canvas-v0.9.30-linux-arm-glibc.tar.gz'); | ||
matchFile2 = true; | ||
} | ||
if (item.name === 'skia-canvas-v0.9.30-win32-x64.tar.gz') { | ||
assert(item.date === '2024-08-26T18:04:29Z'); | ||
assert(item.size === 7497076); | ||
assert.equal(item.url, 'https://github.com/samizdatco/skia-canvas/releases/download/v0.9.30/skia-canvas-v0.9.30-win32-x64.tar.gz'); | ||
matchFile3 = true; | ||
} | ||
} | ||
assert(matchFile1); | ||
assert(matchFile2); | ||
assert(matchFile3); | ||
Comment on lines
+58
to
+91
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. 🛠️ Refactor suggestion Improve test efficiency and remove console logging The test case for fetching specific version data is thorough, but there are a few areas for improvement:
Consider the following improvements:
// Ensure that item URLs don't contain curly braces, which could indicate an unresolved template
assert(result?.items.every(item => !/{.*}/.test(item.url)));
const files = [
{
name: 'skia-canvas-v0.9.30-darwin-arm64.tar.gz',
date: '2024-08-26T18:04:13Z',
size: 7547563,
url: 'https://github.com/samizdatco/skia-canvas/releases/download/v0.9.30/skia-canvas-v0.9.30-darwin-arm64.tar.gz'
},
// ... add other files here
];
files.forEach(expectedFile => {
const file = result.items.find(item => item.name === expectedFile.name);
assert(file, `File ${expectedFile.name} not found`);
assert.equal(file.date, expectedFile.date);
assert.equal(file.size, expectedFile.size);
assert.equal(file.url, expectedFile.url);
});
Remove the console.log statement on line 64 before merging to production. |
||
}); | ||
}); | ||
}); |
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.
🛠️ Refactor suggestion
Consider using
Array.prototype.some()
for more efficient directory checkingWhile the current implementation works, we can improve its efficiency and readability by using
Array.prototype.some()
instead of a loop with a flag.Consider refactoring the directory check as follows:
This change will make the code more concise and potentially more efficient, as it can short-circuit once a match is found.
📝 Committable suggestion