Skip to content
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spec-box/collector",
"version": "0.0.3",
"version": "0.1.0",
"private": false,
"description": "",
"license": "MIT",
Expand Down
45 changes: 34 additions & 11 deletions src/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,44 @@ export class DefaultStrategy {
}

getFeatureTitle = ({path}: StrategyOptions) => {
const attributes = this.parsePathToAttributes(path);
const levels = this.collectorOptions.levels || 3;

if (attributes.length > levels) {
const excludedElements = attributes.slice(levels, -1);
const fileName = attributes[attributes.length - 1];
const titleElements = [...excludedElements, fileName];
return titleElements.map(this.formatPathElement).join(' / ');
}

return this.getTitleFromPath(path);
};

getGroups = ({tests, emptyTests, path}: StrategyOptions) => {
const emptyTestsAssertion = this.loadEmptyTestAssertion(emptyTests);
const pwTestsAssertion = this.loadPwTestFromAssertion(tests);

return [
{
const groups = [];

if (pwTestsAssertion.length > 0) {
groups.push({
title: this.getTitleFromPath(path),
assertions: [...pwTestsAssertion, ...emptyTestsAssertion],
},
];
};
assertions: pwTestsAssertion,
});
}

getAttributes = ({path}: StrategyOptions) => {
const {dir, name} = parsePath(path);
const pathArray = dir.split('/');
if (emptyTestsAssertion.length > 0) {
groups.push({
title: `${this.getTitleFromPath(path)} - Empty Tests`,
assertions: emptyTestsAssertion,
});
}

const editedFileName = this.formatFilename(name);
const attributes = [...pathArray, editedFileName].filter(Boolean) as string[];
return groups;
};

getAttributes = ({path}: StrategyOptions) => {
const attributes = this.parsePathToAttributes(path);
return attributes.slice(0, this.collectorOptions.levels || 3).map(this.formatPathElement);
};

Expand Down Expand Up @@ -103,4 +119,11 @@ export class DefaultStrategy {

return attributeWithoutDash[0]?.toUpperCase() + attributeWithoutDash.slice(1);
};

private parsePathToAttributes = (path: string): string[] => {
const {dir, name} = parsePath(path);
const pathArray = dir.split('/');
const editedFileName = this.formatFilename(name);
return [...pathArray, editedFileName].filter(Boolean) as string[];
};
}