mirror of
https://github.com/fluxscape/fluxscape.git
synced 2026-01-11 23:02:55 +01:00
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>
This commit is contained in:
59
packages/noodl-editor/tests/git/git-diff.spec.ts
Normal file
59
packages/noodl-editor/tests/git/git-diff.spec.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
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';
|
||||
|
||||
describe('Git diff tests', function () {
|
||||
let git: Git;
|
||||
let tempDir: string;
|
||||
|
||||
beforeEach(async function () {
|
||||
// Logger.log(`[jest-before]: ${expect.getState().currentTestName}`)
|
||||
|
||||
tempDir = app.getPath('temp') + '/noodlunittests-git-' + Utils.guid() + '/';
|
||||
FileSystem.instance.makeDirectorySync(tempDir);
|
||||
|
||||
git = new Git(mergeProject);
|
||||
await git.initNewRepo(tempDir);
|
||||
// await git.commit("initial commit"); //commit .gitattributes so we have a clean repo
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
// Logger.log(`\r\n[jest-after]: ${expect.getState().currentTestName}`)
|
||||
FileSystem.instance.removeDirectoryRecursive(tempDir, done);
|
||||
tempDir = undefined;
|
||||
});
|
||||
|
||||
it('can diff files between commits', async function () {
|
||||
FileSystem.instance.writeFileSync(tempDir + 'initial.txt', 'hello world');
|
||||
await git.commit('initial commit');
|
||||
|
||||
const commit0 = await git.getHeadCommitId();
|
||||
|
||||
FileSystem.instance.writeFileSync(tempDir + 'file.txt', 'text');
|
||||
await git.commit('added file');
|
||||
|
||||
const commit1 = await git.getHeadCommitId();
|
||||
let diff = await git.getFileDiff(commit0, commit1);
|
||||
expect(diff).toEqual([
|
||||
{
|
||||
status: 'new',
|
||||
path: 'file.txt'
|
||||
}
|
||||
]);
|
||||
|
||||
FileSystem.instance.writeFileSync(tempDir + 'file.txt', 'text2');
|
||||
await git.commit('modified file');
|
||||
|
||||
const commit2 = await git.getHeadCommitId();
|
||||
diff = await git.getFileDiff(commit1, commit2);
|
||||
expect(diff).toEqual([
|
||||
{
|
||||
status: 'modified',
|
||||
path: 'file.txt'
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user