diff --git a/client/package-lock.json b/client/package-lock.json index 59b919e..b4e280e 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "@suitest/types": "^4.6.0", "ajv": "^6.12.6", - "filenamify": "^4.3.0", "fs-extra": "^7.0.1", "http-network-proxy": "^1.0.11", "needle": "^2.9.1", @@ -2310,30 +2309,6 @@ "node": ">=8" } }, - "node_modules/filename-reserved-regex": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz", - "integrity": "sha512-lc1bnsSr4L4Bdif8Xb/qrtokGbq5zlsms/CYH8PP+WtCkGNF65DPiQY8vG3SakEdRn8Dlnm+gW/qWKKjS5sZzQ==", - "engines": { - "node": ">=4" - } - }, - "node_modules/filenamify": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/filenamify/-/filenamify-4.3.0.tgz", - "integrity": "sha512-hcFKyUG57yWGAzu1CMt/dPzYZuv+jAJUT85bL8mrXvNe6hWj6yEHEc4EdcgiA6Z3oi1/9wXJdZPXF2dZNgwgOg==", - "dependencies": { - "filename-reserved-regex": "^2.0.0", - "strip-outer": "^1.0.1", - "trim-repeated": "^1.0.0" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -5622,17 +5597,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/strip-outer": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/strip-outer/-/strip-outer-1.0.1.tgz", - "integrity": "sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==", - "dependencies": { - "escape-string-regexp": "^1.0.2" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/strnum": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz", @@ -5718,17 +5682,6 @@ "node": ">=0.6" } }, - "node_modules/trim-repeated": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/trim-repeated/-/trim-repeated-1.0.0.tgz", - "integrity": "sha512-pkonvlKk8/ZuR0D5tLW8ljt5I8kmxp2XKymhepUeOdCEfKpZaktSArkLHZt76OB1ZvO9bssUsDty4SWhLvZpLg==", - "dependencies": { - "escape-string-regexp": "^1.0.2" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/ts-node": { "version": "8.10.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.10.2.tgz", @@ -8273,21 +8226,6 @@ "integrity": "sha512-g872QGsHexznxkIAdK8UiZRe7SkE6kvylShU4Nsj8NvfvZag7S0QuQ4IgvPDkk75HxgjIVDwycFTDAgIiO4nDA==", "dev": true }, - "filename-reserved-regex": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz", - "integrity": "sha512-lc1bnsSr4L4Bdif8Xb/qrtokGbq5zlsms/CYH8PP+WtCkGNF65DPiQY8vG3SakEdRn8Dlnm+gW/qWKKjS5sZzQ==" - }, - "filenamify": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/filenamify/-/filenamify-4.3.0.tgz", - "integrity": "sha512-hcFKyUG57yWGAzu1CMt/dPzYZuv+jAJUT85bL8mrXvNe6hWj6yEHEc4EdcgiA6Z3oi1/9wXJdZPXF2dZNgwgOg==", - "requires": { - "filename-reserved-regex": "^2.0.0", - "strip-outer": "^1.0.1", - "trim-repeated": "^1.0.0" - } - }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -10849,14 +10787,6 @@ "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true }, - "strip-outer": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/strip-outer/-/strip-outer-1.0.1.tgz", - "integrity": "sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==", - "requires": { - "escape-string-regexp": "^1.0.2" - } - }, "strnum": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz", @@ -10918,14 +10848,6 @@ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" }, - "trim-repeated": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/trim-repeated/-/trim-repeated-1.0.0.tgz", - "integrity": "sha512-pkonvlKk8/ZuR0D5tLW8ljt5I8kmxp2XKymhepUeOdCEfKpZaktSArkLHZt76OB1ZvO9bssUsDty4SWhLvZpLg==", - "requires": { - "escape-string-regexp": "^1.0.2" - } - }, "ts-node": { "version": "8.10.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.10.2.tgz", diff --git a/client/package.json b/client/package.json index 9a47621..110bbe5 100644 --- a/client/package.json +++ b/client/package.json @@ -31,7 +31,6 @@ "dependencies": { "@suitest/types": "^4.6.0", "ajv": "^6.12.6", - "filenamify": "^4.3.0", "fs-extra": "^7.0.1", "http-network-proxy": "^1.0.11", "needle": "^2.9.1", @@ -91,7 +90,7 @@ }, "mocha": { "timeout": 72000, - "bail": true, + "bail": false, "require": [ "source-map-support/register" ], diff --git a/client/src/RokuDevice.ts b/client/src/RokuDevice.ts index 03db4f5..8808b38 100644 --- a/client/src/RokuDevice.ts +++ b/client/src/RokuDevice.ts @@ -4,7 +4,6 @@ import * as fsExtra from 'fs-extra'; import * as querystring from 'needle/lib/querystring'; import type * as mocha from 'mocha'; import * as net from 'net'; -import * as path from 'path'; import type { ConfigOptions } from './types/ConfigOptions'; import { utils } from './utils'; @@ -180,7 +179,7 @@ export class RokuDevice { } public async getTestScreenshot(contextOrSuite: mocha.Context | mocha.Suite, basePath = '', postFix = '', separator = '_') { - const screenshotPath = path.join(basePath, utils.getTestTitlePath(contextOrSuite).join(separator)) + postFix; + const screenshotPath = utils['getPath']().join(basePath, utils.getTestTitlePath(contextOrSuite).join(separator)) + postFix; return await this.getScreenshot(screenshotPath); } diff --git a/client/src/utils.spec.ts b/client/src/utils.spec.ts index 76431b9..7943a68 100644 --- a/client/src/utils.spec.ts +++ b/client/src/utils.spec.ts @@ -46,4 +46,16 @@ describe('utils', function () { assert.fail('Should have thrown an exception'); }); }); + + describe('getTestTitlePath', function () { + it('Does not mess with test name if sanitize is off', function () { + const result = utils.getTestTitlePath(this, false); + expect(result[2]).to.equal(this.test?.title); + }); + + it('Properly sanitizes if turned on ;,.:*^', function () { + const result = utils.getTestTitlePath(this, true); + expect(result[2]).to.equal('Properly_sanitizes_if_turned_on_______'); + }); + }); }); diff --git a/client/src/utils.ts b/client/src/utils.ts index a4bab3f..3772658 100644 --- a/client/src/utils.ts +++ b/client/src/utils.ts @@ -1,14 +1,14 @@ import type * as fsExtra from 'fs-extra'; import type * as path from 'path'; import type * as Mocha from 'mocha'; -import * as filenamify from 'filenamify'; import * as Ajv from 'ajv'; const ajv = new Ajv(); import type { ConfigOptions, DeviceConfigOptions } from './types/ConfigOptions'; +type PathType = typeof path; class Utils { - private path?: typeof path; + private path?: PathType; private fsExtra?: typeof fsExtra; @@ -19,7 +19,7 @@ class Utils { private getPath() { if (!this.path) { - this.path = this.require('path'); + this.path = this.require('path'); } return this.path; } @@ -210,14 +210,24 @@ class Utils { throw new Error('Neither Mocha.Context or Mocha.Suite passed in'); } - if (!(ctx.currentTest?.constructor.name === 'Test')) { + let test: Mocha.Runnable; + if (ctx.currentTest?.constructor.name === 'Test') { + test = ctx.currentTest; + } else if (ctx.test?.constructor.name === 'Test') { + test = ctx.test; + } else { throw new Error('Mocha.Context did not contain test. At least surrounding Mocha.Suite must use non arrow function'); } - const pathParts = ctx.currentTest?.titlePath(); + const pathParts = test.titlePath(); if (sanitize) { for (const [index, pathPart] of pathParts.entries()) { - pathParts[index] = filenamify(pathPart); + if (sanitize) { + pathParts[index] = pathPart.replace(/[^a-zA-Z0-9_]/g, '_'); + } else { + pathParts[index] = pathPart; + } + } }