-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/.makefiles/ | ||
/artifacts/ | ||
/CHANGELOG.md | ||
/test/fixture/specification/no-prettier/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
test/fixture/specification/no-prettier/prettier-not-configured.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Environment variables | ||
|
||
The `<app>` app uses **declarative environment variables** powered by | ||
**[Austenite]**. | ||
|
||
[austenite]: https://github.com/ezzatron/austenite | ||
|
||
| Name | Usage | Description | | ||
| :-------------- | :------- | :-------------- | | ||
| [`LOGO`](#logo) | Required | Main logo image | | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
> [!TIP] | ||
> If you set an empty value for an environment variable, the app behaves as if that variable isn't set. | ||
<!-- prettier-ignore-end --> | ||
|
||
## `LOGO` | ||
|
||
_Main logo image_ | ||
|
||
The `LOGO` variable is a **required** variable that takes **absolute URL** | ||
values, or **relative URL** values relative to | ||
`https://base.example.org/path/to/resource`. | ||
|
||
### Example values | ||
|
||
```sh | ||
export LOGO=https://host.example.org/path/to/resource # URL (absolute) | ||
``` | ||
|
||
```sh | ||
export LOGO=path/to/resource # URL (relative) | ||
``` |
32 changes: 32 additions & 0 deletions
32
test/fixture/specification/no-prettier/prettier-unavailable.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Environment variables | ||
|
||
The `<app>` app uses **declarative environment variables** powered by **[Austenite]**. | ||
|
||
[austenite]: https://github.com/ezzatron/austenite | ||
|
||
| Name | Usage | Description | | ||
| :-------------- | :------- | :-------------- | | ||
| [`LOGO`](#logo) | Required | Main logo image | | ||
|
||
<!-- prettier-ignore-start --> | ||
|
||
> [!TIP] | ||
> If you set an empty value for an environment variable, the app behaves as if that variable isn't set. | ||
<!-- prettier-ignore-end --> | ||
|
||
## `LOGO` | ||
|
||
_Main logo image_ | ||
|
||
The `LOGO` variable is a **required** variable that takes **absolute URL** values, or **relative URL** values relative to `https://base.example.org/path/to/resource`. | ||
|
||
### Example values | ||
|
||
```sh | ||
export LOGO=https://host.example.org/path/to/resource # URL (absolute) | ||
``` | ||
|
||
```sh | ||
export LOGO=path/to/resource # URL (relative) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { join } from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { | ||
afterAll, | ||
beforeAll, | ||
beforeEach, | ||
describe, | ||
expect, | ||
it, | ||
vi, | ||
} from "vitest"; | ||
import { initialize, url } from "../../src/index.js"; | ||
import { MockConsole, createMockConsole } from "../helpers.js"; | ||
|
||
const fixturesPath = fileURLToPath( | ||
new URL("../fixture/specification", import.meta.url), | ||
); | ||
|
||
describe("Specification documents (Prettier unavailable)", () => { | ||
let exitCode: number | undefined; | ||
let mockConsole: MockConsole; | ||
|
||
beforeEach(() => { | ||
exitCode = undefined; | ||
vi.spyOn(process, "exit").mockImplementation((code) => { | ||
exitCode = code ?? 0; | ||
|
||
return undefined as never; | ||
}); | ||
|
||
process.env = { | ||
AUSTENITE_SPEC: "true", | ||
}; | ||
|
||
mockConsole = createMockConsole(); | ||
}); | ||
|
||
describe("when Prettier is not installed", () => { | ||
beforeAll(() => { | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
vi.doMock("prettier", async () => { | ||
throw new Error('Cannot find module "prettier"'); | ||
}); | ||
}); | ||
|
||
afterAll(() => { | ||
vi.doUnmock("prettier"); | ||
}); | ||
|
||
it("doesn't pretty print the specification output", async () => { | ||
url("LOGO", "Main logo image", { | ||
base: new URL("https://base.example.org/path/to/resource"), | ||
}); | ||
await initialize(); | ||
|
||
await expect(mockConsole.readStdout()).toMatchFileSnapshot( | ||
fixturePath("no-prettier/prettier-unavailable"), | ||
); | ||
expect(exitCode).toBe(0); | ||
}); | ||
}); | ||
|
||
describe("when Prettier is installed but not configured", () => { | ||
beforeAll(() => { | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
vi.doMock("prettier", async () => { | ||
const prettier = await vi.importActual("prettier"); | ||
|
||
return { | ||
...prettier, | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async resolveConfig() { | ||
return null; | ||
}, | ||
}; | ||
}); | ||
}); | ||
|
||
afterAll(() => { | ||
vi.doUnmock("prettier"); | ||
}); | ||
|
||
it("uses prose wrap at 80 columns", async () => { | ||
url("LOGO", "Main logo image", { | ||
base: new URL("https://base.example.org/path/to/resource"), | ||
}); | ||
await initialize(); | ||
|
||
await expect(mockConsole.readStdout()).toMatchFileSnapshot( | ||
fixturePath("no-prettier/prettier-not-configured"), | ||
); | ||
expect(exitCode).toBe(0); | ||
}); | ||
}); | ||
}); | ||
|
||
function fixturePath(name: string): string { | ||
return join(fixturesPath, `${name}.md`); | ||
} |