-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: the ability to specify a test metadata in tests
- `qase.title` - set the test title - `qase.fields` - set the test fields - `qase.suite` - set the test suite - `qase.comment` - set the test comment - `qase.parameters` - set the test parameters - `qase.groupParameters` - set the test group parameters - `qase.ignore` - ignore the test in Qase ```ts it('test', () => { qase.title('Title'); qase.fields({ field: 'value' }); qase.suite('Suite'); qase.comment('Comment'); qase.parameters({ param: 'value' }); qase.groupParameters({ group: { param: 'value' } }); qase.ignore(); cy.visit('https://example.com'); });
- Loading branch information
Showing
9 changed files
with
387 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
# [email protected] | ||
|
||
## What's new | ||
|
||
Added the ability to specify a test metadata in tests: | ||
|
||
- `qase.title` - set the test title | ||
- `qase.fields` - set the test fields | ||
- `qase.suite` - set the test suite | ||
- `qase.comment` - set the test comment | ||
- `qase.parameters` - set the test parameters | ||
- `qase.groupParameters` - set the test group parameters | ||
- `qase.ignore` - ignore the test in Qase | ||
|
||
```ts | ||
it('test', () => { | ||
qase.title('Title'); | ||
qase.fields({ field: 'value' }); | ||
qase.suite('Suite'); | ||
qase.comment('Comment'); | ||
qase.parameters({ param: 'value' }); | ||
qase.groupParameters({ group: { param: 'value' } }); | ||
qase.ignore(); | ||
|
||
cy.visit('https://example.com'); | ||
}); | ||
``` | ||
|
||
# [email protected] | ||
|
||
## What's new | ||
|
@@ -40,8 +68,8 @@ The reporter will wait for all results to be sent to Qase and will not block the | |
|
||
## What's new | ||
|
||
1. Cypress kills the process after the last tests. | ||
The reporter will wait for all results to be sent to Qase and will not block the process after sending. | ||
1. Cypress kills the process after the last tests. | ||
The reporter will wait for all results to be sent to Qase and will not block the process after sending. | ||
|
||
2. The reporter will collect suites and add them to results. | ||
|
||
|
@@ -66,7 +94,7 @@ For more information about the new features and a guide for migration from v1, r | |
|
||
# [email protected] | ||
|
||
Fixed an issue with multiple test runs created when Cypress is running | ||
Fixed an issue with multiple test runs created when Cypress is running | ||
multiple tests in parallel. | ||
|
||
# [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { MetadataManager } from './metadata/manager'; | ||
|
||
module.exports = function(on) { | ||
on('task', { | ||
qaseTitle(value) { | ||
MetadataManager.setTitle(value); | ||
return null; | ||
}, | ||
}); | ||
|
||
on('task', { | ||
qaseFields(value) { | ||
MetadataManager.setFields(value); | ||
return null; | ||
}, | ||
}); | ||
|
||
on('task', { | ||
qaseIgnore() { | ||
MetadataManager.setIgnore(); | ||
return null; | ||
}, | ||
}); | ||
|
||
on('task', { | ||
qaseParameters(value) { | ||
MetadataManager.setParameters(value); | ||
return null; | ||
}, | ||
}); | ||
|
||
on('task', { | ||
qaseGroupParameters(value) { | ||
MetadataManager.setGroupParams(value); | ||
return null; | ||
}, | ||
}); | ||
|
||
on('task', { | ||
qaseSuite(value) { | ||
MetadataManager.setSuite(value); | ||
return null; | ||
}, | ||
}); | ||
|
||
on('task', { | ||
qaseComment(value) { | ||
MetadataManager.setComment(value); | ||
return null; | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { Metadata } from './models'; | ||
import { readFileSync, existsSync, unlinkSync, writeFileSync } from 'fs'; | ||
|
||
const metadataPath = 'qaseMetadata'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-extraneous-class | ||
export class MetadataManager { | ||
public static getMetadata(): Metadata | undefined { | ||
if (!this.isExists()) { | ||
return undefined; | ||
} | ||
|
||
let metadata: Metadata = { | ||
title: undefined, | ||
fields: {}, | ||
parameters: {}, | ||
groupParams: {}, | ||
ignore: false, | ||
suite: undefined, | ||
comment: undefined, | ||
}; | ||
|
||
try { | ||
const data = readFileSync(metadataPath, 'utf8'); | ||
metadata = JSON.parse(data) as Metadata; | ||
|
||
return metadata; | ||
} catch (err) { | ||
console.error('Error reading metadata file:', err); | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
public static setIgnore(): void { | ||
const metadata = this.getMetadata() ?? {}; | ||
metadata.ignore = true; | ||
this.setMetadata(metadata); | ||
} | ||
|
||
public static setSuite(suite: string): void { | ||
const metadata = this.getMetadata() ?? {}; | ||
metadata.suite = suite; | ||
this.setMetadata(metadata); | ||
} | ||
|
||
public static setComment(comment: string): void { | ||
const metadata = this.getMetadata() ?? {}; | ||
metadata.comment = comment; | ||
this.setMetadata(metadata); | ||
} | ||
|
||
public static setTitle(title: string): void { | ||
const metadata = this.getMetadata() ?? {}; | ||
metadata.title = title; | ||
this.setMetadata(metadata); | ||
} | ||
|
||
public static setFields(fields: Record<string, string>): void { | ||
const metadata = this.getMetadata() ?? {}; | ||
metadata.fields = fields; | ||
this.setMetadata(metadata); | ||
} | ||
|
||
public static setParameters(parameters: Record<string, string>): void { | ||
const metadata = this.getMetadata() ?? {}; | ||
metadata.parameters = parameters; | ||
this.setMetadata(metadata); | ||
} | ||
|
||
public static setGroupParams(groupParams: Record<string, string>): void { | ||
const metadata = this.getMetadata() ?? {}; | ||
metadata.groupParams = groupParams; | ||
this.setMetadata(metadata); | ||
} | ||
|
||
private static setMetadata(metadata: Metadata): void { | ||
try { | ||
const data = JSON.stringify(metadata); | ||
writeFileSync(metadataPath, data); | ||
} catch (err) { | ||
console.error('Error writing metadata file:', err); | ||
} | ||
} | ||
|
||
public static clear() { | ||
if (!this.isExists()) { | ||
return; | ||
} | ||
|
||
try { | ||
unlinkSync(metadataPath); | ||
} catch (err) { | ||
console.error('Error clearing state file:', err); | ||
} | ||
} | ||
|
||
static isExists(): boolean { | ||
return existsSync(metadataPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface Metadata { | ||
title?: string | undefined; | ||
fields?: Record<string, string>; | ||
parameters?: Record<string, string>; | ||
groupParams?: Record<string, string>; | ||
ignore?: boolean; | ||
suite?: string | undefined; | ||
comment?: string | undefined; | ||
} |
Oops, something went wrong.