message: Remove group's folder if it is passed
diff: @@ -4,7 +4,13 @@ import * as fs from 'fs';
  import * as path from 'path';
  import { expect } from 'chai';
  -import { describe, it } from 'mocha';
  +import {
  + after,
  + afterEach,
  + Context,
  + describe,
  + it,
  +} from 'mocha';
  import { PNG } from 'pngjs';
  import { compareScreenshots } from './helpers/compare-screenshots';
  @@ -27,8 +33,12 @@ const testResultsOutDir = path.resolve(process.env.CMP_OUT_DIR || path.join(__di
  const goldenStandalonePath = process.env[goldenStandalonePathEnvKey] || '';
  const testStandalonePath = process.env[testStandalonePathEnvKey] || '';
  +function testGroupOutFolder(groupName: string): string {
  + return path.join(testResultsOutDir, groupName);
  +}
  +
  function testCaseOutFolder(groupName: string, testCaseName: string): string {
  - return path.join(testResultsOutDir, groupName, testCaseName);
  + return path.join(testGroupOutFolder(groupName), testCaseName);
  }
  function rmRf(folder: string): void {
  @@ -56,9 +66,8 @@ describe('Graphics tests', function(): void {
  let screenshoter: Screenshoter;
  before(() => {
  - if (!fs.existsSync(testResultsOutDir)) {
  + rmRf(testResultsOutDir);
  fs.mkdirSync(testResultsOutDir, { recursive: true });
  - }
  expect(goldenStandalonePath, `path to golden standalone module must be passed via ${goldenStandalonePathEnvKey} env var`)
  .to.have.length.greaterThan(0);
  @@ -69,8 +78,7 @@ describe('Graphics tests', function(): void {
  screenshoter = new Screenshoter(Boolean(process.env.NO_SANDBOX));
  });
  - for (const groupName of Object.keys(testCases)) {
  - const registerTestGroup = () => {
  + const registerTestGroup = (groupName: string) => {
  for (const testCase of testCases[groupName]) {
  it(testCase.name, async () => {
  const testCaseOutDir = testCaseOutFolder(groupName, testCase.name);
  @@ -131,10 +139,27 @@ See ${testCaseOutDir} folder for an output of the test case.`
  }
  };
  + for (const groupName of Object.keys(testCases)) {
  if (groupName.length === 0) {
  - registerTestGroup();
  + registerTestGroup(groupName);
  } else {
  - describe(groupName, registerTestGroup);
  + describe(groupName, () => {
  + registerTestGroup(groupName);
  +
  + let isGroupFailed = false;
  +
  + afterEach(function(this: Context): void {
  + if (this.currentTest !== undefined && this.currentTest.state === 'failed') {
  + isGroupFailed = true;
  + }
  + });
  +
  + after(() => {
  + if (!isGroupFailed) {
  + rmRf(testGroupOutFolder(groupName));
  + }
  + });
  + });
  }
  }
  