Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ jobs:
run: |
yarn lint

- name: Setup Toit
if: ${{ github.event.inputs.run-tests != 'false' }}
uses: toitlang/action-setup@v1
with:
toit-version: v2.0.0-alpha.189

- name: Generate test data
if: ${{ github.event.inputs.run-tests != 'false' }}
run: |
tests/generate_test_data.sh

- name: Test
if: ${{ github.event.inputs.run-tests != 'false' }}
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,5 @@ sketch
# End of https://www.toptal.com/developers/gitignore/api/yarn,node,react

.packages/
public/toitdoc*.json
cypress_output*.txt
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,28 @@ You can create new json files by running the following command:
### Core libraries

```bash
toit doc build --sdk --out "$OUTFILE"
toit doc build --sdk --output "$OUTFILE"
```

### Package

```bash
toit doc build --package --out "$OUTFILE" $PATH_TO_PACKAGE
toit doc build --package --output "$OUTFILE" $PATH_TO_PACKAGE
```

You might want to exclude the sdk and/or packages from the generated documentation:

```bash
toit doc build --package --exclude-sdk --out "$OUTFILE" $PATH_TO_PACKAGE
toit doc build --package --exclude-pkgs --out "$OUTFILE" $PATH_TO_PACKAGE
toit doc build --package --exclude-sdk --output "$OUTFILE" $PATH_TO_PACKAGE
toit doc build --package --exclude-pkgs --output "$OUTFILE" $PATH_TO_PACKAGE
```

### Folder

You can also just build the toitdoc of a folder:

```bash
toit doc build --out "$OUTFILE" $PATH_TO_FOLDER
toit doc build --output "$OUTFILE" $PATH_TO_FOLDER
```

## Cloudflare
Expand Down
4 changes: 3 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"baseUrl": "http://localhost:3000"
}
117 changes: 117 additions & 0 deletions cypress/integration/docs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/// <reference types="cypress" />

describe("Documentation Viewer", () => {
beforeEach(() => {
// Increase default timeout for all tests as loading/rendering might be slow, especially for SDK
Cypress.config("defaultCommandTimeout", 30000);
});

const checkSidebarGroup = (label: string) => {
// The sidebar might use different structures. This is a generic check.
cy.contains(label).should("be.visible");
};

describe("Package Mode", () => {
beforeEach(() => {
// Load the package-specific json
cy.readFile("public/toitdoc_pkg.json").then((json) => {
json.mode = "package";
cy.intercept("GET", "/toitdoc.json", json).as("getDocs");
});
cy.visit("/");
cy.wait("@getDocs");
});

it("loads the package view", () => {
cy.get("body").should("contain.text", "pkg");
// Enhanced assertions
// Sidebar "Libraries" header
cy.contains("h5", "Libraries").should("be.visible");
// Sidebar "pkg" item
cy.contains("pkg").should("be.visible");
cy.contains("h3", "Functions").should("be.visible");
// Check function signatures
cy.contains("foo str/string").should("be.visible");
cy.contains(" -> string").should("be.visible");
cy.contains("bar a/A").should("be.visible");
cy.contains(" -> A").should("be.visible");
});

it("navigates to class A", () => {
cy.contains("pkg").click();
cy.contains("foo").should("be.visible");
cy.contains("bar").should("be.visible");

// Click on 'A' explicitly within the Classes section.
cy.contains("h3", "Classes")
.parent()
.parent()
.within(() => {
cy.contains("a", /^A$/).click();
});
cy.contains("Class A").should("be.visible");

// Enhanced assertions for Class A
cy.contains("extends Object").should("be.visible");
cy.contains("h3", "Methods").should("be.visible");
cy.contains("operator == other/any").should("be.visible");
cy.contains(" -> bool").should("be.visible");
cy.contains("stringify").should("be.visible");
cy.contains(" -> string").should("be.visible");
});
});

describe("Folder/SDK Mode", () => {
beforeEach(() => {
// Load the folder/sdk-like json
cy.readFile("public/toitdoc_folder.json").then((json) => {
delete json.mode; // mode undefined means Folder view in doc.ts
cy.intercept("GET", "/toitdoc.json", json).as("getDocs");
});
Cypress.config("defaultCommandTimeout", 30000);
cy.visit("/");
cy.wait("@getDocs");
cy.get(".MuiCircularProgress-root").should("not.exist");
});

it("loads the folder view", () => {
cy.get("body").should("contain.text", "pkg");
// Enhanced assertions
cy.contains("Toitdoc Viewer").should("be.visible");
cy.contains("Welcome to the Toitdoc viewer").should("be.visible");
cy.contains("Libraries").should("be.visible");
cy.contains("other").should("be.visible");
cy.contains("pkg").should("be.visible");
});
});

describe("SDK Mode", () => {
beforeEach(() => {
// Load the sdk json
cy.readFile("public/toitdoc_sdk.json").then((json) => {
json.mode = "sdk";
cy.intercept("GET", "/toitdoc.json", json).as("getDocs");
});
cy.visit("/");
cy.wait("@getDocs");
});

it("loads the sdk view and shows Core library", () => {
cy.get("body").should("contain.text", "core");
// Navigate to 'core'
cy.contains("core").click();

// Enhanced assertions for SDK Core
cy.contains("Library core").should("be.visible");
cy.contains("h3", "Exported classes").should("be.visible");
cy.contains("h3", "Exported functions").should("be.visible");

// Check for common core classes/functions
cy.contains("bool").should("be.visible");
cy.contains("int").should("be.visible");
cy.contains("string").should("be.visible");
cy.contains("List").should("be.visible");
cy.contains("print message/any").should("be.visible");
});
});
});
29 changes: 29 additions & 0 deletions tests/generate_test_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Exit on error
set -e

# Go to the project root
cd "$(dirname "$0")/.."

# Install dependencies for the test package
echo "Installing dependencies for test-pkg..."
toit pkg install --project-root=tests/test-pkg

# Generate the toitdoc.json for the package (default for now)
echo "Generating public/toitdoc.json from test-pkg..."
toit doc build --package --output public/toitdoc.json tests/test-pkg

# Generate a separate package json for specific tests
echo "Generating public/toitdoc_pkg.json..."
toit doc build --package --output public/toitdoc_pkg.json tests/test-pkg

# Generate SDK documentation
echo "Generating public/toitdoc_sdk.json..."
toit doc build --sdk --output public/toitdoc_sdk.json

# Generate basic folder documentation
echo "Generating public/toitdoc_folder.json..."
toit doc build --output public/toitdoc_folder.json tests/test-pkg/src

echo "Done."