<commit_before>import path from 'path';
import fs from 'fs-extra';
import { describe, expect, it, loadFixture } from '../suite';
import Mugshot from '../../../src/mugshot';
import jimpEditor from '../../../src/lib/jimp-editor';

describe('Mugshot', () => {
  const resultsPath = path.join(__dirname, `../screenshots/${process.env.BROWSER}`);

  it('should write first baseline', async browser => {
    await loadFixture('simple2');

    const baselinePath = path.join(resultsPath, 'new.png');
    await fs.remove(baselinePath);

    const mugshot = new Mugshot(browser, resultsPath, {
      fs,
      pngEditor: jimpEditor,
      createBaselines: true
    });

    const resultWhenMissingBaseline = await mugshot.check('new');
    expect(resultWhenMissingBaseline.matches).to.be.true;
    expect(
      await fs.pathExists(baselinePath),
      'Baseline wasn\'t written'
    ).to.be.true;

    const resultWhenExistingBaseline = await mugshot.check('new');
    expect(resultWhenExistingBaseline.matches).to.be.true;
  });

  it('should write first baseline and parent folder', async browser => {
    await loadFixture('simple2');

    const baselinePath = path.join(resultsPath, 'foo/bar/new.png');
    await fs.remove(baselinePath);

    const mugshot = new Mugshot(browser, resultsPath, {
      fs,
      pngEditor: jimpEditor,
      createBaselines: true
    });

    const resultWhenMissingBaseline = await mugshot.check('foo/bar/new');
    expect(resultWhenMissingBaseline.matches).to.be.true;
    expect(
      await fs.pathExists(baselinePath),
      'Baseline wasn\'t written'
    ).to.be.true;

    const resultWhenExistingBaseline = await mugshot.check('foo/bar/new');
    expect(resultWhenExistingBaseline.matches).to.be.true;
  });
});
<commit_msg>Use temp dirs to store newly created baselines<commit_after>import path from 'path';
import fs from 'fs-extra';
import { describe, expect, it, beforeEach, loadFixture } from '../suite';
import Mugshot from '../../../src/mugshot';
import jimpEditor from '../../../src/lib/jimp-editor';

describe('Mugshot', async () => {
  let resultsPath!: string;

  beforeEach(async () => {
    resultsPath = await fs.mkdtemp(`/tmp/mugshot-${process.env.BROWSER}`);
  });

  it('should write first baseline', async browser => {
    await loadFixture('simple2');

    const baselinePath = path.join(resultsPath, 'new.png');

    const mugshot = new Mugshot(browser, resultsPath, {
      fs,
      pngEditor: jimpEditor,
      createBaselines: true
    });

    const resultWhenMissingBaseline = await mugshot.check('new');
    expect(resultWhenMissingBaseline.matches).to.be.true;
    expect(
      await fs.pathExists(baselinePath),
      'Baseline wasn\'t written'
    ).to.be.true;

    const resultWhenExistingBaseline = await mugshot.check('new');
    expect(resultWhenExistingBaseline.matches).to.be.true;
  });

  it('should write first baseline and parent folder', async browser => {
    await loadFixture('simple2');

    const baselinePath = path.join(resultsPath, 'foo/bar/new.png');

    const mugshot = new Mugshot(browser, resultsPath, {
      fs,
      pngEditor: jimpEditor,
      createBaselines: true
    });

    const resultWhenMissingBaseline = await mugshot.check('foo/bar/new');
    expect(resultWhenMissingBaseline.matches).to.be.true;
    expect(
      await fs.pathExists(baselinePath),
      'Baseline wasn\'t written'
    ).to.be.true;

    const resultWhenExistingBaseline = await mugshot.check('foo/bar/new');
    expect(resultWhenExistingBaseline.matches).to.be.true;
  });
});

{'fraction_non_alphanumeric': 0.14044469462426118, 'fraction_numerical': 0.001125809175344779, 'mean_word_length': 3.5858064516129033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1537034', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1061, 'n_words': 234}