Skip to content

Commit

Permalink
Add the presence of the client file to diagnose
Browse files Browse the repository at this point in the history
The diagnose report now checks on the presence of the `appsignal.cjs`
file we require customers to initialize the AppSignal client when
starting their apps.
  • Loading branch information
luismiramirez committed May 10, 2023
1 parent 2315536 commit 71e076d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changesets/report-client-file-presence-in-diagnose-result.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "add"
---

The diagnose CLI command now reports on the presence of the `appsignal.cjs` file.
36 changes: 36 additions & 0 deletions src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,42 @@ describe("Configuration", () => {
})
})

describe("clientFilePath", () => {
describe("when the client file exists in the root path", () => {
it("returns the path to the client file", () => {
jest.spyOn(fs, "existsSync").mockImplementation(givenPath => {
return givenPath === path.join(process.cwd(), "appsignal.cjs")
})
config = new Configuration({ name, pushApiKey })

expect(config.clientFilePath).toEqual(
path.join(process.cwd(), "appsignal.cjs")
)
})
})

describe("when the client file exists in the src path", () => {
it("returns the path to the client file", () => {
jest.spyOn(fs, "existsSync").mockImplementation(givenPath => {
return givenPath === path.join(process.cwd(), "src", "appsignal.cjs")
})
config = new Configuration({ name, pushApiKey })

expect(config.clientFilePath).toEqual(
path.join(process.cwd(), "src", "appsignal.cjs")
)
})
})

describe("when the client file does not exist", () => {
it("returns undefined", () => {
config = new Configuration({ name, pushApiKey })

expect(config.clientFilePath).toBeUndefined()
})
})
})

describe("private environment variables", () => {
beforeEach(() => {
new Configuration({})
Expand Down
7 changes: 7 additions & 0 deletions src/cli/diagnose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ export class Diagnose {

this.print_newline()

console.log(` AppSignal client file`)
console.log(
` Path: ${format_value(data["paths"]["appsignal.cjs"]["path"])}`
)

this.print_newline()

console.log(` AppSignal log`)
console.log(
` Path: ${format_value(data["paths"]["appsignal.log"]["path"])}`
Expand Down
13 changes: 13 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from "path"
import os from "os"
import fs from "fs"

import { VERSION } from "./version"
import { isWritable } from "./utils"
Expand Down Expand Up @@ -74,6 +75,18 @@ export class Configuration {
}
}

public get clientFilePath(): string | undefined {
const filename = "appsignal.cjs"

if (fs.existsSync(path.join(process.cwd(), filename))) {
return path.join(process.cwd(), filename)
} else if (fs.existsSync(path.join(process.cwd(), "src", filename))) {
return path.join(process.cwd(), "src", filename)
} else {
return undefined
}
}

/**
* Returns default OS tmp dir. Uses OS package for Windows. Linux and macOS
* have `/tmp` hardcoded as a default
Expand Down
4 changes: 3 additions & 1 deletion src/diagnose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export class DiagnoseTool {

private getPathsData() {
const paths: { [key: string]: FileMetadata } = {}

const logFilePath = this.#config.logFilePath

const pathsToCheck = {
Expand All @@ -157,6 +156,9 @@ export class DiagnoseTool {
log_dir_path: {
path: logFilePath ? path.dirname(logFilePath) : ""
},
"appsignal.cjs": {
path: this.#config.clientFilePath || ""
},
"appsignal.log": {
path: logFilePath || "",
content: logFilePath
Expand Down
2 changes: 1 addition & 1 deletion test/integration/diagnose

0 comments on commit 71e076d

Please sign in to comment.