Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Aug 29, 2024
1 parent 974e97e commit a7b4558
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .taprc
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
files:
- test/**/*.test.js

coverage:
lines: 91
functions: 100
branches: 83
statements: 91
37 changes: 28 additions & 9 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const errorLine =
const fatalErrorLine =
'{"level":60,"time":1597426544906,"pid":43024,"hostname":"Gregors-MacBook-Pro.local","name":"probot","stack":"Error: Oh no!\\n at Object.<anonymous> (/Users/gregor/Projects/probot/pino/example.js:59:12)\\n at Module._compile (internal/modules/cjs/loader.js:1137:30)\\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)\\n at Module.load (internal/modules/cjs/loader.js:985:32)\\n at Function.Module._load (internal/modules/cjs/loader.js:878:14)\\n at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)\\n at internal/main/run_main_module.js:17:47","type":"Error","msg":"Oh no!"}\n';

const stripAnsiColorRE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g
const stripAnsiColorRE =
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;

const env = {
// disable colors
Expand All @@ -29,7 +30,10 @@ test("cli", (t) => {
const child = spawn(nodeBinaryPath, [cliPath], { env });
child.on("error", t.threw);
child.stdout.on("data", (data) => {
t.equal(data.toString().replace(stripAnsiColorRE, ''), `INFO (probot): hello future\n`);
t.equal(
data.toString().replace(stripAnsiColorRE, ""),
`INFO (probot): hello future\n`
);
});
child.stdin.write(logLine);
t.teardown(() => child.kill());
Expand All @@ -41,9 +45,15 @@ test("cli", (t) => {
const child = spawn(nodeBinaryPath, [cliPath], { env });
child.on("error", t.threw);
child.stdout.on("data", (data) => {
t.match(data.toString().replace(stripAnsiColorRE, ''), /event: "installation_repositories.added"/);
t.match(data.toString().replace(stripAnsiColorRE, ''), /status: 500/);
t.match(data.toString().replace(stripAnsiColorRE, ''), /x-github-request-id: "789"/);
t.match(
data.toString().replace(stripAnsiColorRE, ""),
/event: "installation_repositories.added"/
);
t.match(data.toString().replace(stripAnsiColorRE, ""), /status: 500/);
t.match(
data.toString().replace(stripAnsiColorRE, ""),
/x-github-request-id: "789"/
);
t.match(
data.toString(),
/url: "https:\/\/api.github.com\/repos\/octocat\/hello-world\/"/
Expand All @@ -60,7 +70,7 @@ test("cli", (t) => {
});
child.on("error", t.threw);
child.stdout.on("data", (data) => {
t.equal(data.toString().replace(stripAnsiColorRE, ''), logLine);
t.equal(data.toString().replace(stripAnsiColorRE, ""), logLine);
});
child.stdin.write(logLine);
t.teardown(() => child.kill());
Expand All @@ -73,7 +83,10 @@ test("cli", (t) => {
});
child.on("error", t.threw);
child.stdout.on("data", (data) => {
t.equal(data.toString().replace(stripAnsiColorRE, ''), logLine.replace('"level":30', '"level":"info"'));
t.equal(
data.toString().replace(stripAnsiColorRE, ""),
logLine.replace('"level":30', '"level":"info"')
);
});
child.stdin.write(logLine);
t.teardown(() => child.kill());
Expand Down Expand Up @@ -130,7 +143,10 @@ test("cli", (t) => {
});
child.on("error", t.threw);
child.stdout.on("data", (data) => {
const errorStringLines = data.toString().replace(stripAnsiColorRE, '').split(/\n/);
const errorStringLines = data
.toString()
.replace(stripAnsiColorRE, "")
.split(/\n/);
t.equal(errorStringLines[0].trim(), "ERROR (probot): Oops");

// skip the error stack, normalize Sentry Event ID, compare error details only
Expand Down Expand Up @@ -192,7 +208,10 @@ sentryEventId: 123`
});
child.on("error", t.threw);
child.stdout.on("data", (data) => {
t.match(data.toString().replace(stripAnsiColorRE, ''), /^FATAL \(probot\): Oh no!\n/);
t.match(
data.toString().replace(stripAnsiColorRE, ""),
/^FATAL \(probot\): Oh no!\n/
);
});
child.stdin.write(fatalErrorLine);

Expand Down

0 comments on commit a7b4558

Please sign in to comment.