<commit_before>// localLookupStub returns the text of what the path it will be looking up
// Doesn't really return the actual result from the service
// This is fair enough from a unit test point of view
// If this is too brittle, we can convert it into a proper integration test.
const { getProjectPathStub, fixturesBasePath: base, async, localLookupStub } = require('../spec-helper');

// This module is pretty crucial to how babelmodule operates
// Use the fixtures folder as your test dummy
const lookupAlias = require('../../lib/utils/lookup-alias');

describe('module lookup: babel',() => {
  let subject;
  let findBabelConfigMock = jasmine.createSpy('findBabelConfig');

  beforeEach(() => {
    subject = new (require('../../lib/lookups/module/babel'))
      (getProjectPathStub, require('path'),
      findBabelConfigMock, localLookupStub, lookupAlias);
  });

  describe('no config', () => {
    beforeEach(() => {
      // if c === null, the config wasn't found
      findBabelConfigMock.andReturn(Promise.resolve(null));
    });
    it('should not lookup anything', async((done) => {
      subject.getList('someprefix', '/some/path')
      .then(result => {
        done(() => {
          expect(result.length).toBe(0);});
      });
    }));
  });

  describe('v1 - babel-plugin-module-alias', () => {
    beforeEach(() => {
      findBabelConfigMock.andReturn(Promise.resolve({ config: {
        'plugins': [
          ['module-alias', [
            { 'src': './subfolder/innerFolder', 'expose': 'inny' },
            { 'src': './src/fake', 'expose': 'notexist' }
          ]]
        ]}}));
    });

    it('should return aliased suggestions', async((done) => {
      subject.getList('inny/function', `${base}/testbed.js`)
      .then((results) => {
        done(() => {
          expect(results.length).toBe(1);
          expect(results[0].text).toBe(`${base}/subfolder/innerFolder`);
        });
      }).catch(e => { throw new Error(e); });
    }));
  });

  describe('v2 - babel-plugin-module-resolver', () => {
    let v2Config;

    beforeEach(() => {
      v2Config = { config: {
          'plugins': [
            ["module-resolver", {
              "alias": {
                "nonexist": "./src/fake",
                "inny": "./subfolder/innerFolder" }
              }]
          ]}
        };
      findBabelConfigMock.andReturn(Promise.resolve(v2Config));
    });

    it('should return aliased suggestions', async((done) => {
      subject.getList('inny/function', `${base}/testbed.js`)
      .then((results) => {
        done(() => {
          expect(results.length).toBe(1);
          expect(results[0].text).toBe(`${base}/subfolder/innerFolder`);
        });
      }).catch(e => { throw new Error(e); });
    }));

    describe('with custom root directories', () => {
        beforeEach(() => {
          v2Config = { config: {
              'plugins': [
                ["module-resolver", {
                  "root": ["./subfolder"],
                  "alias": {
                    "wrong": "./other_modules/something",
                    "inny": "./subfolder/innerFolder" }
                }]
              ]}
            };
          findBabelConfigMock.andReturn(Promise.resolve(v2Config));
        });

        it('should return aliased suggestions and root suggestions', async((done) => {
          subject.getList('inny/function', `${base}/testbed.js`)
          .then((results) => {
            done(() => {
              expect(results.length).toBe(2);
            });
          }).catch(e => { throw new Error(e); });
        }));

        it('should return root suggestions', async(done => {
          subject
          .getList('namedFunction', `${base}/testbed.js`)
          .then(results => {
            done(() => {
                expect(results).toHaveLength(1);
                expect(results[0].text).toBe(`${base}/subfolder`);
            });
          })
          .catch(e => {
            throw new Error(e);
          });
      }));
    });
  });
});<commit_msg>Include additonal sanity spec for babel<commit_after>// localLookupStub returns the text of what the path it will be looking up
// Doesn't really return the actual result from the service
// This is fair enough from a unit test point of view
// If this is too brittle, we can convert it into a proper integration test.
const { getProjectPathStub, fixturesBasePath: base, async, localLookupStub } = require('../spec-helper');

// This module is pretty crucial to how babelmodule operates
// Use the fixtures folder as your test dummy
const lookupAlias = require('../../lib/utils/lookup-alias');

