|
| 1 | +import { polywrapCli } from "../utils"; |
| 2 | +import { defaultDocsManifest, intlMsg } from "../../../"; |
| 3 | + |
| 4 | +import { Commands, runCli } from "@polywrap/cli-js"; |
| 5 | +import { GetPathToCliTestFiles } from "@polywrap/test-cases"; |
| 6 | +import fse from "fs-extra"; |
| 7 | +import path from "path"; |
| 8 | + |
| 9 | +const DOCS_HELP = `Usage: polywrap docs [options] [command] |
| 10 | +
|
| 11 | +Documentation commands |
| 12 | +
|
| 13 | +Options: |
| 14 | + -h, --help display help for command |
| 15 | +
|
| 16 | +Commands: |
| 17 | + init|i [options] Initialize wrap docs |
| 18 | + help [command] display help for command |
| 19 | +`; |
| 20 | + |
| 21 | +const DOCS_INIT_HELP = `Usage: polywrap docs init|i [options] |
| 22 | +
|
| 23 | +Initialize wrap docs |
| 24 | +
|
| 25 | +Options: |
| 26 | + -m, --manifest-file <path> Path to the Polywrap manifest file (default: |
| 27 | + polywrap.yaml | polywrap.yml) |
| 28 | + -v, --verbose Verbose output (default: false) |
| 29 | + -q, --quiet Suppress output (default: false) |
| 30 | + -l, --log-file [path] Log file to save console output to |
| 31 | + -h, --help display help for command |
| 32 | +`; |
| 33 | + |
| 34 | +describe("docs command", () => { |
| 35 | + const testCaseRoot = path.join(GetPathToCliTestFiles(), "build-cmd/wasm/assemblyscript/001-sanity"); |
| 36 | + const manifestFileName = defaultDocsManifest[0]; |
| 37 | + const manifestFile = path.join(testCaseRoot, manifestFileName); |
| 38 | + |
| 39 | + it("should show help text", async () => { |
| 40 | + const { exitCode, stdout, stderr } = await runCli({ |
| 41 | + args: ["docs"], |
| 42 | + config: { |
| 43 | + cli: polywrapCli |
| 44 | + } |
| 45 | + }); |
| 46 | + |
| 47 | + expect(stderr).toBe(DOCS_HELP); |
| 48 | + expect(stdout).toBe(""); |
| 49 | + expect(exitCode).toEqual(1); |
| 50 | + }); |
| 51 | + |
| 52 | + describe("init command", () => { |
| 53 | + it("should show help text", async () => { |
| 54 | + const { exitCode, stdout, stderr } = await Commands.docs.init({ |
| 55 | + help: true |
| 56 | + }, { |
| 57 | + cli: polywrapCli, |
| 58 | + cwd: testCaseRoot |
| 59 | + }); |
| 60 | + |
| 61 | + expect(stdout).toBe(DOCS_INIT_HELP); |
| 62 | + expect(stderr).toBe(""); |
| 63 | + expect(exitCode).toEqual(0); |
| 64 | + }); |
| 65 | + |
| 66 | + it("should set up wrap docs - no file collisions", async () => { |
| 67 | + const { exitCode, stdout, stderr } = await Commands.docs.init({}, { |
| 68 | + cli: polywrapCli, |
| 69 | + cwd: testCaseRoot |
| 70 | + }); |
| 71 | + |
| 72 | + expect(stdout).toContain(intlMsg.commands_docs_init_msg_manifest_created({ |
| 73 | + manifestFile: manifestFileName |
| 74 | + })); |
| 75 | + expect(stderr).toContain("Set the 'extensions.docs' property"); |
| 76 | + expect(exitCode).toEqual(0); |
| 77 | + expect(fse.existsSync(manifestFile)).toBe(true); |
| 78 | + |
| 79 | + fse.rmSync(manifestFile); |
| 80 | + }); |
| 81 | + |
| 82 | + it("should error when setting up wrap docs - manifest file collision", async () => { |
| 83 | + await fse.createFile(manifestFile); |
| 84 | + |
| 85 | + const { exitCode, stdout, stderr } = await Commands.docs.init({}, { |
| 86 | + cli: polywrapCli, |
| 87 | + cwd: testCaseRoot |
| 88 | + }); |
| 89 | + |
| 90 | + expect(stderr).toContain( |
| 91 | + intlMsg.commands_docs_init_error_manifest_exists({ |
| 92 | + manifestFile: manifestFileName, |
| 93 | + }) |
| 94 | + ); |
| 95 | + expect(stdout).toBe(""); |
| 96 | + expect(exitCode).toEqual(1); |
| 97 | + |
| 98 | + fse.rmSync(manifestFile); |
| 99 | + }); |
| 100 | + }); |
| 101 | +}); |
0 commit comments