<commit_before>const {createSandbox} = require('sinon');
const {restore, Instance, childProcessEmits, closeWithSuccess, wait} = require('./include/setup');
const {autoMergeResponse, autoMergeConflict} = require('../helpers');
const {GitResponseError} = require('../../src/lib/api');

describe('git', () => {

   let git, sandbox;

   beforeEach(() => {
      (sandbox = createSandbox()).stub(console, 'warn');
   });

   afterEach(() => restore(sandbox));

   describe('deprecations', () => {

      it('direct access to properties of custom error on GitResponseError', async () => {
         let callbackErr, promiseErr;

         git = Instance();
         git.merge(['a', 'b'], (err) => callbackErr = err)
            .catch(err => promiseErr = err);

         await closeWithSuccess(
            autoMergeResponse(autoMergeConflict)
         );
         await wait();

         expect(callbackErr).toBeInstanceOf(GitResponseError);
         expect(promiseErr).toBeInstanceOf(GitResponseError);
         expect(callbackErr).not.toBe(promiseErr);

         const warning = jest.spyOn(console, 'warn');

         // accessing properties on the callback error shows a warning
         const conflicts = callbackErr.conflicts;
         expect(warning).toHaveBeenCalledTimes(1);

         // but gives a pointer to the real value
         expect(conflicts).toBe(promiseErr.git.conflicts);

         // subsequent access of properties
         expect(callbackErr.merges).toBe(promiseErr.git.merges);

         // do not show additional warnings in the console
         expect(warning).toHaveBeenCalledTimes(1);

         // the promise error has not been modified with the properties of the response
         expect('conflicts' in promiseErr).toBe(false);
      });

   });

   describe('simpleGit', () => {

      const simpleGit = require('../..');
      const { $fails, $reset } = require('@kwsites/file-exists');

      afterEach(() => $reset());

      it('throws when created with a non-existent directory', () => {<commit_msg>Add ES module properties test<commit_after>const {createSandbox} = require('sinon');
const {restore, Instance, childProcessEmits, closeWithSuccess, wait} = require('./include/setup');
const {autoMergeResponse, autoMergeConflict} = require('../helpers');
const {GitResponseError} = require('../../src/lib/api');

describe('git', () => {

   let git, sandbox;

   beforeEach(() => {
      (sandbox = createSandbox()).stub(console, 'warn');
   });

   afterEach(() => restore(sandbox));

   describe('deprecations', () => {

      it('direct access to properties of custom error on GitResponseError', async () => {
         let callbackErr, promiseErr;

         git = Instance();
         git.merge(['a', 'b'], (err) => callbackErr = err)
            .catch(err => promiseErr = err);

         await closeWithSuccess(
            autoMergeResponse(autoMergeConflict)
         );
         await wait();

         expect(callbackErr).toBeInstanceOf(GitResponseError);
         expect(promiseErr).toBeInstanceOf(GitResponseError);
         expect(callbackErr).not.toBe(promiseErr);

         const warning = jest.spyOn(console, 'warn');

         // accessing properties on the callback error shows a warning
         const conflicts = callbackErr.conflicts;
         expect(warning).toHaveBeenCalledTimes(1);

         // but gives a pointer to the real value
         expect(conflicts).toBe(promiseErr.git.conflicts);

         // subsequent access of properties
         expect(callbackErr.merges).toBe(promiseErr.git.merges);

         // do not show additional warnings in the console
         expect(warning).toHaveBeenCalledTimes(1);

         // the promise error has not been modified with the properties of the response
         expect('conflicts' in promiseErr).toBe(false);
      });

   });

   describe('simpleGit', () => {

      const simpleGit = require('../..');
      const { $fails, $reset } = require('@kwsites/file-exists');

      afterEach(() => $reset());

      it('can be created using the default export', () => {
         expect(simpleGit.__esModule).toBe(true);
         expect(simpleGit.default).toEqual(simpleGit);

         expect(() => simpleGit.default()).not.toThrow();
      });

      it('throws when created with a non-existent directory', () => {
{'fraction_non_alphanumeric': 0.1424263511946184, 'fraction_numerical': 0.0009278589654372535, 'mean_word_length': 2.8742138364779874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '6921519', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1132, 'n_words': 279}