diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 4653da4..71eb4f7 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -15,7 +15,7 @@ jobs: name: e2e-${{matrix.name}} runs-on: ${{matrix.runs-on}} env: - STRUCTURIZR_CLI_VERSION: v2024.11.04 + STRUCTURIZR_CLI_VERSION: v2024.07.03 strategy: fail-fast: true matrix: @@ -57,6 +57,11 @@ jobs: choco install jq --version 1.7.1 choco install bun --version 1.1.20 if: ${{ matrix.os == 'windows' }} + - uses: actions/setup-java@v4 + if: ${{ matrix.os == 'windows' }} + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '21' - run: bun install --ignore-scripts - name: Download created artifacts uses: actions/download-artifact@v4 @@ -106,20 +111,27 @@ jobs: if: ${{ inputs.smoke && matrix.os != 'windows' }} run: | export STRUCTURIZR_CLI_PATH=./dist/structurizr-cli-bin/structurizr.sh + export TMP_FOLDER=${{ runner.temp }} bun test:e2e:smoke - name: E2E Test (Full) if: ${{ !inputs.smoke && matrix.os != 'windows' }} run: | export STRUCTURIZR_CLI_PATH=./dist/structurizr-cli-bin/structurizr.sh + export TMP_FOLDER=${{ runner.temp }} bun test:e2e - # TODO: Windows E2E Tests - # - name: E2E Test (Smoke) (Windows) - # if: ${{ inputs.smoke && matrix.os == 'windows' }} - # run: | - # $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" - # bun test:e2e:smoke - # - name: E2E Test (Full) (Windows) - # if: ${{ !inputs.smoke && matrix.os == 'windows' }} - # run: | - # $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" - # bun test:e2e \ No newline at end of file + - name: E2E Test (Smoke) (Windows) + if: ${{ inputs.smoke && matrix.os == 'windows' }} + run: | + $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" + $env:TMP_FOLDER = "${{ runner.temp }}" + $env:INPUT_TIMEOUT = "600" + java -version + bun test:e2e:smoke + - name: E2E Test (Full) (Windows) + if: ${{ !inputs.smoke && matrix.os == 'windows' }} + run: | + $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" + $env:TMP_FOLDER = "${{ runner.temp }}" + $env:INPUT_TIMEOUT = "600" + java -version + bun test:e2e \ No newline at end of file diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 9f48810..4bb2d41 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -38,4 +38,4 @@ jobs: if: always() uses: ./.github/workflows/e2e.yaml with: - smoke: true \ No newline at end of file + smoke: ${{ github.base_ref != 'main' }} \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit index 426d989..67ca653 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -6,4 +6,5 @@ if [ "$(git config --get custom.hooks.pre-commit)" == "false" ]; then exit 0 fi +bun build:dev bun lint-staged --relative diff --git a/e2e/scfz.test.ts b/e2e/scfz.test.ts index 0570f44..201ff46 100644 --- a/e2e/scfz.test.ts +++ b/e2e/scfz.test.ts @@ -1,5 +1,6 @@ import { afterAll, describe, expect, test } from "bun:test"; import { readdir } from "node:fs/promises"; +import { join } from "node:path"; import { $, type Subprocess, file, spawn } from "bun"; import stripAnsi from "strip-ansi"; import pkg from "../package.json"; @@ -11,7 +12,7 @@ const keypress = { SPACE: "\x20", }; -const INPUT_TIMEOUT = 400; +const INPUT_TIMEOUT = Number.parseInt(process.env.INPUT_TIMEOUT || "400", 10); const loop = ( process: Subprocess<"pipe", "pipe", "inherit">, @@ -35,8 +36,13 @@ const loop = ( } }; +const TMP_FOLDER = process.env.TMP_FOLDER || "/tmp"; + describe("e2e", () => { - const folder = `/tmp/test-${(1000 + Math.ceil(Math.random() * 1000)).toString(16)}`; + const folder = join( + TMP_FOLDER, + `test-${(1000 + Math.ceil(Math.random() * 1000)).toString(16)}`, + ); test("@smoke: should return the correct version", async () => { const proc = spawn(["dist/scfz", "--version"]); diff --git a/lib/generators/component.ts b/lib/generators/component.ts index 8b3f7d9..c85a01f 100644 --- a/lib/generators/component.ts +++ b/lib/generators/component.ts @@ -122,7 +122,7 @@ const generator: GeneratorDefinition = { type: "append", path: "architecture/components/{{kebabCase systemName}}--{{kebabCase containerName}}.dsl", createIfNotExists: true, - pattern: /[\s\S]*\n/, + pattern: /[\s\S]*\r?\n/, templateFile: "templates/components/component.hbs", } as AppendAction, { @@ -148,7 +148,7 @@ const generator: GeneratorDefinition = { `Component relationship for "${answers.containerName}" already included` ); }, - pattern: /.*{\n/, + pattern: /[\s\S]*{\r?\n/, templateFile: "templates/include.hbs", } as AppendAction, { diff --git a/lib/generators/container.ts b/lib/generators/container.ts index e8cf770..8162130 100644 --- a/lib/generators/container.ts +++ b/lib/generators/container.ts @@ -137,7 +137,7 @@ const generator: GeneratorDefinition = { `Container relationship for "${answers.systemName}" already included` ); }, - pattern: /.*\n!include.*/, + pattern: /.*\r?\n!include.*/, templateFile: "templates/include.hbs", } as AppendAction, { diff --git a/lib/generators/relationship.ts b/lib/generators/relationship.ts index 229e7e7..54b7617 100644 --- a/lib/generators/relationship.ts +++ b/lib/generators/relationship.ts @@ -107,7 +107,7 @@ const generator: GeneratorDefinition = { "No system relationships", type: "append", path: "architecture/relationships/_{{kebabCase elementType}}.dsl", - pattern: /\n.* -> .*\n/, + pattern: /\r?\n.* -> .*\r?\n/, templateFile: "templates/relationships/multiple.hbs", } as AppendAction, { @@ -119,7 +119,7 @@ const generator: GeneratorDefinition = { type: "append", createIfNotExists: true, path: "architecture/relationships/{{kebabCase systemName}}.dsl", - pattern: /[\s\S]*\n/, + pattern: /[\s\S]*\r?\n/, templateFile: "templates/relationships/multiple.hbs", } as AppendAction, { @@ -129,7 +129,7 @@ const generator: GeneratorDefinition = { Object.keys(answers.relationships).length <= 0 && "No component relationships", type: "append", - pattern: /[\s\S]*\n/, + pattern: /[\s\S]*\r?\n/, path: "architecture/relationships/{{kebabCase systemName}}.dsl", templateFile: "templates/relationships/multiple-component.hbs", } as AppendAction, diff --git a/lib/main.ts b/lib/main.ts index f6f495d..d720ae0 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -25,7 +25,7 @@ type CLIArguments = { }; const STRUCTURIZR_CLI_PATH = - process.env.STRUCTURIZR_CLI_PATH ?? "structurizr-cli"; + process.env.STRUCTURIZR_CLI_PATH || "structurizr-cli"; async function main(args: CLIArguments = { dest: "." }) { console.log( @@ -71,7 +71,8 @@ Let's create a new one by answering the questions below. ); process.exit(0); } catch (err) { - console.error(err); + console.error(chalk.red("[ERROR]:"), err?.toString()); + console.log(chalk.gray("[DEBUG]:"), err as Error); process.exit(1); } } diff --git a/package.json b/package.json index 99cff51..412ed7a 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,13 @@ "scfz": "lib/main.ts" }, "scripts": { - "build:dev": "bun build ./lib/main.ts --compile --watch --outfile ./dist/scfz", + "build:dev": "bun build ./lib/main.ts --compile --outfile ./dist/scfz", + "build:watch": "bun build:dev --watch", "test:dev": "bun test --watch", "test": "bun test", "test:ci": "bun test --coverage", - "test:e2e:smoke": "bun --config=./e2e/e2e.toml test -t '@smoke' --bail --timeout 15000", - "test:e2e": "bun --config=./e2e/e2e.toml test --bail --timeout 15000", + "test:e2e:smoke": "bun --config=./e2e/e2e.toml test -t '@smoke' --bail --timeout 30000", + "test:e2e": "bun --config=./e2e/e2e.toml test --bail --timeout 30000", "prepare": "husky" }, "trustedDependencies": [".", "@biomejs/biome"],