Skip to content

Commit

Permalink
add vitest integration (fixes #415, via #830)
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw committed Jan 17, 2024
1 parent 9883916 commit f8335b3
Show file tree
Hide file tree
Showing 115 changed files with 4,008 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,173 changes: 1,173 additions & 0 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions .yarnrc.yml
Expand Up @@ -23,4 +23,18 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

supportedArchitectures:
os:
- current
- darwin
- linux
cpu:
- current
- x64
- arm64
libc:
- current
- glibc
- musl

yarnPath: .yarn/releases/yarn-3.6.3.cjs
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -14,7 +14,7 @@
"lint": "yarn workspaces foreach -vpt run lint",
"lint:fix": "yarn workspaces foreach -vpt run lint:fix",
"test": "yarn workspaces foreach -vpt run test",
"test:node-14": "yarn workspaces foreach -vpt --exclude allure-js --exclude allure-hermione run test",
"test:node-14": "yarn workspaces foreach -vpt --exclude allure-js --exclude allure-vitest --exclude allure-hermione run test",
"build": "yarn run clean && yarn run compile"
},
"lint-staged": {
Expand Down
4 changes: 2 additions & 2 deletions packages/allure-js-commons/src/AllureCommandStep.ts
Expand Up @@ -83,7 +83,7 @@ export class AllureCommandStepExecutable implements AllureCommandStep {
steps: [],
};

if (stepMetadata.attachments.length > 0) {
if (stepMetadata.attachments?.length > 0) {
stepMetadata.attachments.forEach((attachment) => {
const attachmentContent = Buffer.from(attachment.content, attachment.encoding);
const attachmentFilename = runtime.writeAttachment(
Expand All @@ -100,7 +100,7 @@ export class AllureCommandStepExecutable implements AllureCommandStep {
});
}

if (stepMetadata.steps.length > 0) {
if (stepMetadata.steps?.length > 0) {
executable.steps = stepMetadata.steps.map((nestedStep) =>
AllureCommandStepExecutable.toExecutableItem(runtime, nestedStep),
);
Expand Down
1 change: 1 addition & 0 deletions packages/allure-js-commons/src/ExecutableItemWrapper.ts
Expand Up @@ -84,6 +84,7 @@ export class ExecutableItemWrapper {
if (typeof options === "string") {
options = { contentType: options };
}

this.info.attachments.push({ name, type: options.contentType, source: fileName });
}

Expand Down
4 changes: 2 additions & 2 deletions packages/allure-playwright/test/fixtures.ts
Expand Up @@ -16,7 +16,7 @@

import { fork } from "child_process";
import { mkdir, writeFile } from "fs/promises";
import { join, dirname } from "path";
import { dirname, join } from "path";
import { test as base, TestInfo } from "@playwright/test";
import type { AllureResults } from "allure-js-commons";
import { parse } from "properties";
Expand All @@ -31,9 +31,9 @@ type Env = { [key: string]: string | number | boolean | undefined };

const writeFiles = async (testInfo: TestInfo, files: Files) => {
const baseDir = testInfo.outputPath();

const hasConfig = Object.keys(files).some((name) => name.includes(".config."));
const reporterOptions = files.reporterOptions && JSON.parse(files.reporterOptions.toString());

if (!hasConfig) {
files = {
...files,
Expand Down
1 change: 1 addition & 0 deletions packages/allure-vitest/.gitignore
@@ -0,0 +1 @@
test/spec/fixtures/
92 changes: 92 additions & 0 deletions packages/allure-vitest/README.md
@@ -0,0 +1,92 @@
# vitest-allure

> Allure framework integration for [Vitest](https://vitest.dev/) framework
<img src="https://allurereport.org/public/img/allure-report.svg" height="85px" alt="Allure Report logo" align="right" />

- Learn more about Allure Report at https://allurereport.org
- 📚 [Documentation](https://allurereport.org/docs/) – discover official documentation for Allure Report
-[Questions and Support](https://github.com/orgs/allure-framework/discussions/categories/questions-support) – get help from the team and community
- 📢 [Official annoucements](https://github.com/orgs/allure-framework/discussions/categories/announcements) – be in touch with the latest updates
- 💬 [General Discussion ](https://github.com/orgs/allure-framework/discussions/categories/general-discussion) – engage in casual conversations, share insights and ideas with the community

---

## Installation

```bash
npm i -D vitest allure-vitest
```

or via yarn:

```bash
yarn add -D vitest allure-vitest
```

## Configuration

Add instance of the reporter to the [`reporters` section](https://vitest.dev/config/#reporters) of your Vitest config:

```js
import AllureReporter from "allure-vitest";
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
// add setup file to be able to use Allure API via `this.allure` in your tests
setupFiles: ["allure-vitest/setup],
reporters: [
// do not forget to keep the "default" if you want to see something in the console
"default",
new AllureReporter({
links: [
{
type: "issue",
urlTemplate: "https://example.org/issue/%s",
},
{
type: "tms",
urlTemplate: "https://example.org/task/%s",
},
],
resultsDir: "./allure-results",
}),
],
},
});
```

## Reporter options

Some reporter settings can set by following options:

| Option | Description | Default |
| ---------- | ----------------------------------------------------- | ------------------ |
| resultsDir | Path to results folder | `./allure-results` |
| links | Links templates to make runtime methods calls simpler | `undefined` |

## API

If you use setup file shipped by the integration, use `this.allure` to get access
to Allure Runtime API:

```js
import { test } from "vitest";

test("sample test", async () => {
await this.allure.label("foo", "bar");
});
```

Additionally, you can call Allure Runtime API methods directly passing the
context argument to the method:

```js
import { test } from "vitest";
import * as allure from "allure-vitest";

test("sample test", async (context) => {
await allure.label(context, "foo", "bar");
});
```
64 changes: 64 additions & 0 deletions packages/allure-vitest/package.json
@@ -0,0 +1,64 @@
{
"name": "allure-vitest",
"version": "2.10.0",
"description": "Allure Vitest integration",
"license": "Apache-2.0",
"homepage": "https://allurereport.org/",
"author": {
"name": "Qameta Software",
"email": "allure@qameta.io",
"url": "https://qameta.io/"
},
"repository": {
"type": "git",
"url": "https://github.com/allure-framework/allure-js.git",
"directory": "packages/allure-vitest"
},
"keywords": [
"vitest",
"typescript",
"allure"
],
"type": "module",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"files": [
"dist"
],
"exports": {
".": "./dist/src/index.js",
"./setup": "./dist/src/setup.js",
"./reporter": "./dist/src/reporter.js"
},
"scripts": {
"clean": "rimraf ./dist ./out",
"compile": "tsc",
"generate-report": "allure generate ./out/allure-results -o ./out/allure-report --clean",
"allure-report": "allure serve ./out/allure-results",
"pretest": "run compile",
"test": "vitest run --dir ./test/spec --config ./vitest.config.ts",
"lint": "eslint ./src --ext .ts",
"lint:fix": "eslint ./src --ext .ts --fix"
},
"dependencies": {
"allure-js-commons": "workspace:*"
},
"devDependencies": {
"@types/eslint": "^8",
"@types/node": "^20.6.3",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsdoc": "^46.6.0",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"glob": "^10.3.10",
"npm-run-all": "^4.1.5",
"rimraf": "^5.0.1",
"typescript": "^5.2.2",
"vite": "^5.0.11",
"vitest": "^1.1.3"
}
}

0 comments on commit f8335b3

Please sign in to comment.