Skip to content

Commit

Permalink
Sanitize filenames in ScreenshotCallbackFunction (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
unsortedhashsets authored Aug 3, 2023
1 parent 547468a commit cbbff1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/suite/mochaHooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Func } from 'mocha';
import { VSBrowser } from '../extester';
import sanitize from 'sanitize-filename';

type HookType = 'before' | 'beforeEach' | 'after' | 'afterEach';

Expand Down Expand Up @@ -46,7 +47,7 @@ function createScreenshotCallbackFunction(name: string | undefined, hookType: Ho
if (this === undefined) throw e;
if (this.test === undefined) {
try {
await VSBrowser.instance.takeScreenshot(alternativeFileName.replace(/"/g, "'"));
await VSBrowser.instance.takeScreenshot(sanitize(alternativeFileName));
}
catch (screenshotError) {
console.error(`Could not take screenshot. this.test is undefined. Reason:\n${screenshotError}\n\n`);
Expand All @@ -56,7 +57,7 @@ function createScreenshotCallbackFunction(name: string | undefined, hookType: Ho

try {
const titlePath = this.test.titlePath();
await VSBrowser.instance.takeScreenshot(titlePath.join('.').replace(/"/g, "'"));
await VSBrowser.instance.takeScreenshot(sanitize(titlePath.join('.')));
}
catch (screenshotError) {
console.error(`Could not take screenshot. Reason:\n${screenshotError}\n\n`);
Expand Down
18 changes: 9 additions & 9 deletions src/suite/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as glob from 'glob';
import { CodeUtil, ReleaseQuality } from '../util/codeUtil';
import * as path from 'path';
import * as yaml from 'js-yaml';
import sanitize = require('sanitize-filename');
import sanitize from 'sanitize-filename';
import { logging } from 'selenium-webdriver';
import * as os from 'os';

Expand Down Expand Up @@ -50,7 +50,7 @@ export class VSRunner {
glob.sync(universalPattern)
.forEach((val) => testFiles.add(val));
}

testFiles.forEach((file) => this.mocha.addFile(file));
this.mocha.suite.afterEach(async function () {
if (this.currentTest && this.currentTest.state !== 'passed') {
Expand All @@ -62,7 +62,7 @@ export class VSRunner {
}
}
});

this.mocha.suite.beforeAll(async function () {
this.timeout(180000);
const start = Date.now();
Expand All @@ -74,8 +74,8 @@ export class VSRunner {
console.log(`Browser ready in ${Date.now() - start} ms`);
console.log('Launching tests...');
});
this.mocha.suite.afterAll(async function() {

this.mocha.suite.afterAll(async function () {
this.timeout(60000);
await browser.quit();
if (process.platform === 'darwin') {
Expand All @@ -87,10 +87,10 @@ export class VSRunner {
}
}
}

code.uninstallExtension(self.cleanup);
});

this.mocha.run((failures) => {
process.exitCode = failures ? 1 : 0;
resolve(process.exitCode);
Expand All @@ -104,11 +104,11 @@ export class VSRunner {
} catch (err) {
return this.chromeBin;
}

const dir = path.parse(src);
const segments = this.chromeBin.split(path.sep);
const newSegments = dest.split(path.sep);

let found = false;
for (let i = 0; i < segments.length; i++) {
if (!found) {
Expand Down

0 comments on commit cbbff1f

Please sign in to comment.