Skip to content

Commit

Permalink
ci(e2e): fix windows tests (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreszorro authored Nov 21, 2024
2 parents 186078d + b908efa commit e8b257f
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 26 deletions.
36 changes: 24 additions & 12 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
- 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
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
if: always()
uses: ./.github/workflows/e2e.yaml
with:
smoke: true
smoke: ${{ github.base_ref != 'main' }}
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ if [ "$(git config --get custom.hooks.pre-commit)" == "false" ]; then
exit 0
fi

bun build:dev
bun lint-staged --relative
10 changes: 8 additions & 2 deletions e2e/scfz.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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">,
Expand All @@ -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"]);
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const generator: GeneratorDefinition<ComponentAnswers> = {
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<ComponentAnswers>,
{
Expand All @@ -148,7 +148,7 @@ const generator: GeneratorDefinition<ComponentAnswers> = {
`Component relationship for "${answers.containerName}" already included`
);
},
pattern: /.*{\n/,
pattern: /[\s\S]*{\r?\n/,
templateFile: "templates/include.hbs",
} as AppendAction<ComponentAnswers>,
{
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const generator: GeneratorDefinition<ContainerAnswers> = {
`Container relationship for "${answers.systemName}" already included`
);
},
pattern: /.*\n!include.*/,
pattern: /.*\r?\n!include.*/,
templateFile: "templates/include.hbs",
} as AppendAction<ContainerAnswers>,
{
Expand Down
6 changes: 3 additions & 3 deletions lib/generators/relationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const generator: GeneratorDefinition<RelationshipAnswers> = {
"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<RelationshipAnswers>,
{
Expand All @@ -119,7 +119,7 @@ const generator: GeneratorDefinition<RelationshipAnswers> = {
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<RelationshipAnswers>,
{
Expand All @@ -129,7 +129,7 @@ const generator: GeneratorDefinition<RelationshipAnswers> = {
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<RelationshipAnswers>,
Expand Down
5 changes: 3 additions & 2 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
}
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit e8b257f

Please sign in to comment.