Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep: add unit test for the Fastify api #5

Closed
7 tasks done
jellydn opened this issue Sep 24, 2023 · 3 comments · Fixed by #14
Closed
7 tasks done

Sweep: add unit test for the Fastify api #5

jellydn opened this issue Sep 24, 2023 · 3 comments · Fixed by #14
Labels
sweep Sweep your software chores

Comments

@jellydn
Copy link
Owner

jellydn commented Sep 24, 2023

Describe the bug

Let's use bun test to run tests for Fastify API

Reproduction

Add a test on package.json to run unit tests

System Info

System:
    OS: macOS 14.0
    CPU: (12) arm64 Apple M2 Pro
    Memory: 1.10 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.20.0 - ~/Library/Caches/fnm_multishells/6820_1695544620557/bin/node
    Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/6820_1695544620557/bin/yarn
    npm: 8.19.4 - ~/Library/Caches/fnm_multishells/6820_1695544620557/bin/npm
    pnpm: 8.7.6 - ~/Library/Caches/fnm_multishells/6820_1695544620557/bin/pnpm
  Browsers:
    Chrome Canary: 119.0.6018.4
    Safari: 17.0

Used Package Manager

bun

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
Checklist
@sweep-ai sweep-ai bot added the sweep Sweep your software chores label Sep 24, 2023
@sweep-ai
Copy link
Contributor

sweep-ai bot commented Sep 24, 2023

Here's the PR! #14.

⚡ Sweep Free Trial: I'm creating this ticket using GPT-4. You have 3 GPT-4 tickets left for the month and 3 for the day. For more GPT-4 tickets, visit [our payment portal.](https://buy.stripe.com/6oE5npbGVbhC97afZ4)

Actions (click)

  • ↻ Restart Sweep

Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description.

