我为Atom创建了一个名为quick-fold的程序包,该程序包跳到下一个可折叠的行,并在命令quick-fold:fold-next
上将其折叠。我想开始了解Atom规范,以便可以对此程序包进行测试,但是我遇到了这个问题,即在运行规范时永远不会激活该程序包。
quick-fold-spec.js
:
describe('QuickFold package', () => {
let editor, editorView;
beforeEach(async () => {
await atom.packages.activatePackage('language-javascript');
await atom.workspace.open('sample.js');
editor = atom.workspace.getActiveTextEditor();
editorView = atom.views.getView(editor);
});
describe('when the specs are run', () => {
it('opens the sample file', () => expect(!editor.isEmpty()).toBe(true));
// true
});
describe('when the quick-fold:fold-next event is triggered', () => {
beforeEach(async () => {
// Try to activate package by dispatching command:
atom.commands.dispatch(editorView, 'quick-fold:fold-next');
await atom.packages.activatePackage('quick-fold'); // Never resolves
});
it('activates the package', () => {
expect(atom.packages.isPackageActive('quick-fold')).toBe(true);
});
it('moves the cursor to a different line number', () => {
expect(editor.getCursorScreenPosition().row).not.toBe(0);
});
});
});
但是atom.packages.activatePackage('quick-fold')
从未解决。该软件包不会激活,而是超时:
timeout: timed out after 5000 msec waiting for spec promise to resolve
激活命令在package.json
中设置:
"activationCommands": {
"atom-workspace": "quick-fold:fold-next"
},
因此,分派这应该激活程序包,然后await atom.packages.activatePackage('quick-fold')
应该解决。但是光标位置不会改变,并且程序包不会被激活。
((请注意,atom.packages.activatePackage('quick-fold')
只是一个承诺-它不会激活程序包,但会在激活程序包时解决。)