Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple test suite for cd commands #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Continuous Integration

on:
pull_request: {}

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: 14
cache: 'npm'
- run: npm test
2 changes: 2 additions & 0 deletions config/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,3 +602,5 @@ for (kv of Object.entries(portfolio)) {
function _filesHere() {
return DIRS[term.cwd].filter((e) => e != 'README.md' || term.user == "root" );
}

if (typeof module !== "undefined") module.exports = commands;
28 changes: 28 additions & 0 deletions config/commands.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// TODO add explicit imports in commands.js rather than relying on globals
global.term = require("../js/terminal-ext")({});
global.portfolio = require("./portfolio");
global.commands = require("./commands");

test.each([
["<anything>", "/", "/"],
["<anything>", "~", "~"],
["<anything>", "~/", "~"],
["~", "..", "home"],
["~", "../", "home"],
["<anything>", "../../", "/"],
["<anything>", "../..", "/"],
["<anything>", "../../../", "/"],
["<anything>", "../../../../", "/"],
["<anything>", "/", "/"],
["/", "home", "home"],
["<anything>", "/home", "home"],
["/", "bin", "bin"],
["<anything>", ".", "<anything>"],
["<anything>", "./", "<anything>"],
["<anything>", "", "~"],
["<anything>", "/bin", "bin"],
])("command.cd(%s, %s)", (initial, args, expected) => {
term.cwd = initial;
term.command("cd " + args);
expect(term.cwd).toBe(expected);
});
2 changes: 2 additions & 0 deletions config/portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,5 @@ const portfolio = {
description: "Kayhan’s spaceflight operations platform allows satellite operators to focus on their core mission.",
},
};

if (typeof module !== "undefined") module.exports = portfolio;
3 changes: 3 additions & 0 deletions js/terminal-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ extend = (term) => {
term.command(term.deepLink);
}
}
return term;
}

// https://stackoverflow.com/questions/14484787/wrap-text-in-javascript
Expand Down Expand Up @@ -175,3 +176,5 @@ function _testWhite(x) {
var white = new RegExp(/^\s$/);
return white.test(x.charAt(0));
};

if (typeof module !== "undefined") module.exports = extend;
Loading