{
"name": "stepci-demo",
"type": "module",
"module": "app.ts",
"scripts": {
"dev": "bun run --watch app.ts",
"build": "tsup app.ts --clean --format esm,cjs",
"ci": "run-p --race test:*",
"format": "prettier --write .",
"lint": "eslint . --ext .ts,.tsx",
"typecheck": "tsc --noEmit",
"test:server": "NODE_DEVELOPMENT=test bun run app.ts",
"test:e2e": "wait-on -l tcp:3000 && stepci run workflow.yml",
"generate": "stepci generate ./specs/openapi.yaml ./specs/generated.yaml",
"start": "bun app.ts",
"start:prod": "node dist/app.js"
},
"dependencies": {
"@fastify/cors": "8.4.0",
"@fastify/helmet": "11.1.1",
"@fastify/swagger": "8.10.1",
"@fastify/swagger-ui": "1.9.3",
"fastify": "4.23.2"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "4.2.0",
"@typescript-eslint/eslint-plugin": "6.7.3",
"@typescript-eslint/parser": "6.7.3",
"bun-types": "latest",
"eslint": "8.50.0",
"eslint-config-productsway": "1.3.0",
"npm-run-all": "4.1.5",
"prettier": "3.0.3",
"stepci": "2.6.8",
"tsup": "7.2.0",
"typescript": "5.2.2",
"wait-on": "7.0.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
}

stepci-demo/README.md

Lines 1 to 95 in a59fd06

<h1 align="center">A Comprehensive Guide to Fastify, Docker, and CI with StepCI 👋</h1>
![stepci-demo](https://socialify.git.ci/jellydn/stepci-demo/image?description=1&issues=1&language=1&logo=https%3A%2F%2Fstepci.com%2Flogo.svg&name=1&owner=1&pattern=Solid&pulls=1&stargazers=1&theme=Auto)
## Overview
Get up and running with a [Fastify](https://fastify.dev/docs/latest/Reference/TypeScript/) application, integrated with continuous testing via [Step CI](https://stepci.com/#get-started).
[![IT Man - A Comprehensive Guide to Fastify, Bun, and CI with StepCI [Vietnamese]](https://i.ytimg.com/vi/pgofbfmxMto/hqdefault.jpg)](https://www.youtube.com/watch?v=pgofbfmxMto)
## Prerequisites
- [Bun](https://bun.sh/) installed on your system.
- [antfu/ni](https://github.com/antfu/ni) 💡 Use the right package manager.
## Getting Started
1. **Clone the Repository**
```bash
git clone https://github.com/jellydn/stepci-demo.git
```
2. **Install Dependencies**
```bash
bun install
```
3. **Run Tests Locally**
```bash
bun run start
bun run test:e2e
```
![Demo](https://i.gyazo.com/10b1e6a520bac9044e4db5d5faacebb4.gif)
## Testing with Step CI
Choose from various methods to run your tests: Node, Docker, or GitHub Actions.
### Node
```bash
npx stepci run workflow.yml
```
### Docker
```bash
docker run \
-v "$(pwd)"/tests:/tests \
ghcr.io/stepci/stepci \
tests/workflow.yml
```
### GitHub Actions
```yaml
on: [push]
jobs:
api_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Step CI Action
uses: stepci/stepci@main
with:
workflow: "workflow.yml"
```
## Deployment with Koyeb
Easily deploy your Fastify application on the serverless platform [Koyeb](https://www.koyeb.com/docs/deploy/fastify).
## Additional Resources
- [Step CI Documentation](https://docs.stepci.com/guides/concepts.html)
- [Fastify TypeScript Documentation](https://fastify.dev/docs/latest/Reference/TypeScript/)
- [Bun 1.0 Release Blog](https://bun.sh/blog/bun-v1.0)
- [How to run GitHub Action locally with act.](https://github.com/jellydn/github-action-locally)
## Author
👤 **Huynh Duc Dung**
- Website: https://productsway.com/
- Twitter: [@jellydn](https://twitter.com/jellydn)
- Github: [@jellydn](https://github.com/jellydn)
## Show your support
If this guide has been helpful, please give it a ⭐️.
[![kofi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/dunghd)
[![paypal](https://img.shields.io/badge/PayPal-00457C?style=for-the-badge&logo=paypal&logoColor=white)](https://paypal.me/dunghd)

{
"swagger": "2.0",
"info": {
"title": "Test swagger",
"description": "Testing the Fastify swagger API",
"version": "0.1.0"
},
"definitions": {},
"paths": {
"/api": {
"get": {
"responses": {
"200": {
"description": "Default Response"
}
}
}
},
"/api/hello": {
"get": {
"responses": {
"200": {
"description": "Default Response"
}
}
}
},
"/api/ping": {
"get": {
"responses": {
"200": {
"description": "Default Response",
"schema": {
"type": "object",
"properties": {
"pong": {
"type": "string"
}
}
}
}
}
}
}
},
"host": "localhost:3000",
"schemes": ["http", "https"],
"consumes": ["application/json"],
"produces": ["application/json"],
"externalDocs": {
"url": "https://swagger.io",
"description": "Find more info here"
}

name

openapi: 3.0.1
info:
title: Test swagger
description: Testing the Fastify swagger API
version: 0.1.0
externalDocs:
description: Find more info here
url: https://swagger.io
servers:
- url: http://localhost:3000
paths:
/api:
get:
responses:
200:
description: Default Response
content: {}
/api/hello:
get:
responses:
200:
description: Successful response with a JSON object
content:
application/json:
schema:
type: string
description: Successful response with a JSON object
/api/ping:
get:
responses:
200:
description: Default Response
content:
application/json:
schema:
type: object
properties:
pong:
type: string

I also found the following external resources that might be helpful:

Summaries of links found in the content:

https://stackoverflow.com/help/minimal-reproducible-example:

The page titled "How to create a Minimal, Reproducible Example - Help Center" on Stack Overflow provides guidance on creating a minimal, reproducible example when asking a debugging question. It explains that including code as text in the question helps others provide better help. The guidelines for creating a minimal, reproducible example are as follows:

  1. Minimal: Use as little code as possible that still produces the same problem.
  2. Complete: Provide all parts someone else needs to reproduce your problem in the question itself.
  3. Reproducible: Test the code you're about to provide to make sure it reproduces the problem.

The page also provides tips on streamlining the example code, such as starting from scratch or removing code incrementally until the problem disappears. It emphasizes the importance of clarity and readability in the code example, including consistent naming, indentation, and code formatting.

Additionally, the page advises against using images of code and encourages copying the actual text from the code editor and formatting it as code. It suggests using individual code blocks for each file or snippet and providing descriptions for the purpose of each block. If the problem involves multiple technologies (e.g., HTML, CSS, JavaScript), code for all relevant parts should be included.

To ensure the problem is reproducible, the page recommends describing the problem in detail, including the expected behavior, error messages, and specific lines of code causing the issue. It suggests eliminating irrelevant issues and validating the example code to confirm it reproduces the problem.

In summary, the page provides comprehensive guidance on creating a minimal, reproducible example when asking a debugging question, with tips on code streamlining, clarity, completeness, and reproducibility.

https://github.com/antfu/.github/blob/main/CODE_OF_CONDUCT.md:

The page is a GitHub repository file for the CODE_OF_CONDUCT.md in the .github directory of the antfu user's repository. The file contains the Contributor Covenant Code of Conduct, which outlines the standards of behavior expected from contributors and maintainers in the project. It emphasizes creating an open and welcoming environment, free from harassment and discrimination. The code snippet provided in the problem description is unrelated to the content of the page.

https://github.com/antfu/contribute:

The page is a contribution guide for the antfu/contribute project on GitHub. It provides instructions and guidelines for contributing to the project. The specific problem mentioned in the user's query is not directly addressed in the page content. The page includes information on repository setup, available commands, sending pull requests, commit conventions, maintenance tasks, and references to related tools and configurations. However, there is no specific information on running tests with bun test or the mentioned system info and package manager.


Step 2: ⌨️ Coding

  • test/api.test.ts ✅ Commit fcc5058
• Import Fastify from 'fastify' at the top of the file. • Create a new instance of Fastify and assign it to a variable, say `app`. • Write a test for each endpoint in the Fastify API. Each test should send a request to the endpoint and check the response. • After all tests, close the Fastify instance.
Sandbox Execution Logs
trunk init 1/16 ✓
⡿ Downloading Trunk 1.16.0...
⡿ Downloading Trunk 1.16.0...
⢿ Downloading Trunk 1.16.0...
⣻ Downloading Trunk 1.16.0...
⣽ Downloading Trunk 1.16.0...
⣾ Downloading Trunk 1.16.0...
⣷ Downloading Trunk 1.16.0...
⣯ Downloading Trunk 1.16.0...
⣟ Downloading Trunk 1.16.0...
⡿ Downloading Trunk 1.16.0...
⢿ Downloading Trunk 1.16.0...
⣻ Downloading Trunk 1.16.0...
⣽ Downloading Trunk 1.16.0...
⣾ Downloading Trunk 1.16.0...
✔ Downloading Trunk 1.16.0... done
⡿ Verifying Trunk sha256...
✔ Verifying Trunk sha256... done
⡿ Unpacking Trunk...
✔ Unpacking Trunk... done




































✔ 12 linters were enabled (.trunk/trunk.yaml)
  actionlint 1.6.26 (2 github-workflow files)
  checkov 2.4.9 (1 docker, 4 json, 6 yaml files)
  eslint 8.50.0 (2 javascript, 3 typescript files)
  git-diff-check (24 files)
  hadolint 2.12.0 (1 docker file) (created .hadolint.yaml)
  markdownlint 0.37.0 (1 markdown file) (created .markdownlint.yaml)
  prettier 3.0.3 (2 javascript, 4 json, 1 markdown, 3 typescript, 6 yaml files)
  renovate 36.97.3 (1 renovate-config file)
  terrascan 1.18.3 (1 docker file)
  trivy 0.45.1 (1 docker, 6 yaml files)
  trufflehog 3.57.0 (24 files)
  yamllint 1.32.0 (6 yaml files) (created .yamllint.yaml)
Next Steps
 1. Read documentation
    Our documentation can be found at https://docs.trunk.io
 2. Get help and give feedback
    Join the Trunk community at https://slack.trunk.io
trunk fmt test/api.test.ts 2/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/enj0L.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 3/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/q7u5y.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 4/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/gD9C9.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 5/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/NG73y.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 6/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/ExcoV.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 7/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/PALFi.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 8/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/pcRyD.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 9/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/Voo3b.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 10/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/NASNe.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 11/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/2P1eT.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 12/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/V65Fg.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 13/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/snjR6.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 14/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/vddO3.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 15/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/t8TLm.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt test/api.test.ts 16/16 ❌ (`1`)
  FAILURES  
 prettier  test/api.test.ts  .trunk/out/EE4uM.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
• Add a new script named `test` in the `scripts` section. The value of this script should be `bun test`.
Sandbox Execution Logs
trunk init 1/16 ✓
⡿ Downloading Trunk 1.16.0...
⡿ Downloading Trunk 1.16.0...
⢿ Downloading Trunk 1.16.0...
⣻ Downloading Trunk 1.16.0...
⣽ Downloading Trunk 1.16.0...
⣾ Downloading Trunk 1.16.0...
⣷ Downloading Trunk 1.16.0...
⣯ Downloading Trunk 1.16.0...
⣟ Downloading Trunk 1.16.0...
⡿ Downloading Trunk 1.16.0...
⢿ Downloading Trunk 1.16.0...
⣻ Downloading Trunk 1.16.0...
⣽ Downloading Trunk 1.16.0...
⣾ Downloading Trunk 1.16.0...
⣷ Downloading Trunk 1.16.0...
✔ Downloading Trunk 1.16.0... done
⡿ Verifying Trunk sha256...
✔ Verifying Trunk sha256... done
⡿ Unpacking Trunk...
✔ Unpacking Trunk... done



































✔ 12 linters were enabled (.trunk/trunk.yaml)
  actionlint 1.6.26 (2 github-workflow files)
  checkov 2.4.9 (1 docker, 4 json, 6 yaml files)
  eslint 8.50.0 (2 javascript, 2 typescript files)
  git-diff-check (23 files)
  hadolint 2.12.0 (1 docker file) (created .hadolint.yaml)
  markdownlint 0.37.0 (1 markdown file) (created .markdownlint.yaml)
  prettier 3.0.3 (2 javascript, 4 json, 1 markdown, 2 typescript, 6 yaml files)
  renovate 36.97.3 (1 renovate-config file)
  terrascan 1.18.3 (1 docker file)
  trivy 0.45.1 (1 docker, 6 yaml files)
  trufflehog 3.57.0 (23 files)
  yamllint 1.32.0 (6 yaml files) (created .yamllint.yaml)
Next Steps
 1. Read documentation
    Our documentation can be found at https://docs.trunk.io
 2. Get help and give feedback
    Join the Trunk community at https://slack.trunk.io
trunk fmt package.json 2/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/i577h.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 3/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/LkcMc.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 4/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/WVy0w.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 5/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/0otWm.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 6/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/92tzb.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 7/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/xC7aw.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 8/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/Gu2Qa.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 9/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/RzKQv.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 10/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/yHQkV.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 11/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/Ij0Iu.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 12/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/ou5IP.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 13/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/FokBG.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 14/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/exOR5.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 15/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/V56Gf.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure
trunk fmt package.json 16/16 ❌ (`1`)
  FAILURES  
 prettier  package.json  .trunk/out/VLkVD.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 0 files
✖ No issues, 1 failure

Step 3: 🔁 Code Review

Here are my self-reviews of my changes at sweep/add-unit-test-for-fastify-api_2.

Here is the 1st review

Thanks for your contribution. There are a few changes that need to be made:

In test/api.test.ts:

  • Instead of just logging the status code and content type of the response, you should be asserting that these values are as expected. You can use a library like tap or assert to do this. For example, you could write assert.strictEqual(response.statusCode, 200) to check that the status code is 200.
  • You should add error handling in the callback functions. If err is not null, you should log the error and fail the test.

In package.json, no changes are required. The new test script is correctly implemented and should work as expected.

Keep up the good work!

I finished incorporating these changes.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.
Join Our Discord

@jellydn jellydn changed the title Sweep: add unit test for the Fastiffy api Sweep: add unit test for the Fastify api Sep 24, 2023
@jellydn
Copy link
Owner Author

jellydn commented Sep 24, 2023

Let's integrate with stepci runner

Using as a Library[#](https://docs.stepci.com/guides/using-library.html#using-as-a-library)
Step CI runner can be used independently in other Node projects

Install @stepci/runner dependency


npm install --save-dev @stepci/runner
Example: Run workflow from file

js
import { runFromFile } from '@stepci/runner'
runFromFile('./examples/status.yml').then(console.log)
Example: Run workflow from config

js
import { run } from '@stepci/runner'

const workflow = {
  version: "1.0",
  name: "Status Test",
  env: {
    host: "example.com"
  },
  tests: {
    example: {
      steps: [{
        name: "GET request",
        http: {
          url: "https://${{env.host}}",
          method: "GET",
          check: {
            status: "/^20/"
          }
        }
      }]
    }
  }
}

run(workflow).then(console.log)
INFO

See the runner repository for documentation and examples: https://github.com/stepci/runner

@jellydn
Copy link
Owner Author

jellydn commented Sep 26, 2023

Let's write test with bun:test. Here is the usage.

Define tests with a Jest-like API imported from the built-in bun:test module. Long term, Bun aims for complete Jest compatibility; at the moment, a limited set of expect matchers are supported.

Basic usage
To define a simple test:

math.test.ts
import { expect, test } from "bun:test";

test("2 + 2", () => {
  expect(2 + 2).toBe(4);
});

Tests can be grouped into suites with describe.

math.test.ts
import { expect, test, describe } from "bun:test";

describe("arithmetic", () => {
  test("2 + 2", () => {
    expect(2 + 2).toBe(4);
  });

  test("2 * 2", () => {
    expect(2 * 2).toBe(4);
  });
});

Tests can be async.

import { expect, test } from "bun:test";

test("2 * 2", async () => {
  const result = await Promise.resolve(2 * 2);
  expect(result).toEqual(4);
});

Alternatively, use the done callback to signal completion. If you include the done callback as a parameter in your test definition, you must call it or the test will hang.

import { expect, test } from "bun:test";

test("2 * 2", done => {
  Promise.resolve(2 * 2).then(result => {
    expect(result).toEqual(4);
    done();
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment