Skip to content

Commit 46fdaf6

Browse files
formaceft-93epszawgithub-advanced-security[bot]
authored
added bun integration (#1446)
Co-authored-by: epszaw <konstantin@epishev.me> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 61c82d8 commit 46fdaf6

47 files changed

Lines changed: 5982 additions & 854 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ jobs:
131131
run: |
132132
yarn install --immutable --immutable-cache
133133
134+
- name: Setup Bun
135+
if: ${{ matrix.suite.id == 'midweight' }}
136+
uses: oven-sh/setup-bun@v2
137+
with:
138+
bun-version: 1.3.11
139+
134140
- name: Compile suite dependencies
135141
run: |
136142
node ./scripts/ci/run-suite.mjs compile ${{ matrix.suite.id }}

.pnp.cjs

Lines changed: 854 additions & 825 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ This repository is currently validated in CI on:
5151
Minimum supported framework versions by package:
5252

5353
- `allure-codeceptjs`: `codeceptjs >= 2.3.6`
54+
- `allure-bun`: Bun test
5455
- `allure-cucumberjs`: `@cucumber/cucumber >= 10.8.0`
5556
- `allure-cypress`: `cypress >= 12.17.4`
5657
- `allure-jasmine`: `jasmine >= 2.7.0`
@@ -101,6 +102,12 @@ npx allure open ./allure-report
101102

102103
[Read more](/packages/allure-jest/README.md)
103104

105+
### Bun
106+
107+
![npm](https://img.shields.io/npm/dm/allure-bun.svg) ![npm](https://img.shields.io/npm/v/allure-bun.svg)
108+
109+
[Read more](/packages/allure-bun/README.md)
110+
104111
### Jasmine
105112

106113
![npm](https://img.shields.io/npm/dm/allure-jasmine.svg) ![npm](https://img.shields.io/npm/v/allure-jasmine.svg)

packages/allure-bun/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vitest.config.ts.timestamp-*

packages/allure-bun/README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# allure-bun
2+
3+
> Allure framework integration for Bun test
4+
5+
[<img src="https://allurereport.org/public/img/allure-report.svg" height="85px" alt="Allure Report logo" align="right" />](https://allurereport.org "Allure Report")
6+
7+
- Learn more about Allure Report at https://allurereport.org
8+
- Documentation is available at https://allurereport.org/docs/
9+
- Questions and support are available at https://github.com/orgs/allure-framework/discussions/categories/questions-support
10+
11+
## Installation
12+
13+
Install `allure-bun` using a package manager of your choice. For example:
14+
15+
```shell
16+
npm install -D allure-bun allure-js-commons
17+
```
18+
19+
Keep `allure-bun` and `allure-js-commons` on the same version.
20+
21+
## Usage
22+
23+
Bun support is provided through Bun's documented preload hook. Keep your test imports unchanged and preload `allure-bun/setup` from `bunfig.toml`:
24+
25+
```toml
26+
[test]
27+
preload = ["allure-bun/setup"]
28+
```
29+
30+
Example:
31+
32+
```ts
33+
import { describe, expect, it } from "bun:test";
34+
import { label, step } from "allure-js-commons";
35+
36+
describe("signing in", () => {
37+
it("works", async () => {
38+
await label("severity", "critical");
39+
await step("submit form", async () => {});
40+
41+
expect(1 + 1).toBe(2);
42+
});
43+
});
44+
```
45+
46+
When the test run completes, the result files will be generated in the `./allure-results` directory.
47+
48+
## Configuration
49+
50+
`allure-bun/setup` accepts the common Allure reporter configuration through `globalThis.allureBunConfig` or the `ALLURE_BUN_CONFIG` environment variable. Use a custom preload when you need values that JSON can't represent, such as listener functions or link-template functions:
51+
52+
```ts
53+
import type { ReporterConfig } from "allure-js-commons/sdk/reporter";
54+
55+
globalThis.allureBunConfig = {
56+
resultsDir: "allure-results",
57+
environmentInfo: {
58+
bun: Bun.version,
59+
},
60+
globalLabels: {
61+
layer: "api",
62+
},
63+
links: {
64+
issue: {
65+
urlTemplate: "https://issues.example/%s",
66+
},
67+
},
68+
} satisfies ReporterConfig;
69+
70+
await import("allure-bun/setup");
71+
```
72+
73+
## Notes
74+
75+
- `allure-bun/setup` uses Bun preload and is not a Jest environment.
76+
- Keep using Bun's regular test API in test files, including hooks, `.each`, and supported non-concurrent modifiers.
77+
- Concurrent Bun execution is not supported. `test.concurrent`, `test.concurrent.each`, and `bun test --concurrent` fail fast with a descriptive error.
78+
- Randomized Bun execution is not supported. `bun test --randomize` fails fast because Bun doesn't expose the current test identity to `beforeEach` hooks.
79+
- Test-plan selection is handled while Bun tests are registered. Excluded test and hook bodies are not invoked, but top-level module code and `describe(...)` registration callbacks still run.
80+
81+
## View the report
82+
83+
Use Allure Report 2:
84+
85+
```bash
86+
allure generate ./allure-results -o ./allure-report
87+
allure open ./allure-report
88+
```
89+
90+
Or use Allure Report 3:
91+
92+
```bash
93+
npx allure generate ./allure-results
94+
npx allure open ./allure-report
95+
```

packages/allure-bun/babel.cjs.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-typescript",
5+
{
6+
"rewriteImportExtensions": true
7+
}
8+
],
9+
["@babel/preset-env", { "modules": "commonjs" }]
10+
],
11+
"plugins": ["babel-plugin-add-module-exports"],
12+
"targets": {
13+
"esmodules": false,
14+
"node": 18
15+
}
16+
}

packages/allure-bun/babel.esm.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-typescript",
5+
{
6+
"rewriteImportExtensions": true
7+
}
8+
],
9+
["@babel/preset-env", { "modules": false }]
10+
],
11+
"targets": {
12+
"esmodules": true,
13+
"node": 18
14+
}
15+
}

