diff --git a/package-lock.json b/package-lock.json index 2181c9c..a4bd580 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@spec-box/spec-collector", - "version": "0.0.3", + "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@spec-box/spec-collector", - "version": "0.0.3", + "version": "0.1.0", "license": "MIT", "dependencies": { "@playwright/test": "^1.52.0", diff --git a/package.json b/package.json index 4951f73..a77e54a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spec-box/collector", - "version": "0.0.3", + "version": "0.1.0", "private": false, "description": "", "license": "MIT", diff --git a/src/strategy.ts b/src/strategy.ts index 55815f3..4662ba7 100644 --- a/src/strategy.ts +++ b/src/strategy.ts @@ -15,6 +15,16 @@ 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); }; @@ -22,21 +32,27 @@ export class DefaultStrategy { 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); }; @@ -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[]; + }; }