diff --git a/packages/link/spec/.eslintrc.js b/packages/link/spec/.eslintrc.js new file mode 100644 index 000000000..5226d6921 --- /dev/null +++ b/packages/link/spec/.eslintrc.js @@ -0,0 +1,9 @@ +module.exports = { + env: { jasmine: true }, + rules: { + "node/no-unpublished-require": "off", + "node/no-extraneous-require": "off", + "no-unused-vars": "off", + "no-empty": "off" + } +}; diff --git a/packages/link/spec/link-spec.js b/packages/link/spec/link-spec.js index e8a1bb4ce..09d63bd9a 100644 --- a/packages/link/spec/link-spec.js +++ b/packages/link/spec/link-spec.js @@ -2,8 +2,8 @@ const { shell } = require('electron'); describe('link package', () => { beforeEach(async () => { - await atom.packages.activatePackage('language-gfm'); await atom.packages.activatePackage('language-hyperlink'); + await atom.packages.activatePackage('language-gfm'); const activationPromise = atom.packages.activatePackage('link'); atom.commands.dispatch(atom.views.getView(atom.workspace), 'link:open'); @@ -15,7 +15,10 @@ describe('link package', () => { await atom.workspace.open('sample.md'); const editor = atom.workspace.getActiveTextEditor(); - editor.setText('// "http://github.com"'); + let languageMode = editor.getBuffer().getLanguageMode(); + await languageMode.ready; + editor.setText('// http://github.com '); + await languageMode.atTransactionEnd(); spyOn(shell, 'openExternal'); atom.commands.dispatch(atom.views.getView(editor), 'link:open'); @@ -35,76 +38,80 @@ describe('link package', () => { expect(shell.openExternal.argsForCall[0][0]).toBe('http://github.com'); shell.openExternal.reset(); - editor.setCursorBufferPosition([0, 21]); + editor.setCursorBufferPosition([0, 20]); atom.commands.dispatch(atom.views.getView(editor), 'link:open'); expect(shell.openExternal).toHaveBeenCalled(); expect(shell.openExternal.argsForCall[0][0]).toBe('http://github.com'); }); - // only works in Atom >= 1.33.0 - // https://github.com/atom/link/pull/33#issuecomment-419643655 - const atomVersion = atom.getVersion().split('.'); - console.error('atomVersion', atomVersion); - if (+atomVersion[0] > 1 || +atomVersion[1] >= 33) { - it("opens an 'atom:' link", async () => { - await atom.workspace.open('sample.md'); + // NOTE: I don't think anyone realized that this was a feature. Our + // `tree-sitter-markdown` parser doesn't recognize these as URLs. We'd need + // our custom `tree-sitter-hyperlink` to support this, and it doesn't right + // now, but I'll keep it in mind for the future. + xit("opens an 'atom:' link", async () => { + await atom.workspace.open('sample.md'); - const editor = atom.workspace.getActiveTextEditor(); - editor.setText( - '// "atom://core/open/file?filename=sample.js&line=1&column=2"' - ); + const editor = atom.workspace.getActiveTextEditor(); + editor.setText( + '// atom://core/open/file?filename=sample.js&line=1&column=2 ' + ); - spyOn(shell, 'openExternal'); - atom.commands.dispatch(atom.views.getView(editor), 'link:open'); - expect(shell.openExternal).not.toHaveBeenCalled(); + spyOn(shell, 'openExternal'); + atom.commands.dispatch(atom.views.getView(editor), 'link:open'); + expect(shell.openExternal).not.toHaveBeenCalled(); - editor.setCursorBufferPosition([0, 4]); - atom.commands.dispatch(atom.views.getView(editor), 'link:open'); + editor.setCursorBufferPosition([0, 4]); + atom.commands.dispatch(atom.views.getView(editor), 'link:open'); - expect(shell.openExternal).toHaveBeenCalled(); - expect(shell.openExternal.argsForCall[0][0]).toBe( - 'atom://core/open/file?filename=sample.js&line=1&column=2' - ); + expect(shell.openExternal).toHaveBeenCalled(); + expect(shell.openExternal.argsForCall[0][0]).toBe( + 'atom://core/open/file?filename=sample.js&line=1&column=2' + ); - shell.openExternal.reset(); - editor.setCursorBufferPosition([0, 8]); - atom.commands.dispatch(atom.views.getView(editor), 'link:open'); + shell.openExternal.reset(); + editor.setCursorBufferPosition([0, 8]); + atom.commands.dispatch(atom.views.getView(editor), 'link:open'); - expect(shell.openExternal).toHaveBeenCalled(); - expect(shell.openExternal.argsForCall[0][0]).toBe( - 'atom://core/open/file?filename=sample.js&line=1&column=2' - ); + expect(shell.openExternal).toHaveBeenCalled(); + expect(shell.openExternal.argsForCall[0][0]).toBe( + 'atom://core/open/file?filename=sample.js&line=1&column=2' + ); - shell.openExternal.reset(); - editor.setCursorBufferPosition([0, 60]); - atom.commands.dispatch(atom.views.getView(editor), 'link:open'); + shell.openExternal.reset(); + editor.setCursorBufferPosition([0, 59]); + atom.commands.dispatch(atom.views.getView(editor), 'link:open'); - expect(shell.openExternal).toHaveBeenCalled(); - expect(shell.openExternal.argsForCall[0][0]).toBe( - 'atom://core/open/file?filename=sample.js&line=1&column=2' - ); - }); - } + expect(shell.openExternal).toHaveBeenCalled(); + expect(shell.openExternal.argsForCall[0][0]).toBe( + 'atom://core/open/file?filename=sample.js&line=1&column=2' + ); + }); describe('when the cursor is on a [name][url-name] style markdown link', () => it('opens the named url', async () => { + jasmine.useRealClock(); await atom.workspace.open('README.md'); const editor = atom.workspace.getActiveTextEditor(); + let languageMode = editor.getBuffer().getLanguageMode(); + await languageMode.ready; + editor.setText(`\ you should [click][here] you should not [click][her] [here]: http://github.com\ `); + // Allow for time for injections to populate + await languageMode.atTransactionEnd(); spyOn(shell, 'openExternal'); editor.setCursorBufferPosition([0, 0]); atom.commands.dispatch(atom.views.getView(editor), 'link:open'); expect(shell.openExternal).not.toHaveBeenCalled(); - editor.setCursorBufferPosition([0, 20]); + editor.setCursorBufferPosition([0, 19]); atom.commands.dispatch(atom.views.getView(editor), 'link:open'); expect(shell.openExternal).toHaveBeenCalled();