describe('module lookup: babel',() => {
  let subject;
  let findBabelConfigMock = jasmine.createSpy('findBabelConfig');

  beforeEach(() => {
    subject = new (require('../../lib/lookups/module/babel'))
      (getProjectPathStub, require('path'),
      findBabelConfigMock, localLookupStub, lookupAlias);
  });

  describe('no config', () => {
    beforeEach(() => {
      // if c === null, the config wasn't found
      findBabelConfigMock.andReturn(Promise.resolve(null));
    });
    it('should not lookup anything', async((done) => {
      subject.getList('someprefix', '/some/path')
      .then(result => {
        done(() => {
          expect(result.length).toBe(0);});
      });
    }));
  });

  describe('v1 - babel-plugin-module-alias', () => {
    beforeEach(() => {
      findBabelConfigMock.andReturn(Promise.resolve({ config: {
        'plugins': [
          ['module-alias', [
            { 'src': './subfolder/innerFolder', 'expose': 'inny' },
            { 'src': './src/fake', 'expose': 'notexist' }
          ]]
        ]}}));
    });

    it('should return aliased suggestions', async((done) => {
      subject.getList('inny/function', `${base}/testbed.js`)
      .then((results) => {
        done(() => {
          expect(results.length).toBe(1);
          expect(results[0].text).toBe(`${base}/subfolder/innerFolder`);
        });
      }).catch(e => { throw new Error(e); });
    }));
  });

  describe('v2 - babel-plugin-module-resolver', () => {
    let v2Config;

    beforeEach(() => {
      v2Config = { config: {
          'plugins': [
            ["module-resolver", {
              "alias": {
                "nonexist": "./src/fake",
                "inny": "./subfolder/innerFolder" }
              }]
          ]}
        };
      findBabelConfigMock.andReturn(Promise.resolve(v2Config));
    });

    it('should return aliased suggestions', async((done) => {
      subject.getList('inny/function', `${base}/testbed.js`)
      .then((results) => {
        done(() => {
          expect(results.length).toBe(1);
          expect(results[0].text).toBe(`${base}/subfolder/innerFolder`);
        });
      }).catch(e => { throw new Error(e); });
    }));

    describe('with custom root directories', () => {
        beforeEach(() => {
          v2Config = { config: {
              'plugins': [
                ["module-resolver", {
                  "root": ["./subfolder"],
                  "alias": {
                    "wrong": "./other_modules/something",
                    "inny": "./subfolder/innerFolder" }
                }]
              ]}
            };
          findBabelConfigMock.andReturn(Promise.resolve(v2Config));
        });

        it('should return aliased suggestions and root suggestions', async((done) => {
          subject.getList('inny/function', `${base}/testbed.js`)
          .then((results) => {
            done(() => {
              expect(results.length).toBe(2);
            });
          }).catch(e => { throw new Error(e); });
        }));

        it('should return root suggestions', async(done => {
          subject
          .getList('namedFunction', `${base}/testbed.js`)
          .then(results => {
            done(() => {
                expect(results).toHaveLength(1);
                expect(results[0].text).toBe(`${base}/subfolder`);
            });
          })
          .catch(e => {
            throw new Error(e);
          });
      }));

        describe('root as .', () => {
          beforeEach(() => {
            v2Config.config.plugins = [
                  ["module-resolver", {
                    "root": ["."]
                  }]
                ];
            findBabelConfigMock.andReturn(Promise.resolve(v2Config));
          });

          it('should return suggestions from base', async(done => {
            subject
            .getList('subfolder/innerFolder', `${base}/testbed.js`)
            .then(results => {
              done(() => {
                  expect(results).toHaveLength(1);
                  expect(results[0].text).toBe(`${base}`);
              });
            })
            .catch(e => {
              throw new Error(e);
            });
        }));
        });
    });
  });
});
{'fraction_non_alphanumeric': 0.17792869269949066, 'fraction_numerical': 0.003848330503678551, 'mean_word_length': 1.9142480211081794, 'pattern_counts': {'":': 15, '<': 3, '<?xml version=': 0, '>': 67, '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': '326184', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2440, 'n_words': 475}