Files
OpenNoodl/packages/noodl-editor/tests/git/git-clone-and-fetch-remote.spec.ts
Michael Cartner b9c60b07dc Initial commit
Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com>
Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com>
Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com>
Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com>
Co-Authored-By: Johan  <4934465+joolsus@users.noreply.github.com>
Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com>
Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
2024-01-26 11:52:55 +01:00

81 lines
2.2 KiB
TypeScript

import { app } from '@electron/remote';
import { Git } from '@noodl/git';
import FileSystem from '@noodl-utils/filesystem';
import { mergeProject } from '@noodl-utils/projectmerger';
import Utils from '@noodl-utils/utils';
// https://codehandbook.org/check-if-an-array-sorted-javascript/
// Check if an array is sorted in order.
function sorted(arr: number[]) {
let second_index: number;
for (let first_index = 0; first_index < arr.length; first_index++) {
second_index = first_index + 1;
if (arr[second_index] - arr[first_index] < 0) return false;
}
return true;
}
describe('Git clone progress tests', function () {
let tempDir: string | undefined;
beforeEach(async function () {
tempDir = app.getPath('temp') + '/noodlunittests-git-' + Utils.guid() + '/';
FileSystem.instance.makeDirectorySync(tempDir);
});
afterEach(function (done) {
FileSystem.instance.removeDirectoryRecursive(tempDir, done);
tempDir = undefined;
});
it('clone from "master" with progress', async function () {
const result = [];
// Clone the project
const git = new Git(mergeProject);
await git.clone({
url: 'https://github.com/github/testrepo.git',
directory: tempDir,
onProgress: (progress) => {
result.push(progress);
}
});
const values = result.map((x) => x.value);
const isValuesSorted = sorted(values);
expect(result.length).toBeGreaterThan(10);
expect(isValuesSorted).toBeTrue();
});
it('clone and fetch with progress', async function () {
const result = [];
// Create empty repo
const git = new Git(mergeProject);
await git.clone({
url: 'https://github.com/github/testrepo.git',
directory: tempDir,
onProgress: (progress) => {
result.push(progress);
}
});
await git.checkoutBranch('master', '6ff1be9c3819c93a2f41e0ddc09f252fcf154f34');
// Fetch from remote
await git.fetch({
onProgress: (progress) => {
result.push(progress);
}
});
const values = result.map((x) => x.value);
const isValuesSorted = sorted(values);
expect(result.length).toBeGreaterThan(10);
expect(isValuesSorted).toBeTrue();
});
});