packages/allure-bun/package.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "allure-bun",
3+
"version": "3.7.1",
4+
"description": "Allure Bun integration",
5+
"keywords": [
6+
"allure",
7+
"bun",
8+
"html",
9+
"report",
10+
"reporter",
11+
"test",
12+
"testing",
13+
"testops"
14+
],
15+
"homepage": "https://allurereport.org/",
16+
"license": "Apache-2.0",
17+
"author": {
18+
"name": "Qameta Software",
19+
"email": "allure@qameta.io",
20+
"url": "https://qameta.io/"
21+
},
22+
"repository": {
23+
"type": "git",
24+
"url": "https://github.com/allure-framework/allure-js.git",
25+
"directory": "packages/allure-bun"
26+
},
27+
"files": [
28+
"dist"
29+
],
30+
"exports": {
31+
"./setup": {
32+
"types": "./dist/types/setup.d.ts",
33+
"import": "./dist/esm/setup.js",
34+
"require": "./dist/cjs/setup.js"
35+
}
36+
},
37+
"scripts": {
38+
"allure-report": "allure serve ./out/allure-results",
39+
"clean": "rimraf ./dist ./out",
40+
"compile": "run-s 'compile:*'",
41+
"compile:esm-babel": "babel --config-file ./babel.esm.json ./src --out-dir ./dist/esm --extensions '.ts' --source-maps",
42+
"compile:cjs-babel": "babel --config-file ./babel.cjs.json ./src --out-dir ./dist/cjs --extensions '.ts' --source-maps",
43+
"compile:types": "tsc",
44+
"compile:fixup": "node ./scripts/fixup.mjs",
45+
"generate-report": "allure generate ./out/allure-results -o ./out/allure-report --clean",
46+
"lint": "oxlint --import-plugin src test",
47+
"lint:fix": "oxlint --import-plugin --fix src test",
48+
"pretest": "yarn workspace allure-js-commons compile && yarn run compile",
49+
"test": "vitest run"
50+
},
51+
"dependencies": {
52+
"allure-js-commons": "workspace:*"
53+
},
54+
"devDependencies": {
55+
"@babel/cli": "^7.28.0",
56+
"@babel/core": "^7.28.0",
57+
"@babel/preset-env": "^7.28.0",
58+
"@babel/preset-typescript": "^7.27.1",
59+
"@types/babel__core": "^7.20.5",
60+
"@types/babel__preset-env": "^7.10.0",
61+
"@types/node": "^20.19.0",
62+
"allure-commandline": "^2.29.0",
63+
"allure-vitest": "workspace:*",
64+
"babel-plugin-add-module-exports": "^1.0.4",
65+
"npm-run-all2": "^8.0.0",
66+
"rimraf": "^6.0.0",
67+
"typescript": "^5.2.2",
68+
"vitest": "^4.0.18"
69+
}
70+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { mkdirSync, writeFileSync } from "node:fs";
2+
import { join, resolve } from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
const dirname = fileURLToPath(new URL(".", import.meta.url));
6+
const esmBuildPath = resolve(dirname, "../dist/esm");
7+
const cjsBuildPath = resolve(dirname, "../dist/cjs");
8+
9+
try {
10+
mkdirSync(esmBuildPath, { recursive: true });
11+
} catch (err) {}
12+
13+
try {
14+
mkdirSync(cjsBuildPath, { recursive: true });
15+
} catch (err) {}
16+
17+
writeFileSync(
18+
join(esmBuildPath, "package.json"),
19+
JSON.stringify(
20+
{
21+
type: "module",
22+
},
23+
null,
24+
2,
25+
),
26+
"utf8",
27+
);
28+
writeFileSync(
29+
join(cjsBuildPath, "package.json"),
30+
JSON.stringify(
31+
{
32+
type: "commonjs",
33+
},
34+
null,
35+
2,
36+
),
37+
"utf8",
38+
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const TODO_MESSAGE = "TODO";
2+
export const TODO_UNEXPECTED_PASS_MESSAGE =
3+
"This test is marked as todo but passes. Remove `.todo` if tested behavior now works.";
4+
export const FAILING_UNEXPECTED_PASS_MESSAGE =
5+
"This test is marked as failing but it passed. Remove `.failing` if tested behavior now works.";
6+
export const CONCURRENT_UNSUPPORTED_MESSAGE = "allure-bun does not support concurrent tests";
7+
export const RANDOMIZE_UNSUPPORTED_MESSAGE = "allure-bun does not support randomized test order";

0 commit comments

Comments
 (0)