Skip to content

Commit

Permalink
Fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ecooper committed Dec 9, 2024
1 parent 4b34f39 commit 8a516ba
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
10 changes: 8 additions & 2 deletions src/lib/formatting/colorize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ const fqlToAnsi = async (obj) => {

const raw = stripAnsi(obj);
const codeToAnsi = container.resolve("codeToAnsi");
const res = await codeToAnsi(raw, "typescript", THEME);

return await codeToAnsi(raw, "typescript", THEME);
return res.trim();
};

const jsonToAnsi = async (obj) => {
const codeToAnsi = container.resolve("codeToAnsi");
const stringified = objToString(obj);
const res = await codeToAnsi(stringified, "json", THEME);

return await codeToAnsi(stringified, "json", THEME);
if (!res) {
return "";
}

return res.trim();
};

/**
Expand Down
2 changes: 1 addition & 1 deletion test/credentials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe("credentials", function () {
},
},
{
command: `query "Database.all()" -d us-std/test:badpath --no-color`,
command: `query "Database.all()" -d us-std/test:badpath --no-color --json`,
localCreds: defaultLocalCreds,
expected: {
databaseKeys: {
Expand Down
11 changes: 4 additions & 7 deletions test/login.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,13 @@ describe("login", function () {
// We open auth url in the browser and prompt user
expect(container.resolve("open").calledWith("http://dashboard-url.com"));
expect(logger.stdout).to.have.been.calledWith(
"To login, open your browser to:\n http://dashboard-url.com",
"To login, open your browser to:\nhttp://dashboard-url.com",
);
// Trigger server event with mocked auth code
await oauthClient._receiveAuthCode();
// Show login success message
expect(logger.stdout).to.have.been.calledWith("Login Success!\n");
expect(credentials.accountKeys.key).to.equal("login-account-key");

// We save the session credentials alongside existing credential contents
expect(credentials.accountKeys.key).to.equal("login-account-key");
expect(fs.writeFileSync.getCall(1).args[0]).to.include("access_keys");
expect(JSON.parse(fs.writeFileSync.getCall(1).args[1])).to.deep.equal(
expectedCreds,
Expand All @@ -140,7 +139,6 @@ describe("login", function () {
fs.readFileSync.returns(JSON.stringify(existingCreds));
await run(`login --user testUser`, container);
const oauthClient = container.resolve("oauthClient");
const logger = container.resolve("logger");
const expectedCreds = {
testUser: {
accountKey: "login-account-key",
Expand All @@ -149,8 +147,7 @@ describe("login", function () {
};
// Trigger server event with mocked auth code
await oauthClient._receiveAuthCode();
// Show login success message
expect(logger.stdout).to.have.been.calledWith("Login Success!\n");

// We save the session credentials and overwrite the profile of the same name locally
expect(fs.writeFileSync.getCall(1).args[0]).to.include("access_keys");
expect(JSON.parse(fs.writeFileSync.getCall(1).args[1])).to.deep.equal(
Expand Down
2 changes: 2 additions & 0 deletions test/shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe("shell", function () {

// send our first command
stdin.push(`1\n2\n3\n`);
await sleep(50);
await stdout.waitForWritten();

// navigate up through history
Expand Down Expand Up @@ -167,6 +168,7 @@ describe("shell", function () {

// send our first command
stdin.push("4\n5\n6\n");
await sleep(50);
await stdout.waitForWritten();

const command = ".clearhistory";
Expand Down

0 comments on commit 8a516ba

Please sign in to comment.