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

feat: add store export #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions package-e2e/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
$Story,
$Tag,
$TmsLink,
allure,
} from 'jest-allure2-reporter/api';
allure, AllureRuntime
} from "jest-allure2-reporter/api";

import type {
AllureRuntimePluginCallback,
Expand All @@ -26,7 +26,6 @@ import type {
FileAttachmentContext,
FileAttachmentHandler,
FileAttachmentOptions,
IAllureRuntime,
MIMEInferer,
MIMEInfererContext,
UserParameter,
Expand All @@ -51,9 +50,9 @@ $Severity('critical');
$Tag('e2e');
$TmsLink('TEST-456');
test('typings of jest-allure2-reporter/api', async () => {
assertType<IAllureRuntime>(allure);
assertType<IAllureRuntime>(allure.$bind());
assertType<IAllureRuntime>(allure.$bind({ metadata: false, time: true }));
assertType<AllureRuntime>(allure);
assertType<AllureRuntime>(allure.$bind());
assertType<AllureRuntime>(allure.$bind({ metadata: false, time: true }));
allure.description('This is a _description_ generated in runtime');
allure.descriptionHtml('This is a <i>description</i> generated in runtime');
allure.historyId('00-11-22-33-44-55');
Expand Down Expand Up @@ -201,7 +200,7 @@ function enablePlugins() {
assertType<AttachmentContent>(Buffer.from('content'));

const plugin: AllureRuntimePluginCallback = (context: AllureRuntimePluginContext) => {
assertType<IAllureRuntime>(context.runtime);
assertType<AllureRuntime>(context.runtime);
context.contentAttachmentHandlers['custom'] = customContent;
context.fileAttachmentHandlers['custom'] = customFile;
context.inferMimeType = inferMimeType;
Expand Down
23 changes: 23 additions & 0 deletions package-e2e/store.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { AllureContainer, AllureStore, AllureReader, AllureWriter, fromConfig, fromDirectory } from 'jest-allure2-reporter/store';

declare function assertType<T>(value: T): T;

assertType<AllureContainer>({
uuid: 'fake-uuid',
name: 'fake-name',
children: [],
});

assertType<typeof AllureStore>(AllureStore);
assertType<(options: { reader: AllureReader; writer: AllureWriter }) => Promise<AllureStore>>(fromConfig);
assertType<(options: { resultsDir: string; overwrite: boolean }) => Promise<AllureStore>>(fromDirectory);

// Optional: You can perform a minimal runtime check if you have proper mocks/stubs.
(async () => {
const fakeReaderWriter = { reader: {}, writer: {} } as any;
const store = await fromConfig(fakeReaderWriter);
assertType<AllureStore>(store);

const store2 = await fromDirectory({ resultsDir: 'fake/resultsDir' } as any);
assertType<AllureStore>(store2);
})();
5 changes: 5 additions & 0 deletions package-e2e/test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ assert(typeof Attachment === 'function', 'jest-allure2-reporter should export At
assert(typeof $Owner === 'function', 'jest-allure2-reporter should export $Owner function as a named export');
assert(typeof allure === 'object', 'jest-allure2-reporter should export allure object as a named export');

const { AllureStore, fromConfig, fromDirectory } = require('jest-allure2-reporter/store');
assert(typeof AllureStore === 'function', 'AllureStore should be a function (class)');
assert(typeof fromConfig === 'function', 'fromConfig should be a function');
assert(typeof fromDirectory === 'function', 'fromDirectory should be a function');

function isClass(obj) {
return typeof obj === 'function' && /^class\s/.test(Function.prototype.toString.call(obj));
}
4 changes: 4 additions & 0 deletions package-e2e/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import environmentListener from 'jest-allure2-reporter/environment-listener';
import JsdomTestEnvironment from 'jest-allure2-reporter/environment-jsdom';
import NodeTestEnvironment from 'jest-allure2-reporter/environment-node';
import { Attachment, $Owner, allure } from 'jest-allure2-reporter/api';
import { AllureStore, fromConfig, fromDirectory } from 'jest-allure2-reporter/store';

assert(isClass(JestAllure2Reporter), 'jest-allure2-reporter should export a class as its default export');
assert(typeof environmentListener === 'function', 'jest-allure2-reporter/environment-listener should export a class as its default export');
Expand All @@ -12,6 +13,9 @@ assert(isClass(NodeTestEnvironment), 'jest-allure2-reporter/environment-node sho
assert(typeof allure === 'object', 'jest-allure2-reporter should export allure object as a named export');
assert(typeof Attachment === 'function', 'jest-allure2-reporter should export Attachment decorator as a named export');
assert(typeof $Owner === 'function', 'jest-allure2-reporter should export $Owner function as a named export');
assert(typeof AllureStore === 'function', 'AllureStore should be a function (class)');
assert(typeof fromConfig === 'function', 'fromConfig should be a function');
assert(typeof fromDirectory === 'function', 'fromDirectory should be a function');

function isClass(obj) {
return typeof obj === 'function' && /^class\s/.test(Function.prototype.toString.call(obj));
Expand Down
2 changes: 1 addition & 1 deletion package-e2e/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function assertType<T>(_actual: T): void {

const reporter = new Reporter({} as any, {} as any);
assertType<Promise<void>>(reporter.onRunStart({} as any, {} as any));
assertType<Reporter>(reporter);
assertType<Reporter>(repgorter);
// assertType<object>(Reporter.query);
assertType<ReporterOptions>({
overwrite: false,
Expand Down
1 change: 1 addition & 0 deletions package-e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"files": [
"api.test.ts",
"globals.test.ts",
"store.test.ts",
"test.ts"
],
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
"require": "./environment-node.js",
"types": "./dist/environment/node.d.ts"
},
"./store": {
"import": "./store.mjs",
"require": "./store.js",
"types": "./dist/store/index.d.ts"
},
"./package.json": "./package.json"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/JestAllure2Reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {
import { type ReporterConfig, resolveOptions } from '../options';
import { AllureMetadataProxy, MetadataSquasher } from '../metadata';
import { compactArray, FileNavigatorCache, stringifyValues } from '../utils';
import { type AllureWriter, FileAllureWriter } from '../serialization';
import { type AllureWriter, FileAllureWriter } from '../store';
import { log, optimizeForTracing } from '../logger';

import * as fallbacks from './fallbacks';
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/allure-adapter/toTestContainer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AllureTestCaseResult } from 'jest-allure2-reporter';
import { v5 } from 'uuid';

import type { AllureContainer } from '../../serialization';
import type { AllureContainer } from '../../store';

import { toTestStep } from './toTestStep';

Expand Down
2 changes: 1 addition & 1 deletion src/reporter/allure-adapter/toTestResult.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AllureTestCaseResult } from 'jest-allure2-reporter';

import type { AllureResult as Serialized } from '../../serialization';
import type { AllureResult as Serialized } from '../../store';

import { ensureUUID } from './ensureUUID';
import { hashHistoryId } from './hashHistoryId';
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/allure-adapter/toTestStep.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AllureTestStepResult } from 'jest-allure2-reporter';

import type { AllureStep as Serialized } from '../../serialization';
import type { AllureStep as Serialized } from '../../store';

import { normalizeAttachments } from './normalizeAttachments';
import { normalizeParameters } from './normalizeParameters';
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/allureCommons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AllureTestCaseResult } from 'jest-allure2-reporter';

import type { AllureWriter } from '../serialization';
import type { AllureWriter } from '../store';

import { toTestContainer, toTestResult } from './allure-adapter';

Expand Down
2 changes: 0 additions & 2 deletions src/serialization/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/serialization/types.d.ts

This file was deleted.

50 changes: 50 additions & 0 deletions src/store/AllureReader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { Category, ExecutorInfo } from 'jest-allure2-reporter';

import type { AllureContainer, AllureResult } from './types';

export interface AllureReader {
/**
* (Optional) Initializes the reader.
*/
init?(): Promise<void>;

/**
* (Optional) Cleans up any resources used by the reader.
*/
cleanup?(): Promise<void>;

/**
* Returns identifiers for available containers
*/
getContainerIds(): Promise<string[]>;

/**
* Returns identifiers for available results
*/
getResultIds(): Promise<string[]>;

/**
* Reads a container by ID.
*/
readContainer(id: string): Promise<AllureContainer | null>;

/**
* Reads a result by ID.
*/
readResult(id: string): Promise<AllureResult | null>;

/**
* Reads the categories from the categories.json file.
*/
readCategories(): Promise<Category[] | null>;

/**
* Reads the environment information from the environment.properties file.
*/
readEnvironmentInfo(): Promise<Record<string, string> | null>;

/**
* Reads the executor information from the executor.json file.
*/
readExecutorInfo(): Promise<ExecutorInfo | null>;
}
Loading
Loading