Files
atom/packages/git-diff/spec/diff-list-view-spec.js
Ruby Allison Rose b079194478 Fix git diff subscriptions (#21968)
The startup script now uses a `Set` to manage `GitDiffView`s held in memory and destroy them when `deactivate` is called.
There are now four major subscription blocks. 
1. The outer subscriptions held by `activate`.
2. The per-editor subscriptions held within `activate`.
3. The per-editor repository event subscriptions held within each `GitDIffView` instance.
4. The per-editor modification event subscriptions held within each `GitDiffView` are only active when the editor content is bound to a valid git repository.

Teardowns of any editor or the module now result in `disposal` of the respective editor's subscriptions or all subscriptions authored within the module.

I removed some of `GitDiffView`'s unnecessary methods such as the `start`, `cancleUpdate`, `addDecoration` and `removeDecorations`;
The last two methods were combined into the body of `updateDiffs`.
`scheduleUpdate` now calls `requestAnimationFrame` instead of `setImmediate` because it's native, standard, and yields
to other more important browser processes. I know Atom Core implements setImmediate, but rAF seems to work just as fast if not faster.
The memory management of the editor markers and diffs have been joined using a WeakMap. When the diffs are destroyed,
so too are the editor markers.
Finally, I added the `destroy` method to handle the teardown of subscriptions and other destroyable objects contained within the `GitDiffViews` before object release.
2021-03-08 21:12:07 +03:00

52 lines
1.5 KiB
JavaScript

const path = require('path');
const fs = require('fs-plus');
const temp = require('temp').track();
describe('git-diff:toggle-diff-list', () => {
let diffListView, editor;
beforeEach(() => {
const projectPath = temp.mkdirSync('git-diff-spec-');
fs.copySync(path.join(__dirname, 'fixtures', 'working-dir'), projectPath);
fs.moveSync(
path.join(projectPath, 'git.git'),
path.join(projectPath, '.git')
);
atom.project.setPaths([projectPath]);
jasmine.attachToDOM(atom.workspace.getElement());
waitsForPromise(() => atom.packages.activatePackage('git-diff'));
waitsForPromise(() => atom.workspace.open('sample.js'));
runs(() => {
editor = atom.workspace.getActiveTextEditor();
editor.setCursorBufferPosition([8, 30]);
editor.insertText('a');
atom.commands.dispatch(editor.getElement(), 'git-diff:toggle-diff-list');
});
waitsFor(() => {
diffListView = document.querySelector('.diff-list-view');
return diffListView && diffListView.querySelectorAll('li').length > 0;
});
});
it('shows a list of all diff hunks', () => {
diffListView = document.querySelector('.diff-list-view ol');
expect(diffListView.textContent).toBe(
'while (items.length > 0) {a-9,1 +9,1'
);
});
it('moves the cursor to the selected hunk', () => {
editor.setCursorBufferPosition([0, 0]);
atom.commands.dispatch(
document.querySelector('.diff-list-view'),
'core:confirm'
);
expect(editor.getCursorBufferPosition()).toEqual([8, 4]);
});
});