Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Commit

Permalink
feat(allure-node-environment.ts): added testPath config option
Browse files Browse the repository at this point in the history
This alows users to specify an exact path that will specify where Allure begins to break tests into
suites.
  • Loading branch information
ryparker committed Jan 2, 2021
1 parent 6eef967 commit bf787c3
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 132 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Options that can be passed into the `environmentOptions` property of your `jest.
| tmsUrl | Decorator that receives Allure test result objects. | `undefined` |
| environmentInfo | Key value pairs that will appear under the environment section of the Allure report | `{}` |
| categoryDefinitions | Array of custom categories you wish to see in the Allure report | `[]` |
| testPath | Path to your test files. This path will be subtracted from the Allure report when organizing tests into suites. | `Jest.config.rootDir` |

## 📈 DocBlocks

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@jest/environment": "^26.6.2",
"@jest/reporters": "^26.6.2",
"@jest/types": "^26.6.2",
"allure-js-commons": "2.0.0-beta.8",
"allure-js-commons": "2.0.0-beta.9",
"ansi_up": "^4.0.4",
"crypto": "^1.0.1",
"jest-circus": "^26.6.3",
Expand All @@ -90,8 +90,8 @@
"@types/allure-js-commons": "^0.0.1",
"@types/highlight.js": "^10.1.0",
"@types/jest": "^26.0.19",
"@types/lodash": "^4.14.165",
"@types/node": "^14.14.14",
"@types/lodash": "^4.14.167",
"@types/node": "^14.14.19",
"commitizen": "^4.2.2",
"conventional-changelog-conventionalcommits": "^4.5.0",
"cz-conventional-changelog": "3.3.0",
Expand All @@ -100,7 +100,7 @@
"husky": "^4.3.6",
"jest": "^26.6.3",
"lint-staged": "^10.5.3",
"semantic-release": "^17.3.0",
"semantic-release": "^17.3.1",
"typescript": "^4.1.3",
"xo": "^0.36.1"
},
Expand Down
43 changes: 29 additions & 14 deletions src/allure-node-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,53 @@ export default class AllureNodeEnvironment extends NodeEnvironment {
private readonly reporter: AllureReporter;
private readonly testPath: string;
private readonly testFileName: string;
private readonly docblockPragmas?: Record<string, string | string[]>;

constructor(config: Config.ProjectConfig, context: EnvironmentContext) {
super(config);

const allureConfig: IAllureConfig = {
resultsDir: config.testEnvironmentOptions.resultsDir as string ?? 'allure-results'
};
if (typeof config.testEnvironmentOptions.testPath === 'string') {
this.testPath = config.testEnvironmentOptions.testPath;
}

this.testPath = this.initializeTestPath(config, context);

this.testFileName = basename(this.testPath);

this.reporter = this.initializeAllureReporter(config);

this.global.allure = this.reporter.getImplementation();
}

this.testPath = context.testPath ? context.testPath.replace(config.rootDir, '') : '';
initializeTestPath(config: Config.ProjectConfig, context: EnvironmentContext) {
let testPath = context.testPath ?? '';

if (this.testPath.includes('/tests/')) {
this.testPath = this.testPath.split('tests/')[1];
if (typeof config.testEnvironmentOptions.testPath === 'string') {
testPath = testPath?.replace(config.testEnvironmentOptions.testPath, '');
}

if (this.testPath.includes('/__tests__/')) {
this.testPath = this.testPath.split('__tests__/')[1];
if (typeof config.testEnvironmentOptions.testPath !== 'string') {
testPath = testPath?.replace(config.rootDir, '');
}

this.testFileName = basename(this.testPath);
if (testPath.startsWith('/')) {
testPath = testPath.slice(1);
}

return testPath;
}

this.docblockPragmas = context.docblockPragmas;
initializeAllureReporter(config: Config.ProjectConfig) {
const allureConfig: IAllureConfig = {
resultsDir: config.testEnvironmentOptions.resultsDir as string ?? 'allure-results'
};

this.reporter = new AllureReporter({
return new AllureReporter({
allureRuntime: new AllureRuntime(allureConfig),
jiraUrl: config.testEnvironmentOptions?.jiraUrl as string,
tmsUrl: config.testEnvironmentOptions?.tmsUrl as string,
environmentInfo: config.testEnvironmentOptions?.environmentInfo as Record<string, any>,
categoryDefinitions: config.testEnvironmentOptions?.categories as Array<Record<string, any>>
});

this.global.allure = this.reporter.getImplementation();
}

async setup() {
Expand Down
2 changes: 1 addition & 1 deletion src/allure-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export default class AllureReporter {
}

if (!message) {
message = 'Unformatted error. Expand for more details.';
message = 'Error. Expand for more details.';
trace = error;
}

Expand Down
Loading

0 comments on commit bf787c3

Please sign in to comment.