Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
valo committed Apr 25, 2017
0 parents commit 1ef8b95
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
npm-debug.log
node_modules
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## 0.1.0 - First Release
* Allows to jump between a module and its tests
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2017 Valentin Mihov

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# elixir-jump-around package

A plugin which allows to jump between the module and its tests in a mix project. By default the keybinding for the toggle is with `Alt-G Alt-T` (mnemonic of "Go To Test").
5 changes: 5 additions & 0 deletions keymaps/elixir-jump-around.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"atom-text-editor[data-grammar='source elixir']": {
"alt-g alt-t": "elixir-jump-around:toggle-test-file"
}
}
49 changes: 49 additions & 0 deletions lib/elixir-jump-around.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use babel';

import { CompositeDisposable } from 'atom';
const path = require('path');

export default {

subscriptions: null,

activate(state) {
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
this.subscriptions = new CompositeDisposable();

// Register command that toggles this view
this.subscriptions.add(atom.commands.add("atom-text-editor[data-grammar='source elixir']", {
'elixir-jump-around:toggle-test-file': () => this.toggle_test_file()
}));
},

deactivate() {
this.subscriptions.dispose();
},

toggle_test_file() {
currentFilePath = atom.workspace.getActiveTextEditor().getPath();
if (this.isTestFilePath(currentFilePath)) {
return atom.workspace.open(this.getModulePath(currentFilePath));
} else {
return atom.workspace.open(this.getTestPath(currentFilePath));
}
},

isTestFilePath(filePath) {
return atom.project.getPaths().find((rootPath) => {
console.log(rootPath);
relativePath = path.relative(rootPath, filePath);
console.log(`${relativePath} is the relative of ${filePath}`)
return relativePath.match(/^test\/.+_test\.exs$/);
});
},

getModulePath(filePath) {
return filePath.replace("test", "lib").replace(/_test\.exs$/, ".ex");
},

getTestPath(filePath) {
return filePath.replace("lib", "test").replace(/\.ex$/, "_test.exs");
}
};
26 changes: 26 additions & 0 deletions menus/elixir-jump-around.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"context-menu": {
"atom-text-editor": [
{
"label": "Toggle test file and the module definiton",
"command": "elixir-jump-around:toggle-test-file"
}
]
},
"menu": [
{
"label": "Packages",
"submenu": [
{
"label": "elixir-jump-around",
"submenu": [
{
"label": "Toggle Test File",
"command": "elixir-jump-around:toggle-test-file"
}
]
}
]
}
]
}
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "elixir-jump-around",
"main": "./lib/elixir-jump-around",
"version": "0.1.0",
"description": "Jump between modules and tests in an elixir mix projects",
"keywords": [
],
"activationCommands": {
"atom-workspace": "elixir-jump-around:toggle-test-file"
},
"repository": "https://github.com/valo/elixir-jump-around",
"license": "MIT",
"engines": {
"atom": ">=1.0.0 <2.0.0"
},
"dependencies": {
}
}
43 changes: 43 additions & 0 deletions spec/elixir-jump-around-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use babel';

import ElixirJumpAround from '../lib/elixir-jump-around';

// Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
//
// To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
// or `fdescribe`). Remove the `f` to unfocus the block.

const path = require('path');
const fs = require('fs');
const PROJECT_ROOT = fs.mkdtempSync("/tmp/elixir-jump-around-");

describe('ElixirJumpAround', () => {
let workspaceElement, activationPromise;

beforeEach(() => {
atom.project.setPaths([PROJECT_ROOT])

workspaceElement = atom.views.getView(atom.workspace);
activationPromise = atom.packages.activatePackage('elixir-jump-around');
});

describe('isTestFilePath', () => {
it('returns if the file is a test or not', () => {
expect(ElixirJumpAround.isTestFilePath(path.join(PROJECT_ROOT, "/lib/foo.ex"))).toBeFalsy();
expect(ElixirJumpAround.isTestFilePath(path.join(PROJECT_ROOT, "/lib/foo.ex"))).toBeFalsy();
expect(ElixirJumpAround.isTestFilePath(path.join(PROJECT_ROOT, "/test/foo_test.exs"))).toBeTruthy();
});
});

describe('getModulePath', () => {
it('returns the correct module path of a test file', () => {
expect(ElixirJumpAround.getModulePath(path.join(PROJECT_ROOT, "/test/foo_test.exs"))).toEqual(path.join(PROJECT_ROOT, "/lib/foo.ex"));
});
});

describe('getTestPath', () => {
it('returns the correct test path of a test file', () => {
expect(ElixirJumpAround.getTestPath(path.join(PROJECT_ROOT, "/lib/foo.ex"))).toEqual(path.join(PROJECT_ROOT, "/test/foo_test.exs"));
});
});
});

0 comments on commit 1ef8b95

Please sign in to comment.