<commit_before>/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 */

jest.mock('../resolveToValue');

import { statement } from '../../../tests/utils';
import resolveToValue from '../resolveToValue';
import resolveExportDeclaration from '../resolveExportDeclaration';

describe('resolveExportDeclaration', () => {
  const returnValue = {};
  const ignoreImports = () => null;

  beforeEach(() => {
    resolveToValue.mockReturnValue(returnValue);
  });

  it('resolves default exports', () => {
    const exp = statement('export default 42;');
    const resolved = resolveExportDeclaration(exp, ignoreImports);

    expect(resolved).toEqual([returnValue]);
    expect(resolveToValue).toBeCalledWith(
      exp.get('declaration'),
      ignoreImports,
    );
  });

  it('resolves named exports', () => {
    let exp = statement('export var foo = 42, bar = 21;');
    let resolved = resolveExportDeclaration(exp, ignoreImports);

    const declarations = exp.get('declaration', 'declarations');
    expect(resolved).toEqual([returnValue, returnValue]);
    expect(resolveToValue).toBeCalledWith(declarations.get(0), ignoreImports);
    expect(resolveToValue).toBeCalledWith(declarations.get(1), ignoreImports);

    exp = statement('export function foo(){}');
    resolved = resolveExportDeclaration(exp, ignoreImports);

    expect(resolved).toEqual([returnValue]);
    expect(resolveToValue).toBeCalledWith(
      exp.get('declaration'),
      ignoreImports,
    );

    exp = statement('export class Foo {}');
    resolved = resolveExportDeclaration(exp, ignoreImports);

    expect(resolved).toEqual([returnValue]);
    expect(resolveToValue).toBeCalledWith(
      exp.get('declaration'),
      ignoreImports,
    );
  });

  it('resolves named exports', () => {
    const exp = statement('export {foo, bar, baz}; var foo, bar, baz;');
    const resolved = resolveExportDeclaration(exp, ignoreImports);

    const specifiers = exp.get('specifiers');
    expect(resolved).toEqual([returnValue, returnValue, returnValue]);
    expect(resolveToValue).toBeCalledWith(
      specifiers.get(0, 'local'),
      ignoreImports,
    );
    expect(resolveToValue).toBeCalledWith(
      specifiers.get(1, 'local'),
      ignoreImports,
    );
    expect(resolveToValue).toBeCalledWith(
      specifiers.get(2, 'local'),
      ignoreImports,
    );
  });
});<commit_msg>Switch resolveExportDeclaration tests to use noopImporter<commit_after>/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 */

jest.mock('../resolveToValue');

import { statement, noopImporter } from '../../../tests/utils';
import resolveToValue from '../resolveToValue';
import resolveExportDeclaration from '../resolveExportDeclaration';

describe('resolveExportDeclaration', () => {
  const returnValue = {};

  beforeEach(() => {
    resolveToValue.mockReturnValue(returnValue);
  });

  it('resolves default exports', () => {
    const exp = statement('export default 42;');
    const resolved = resolveExportDeclaration(exp, noopImporter);

    expect(resolved).toEqual([returnValue]);
    expect(resolveToValue).toBeCalledWith(exp.get('declaration'), noopImporter);
  });

  it('resolves named exports', () => {
    let exp = statement('export var foo = 42, bar = 21;');
    let resolved = resolveExportDeclaration(exp, noopImporter);

    const declarations = exp.get('declaration', 'declarations');
    expect(resolved).toEqual([returnValue, returnValue]);
    expect(resolveToValue).toBeCalledWith(declarations.get(0), noopImporter);
    expect(resolveToValue).toBeCalledWith(declarations.get(1), noopImporter);

    exp = statement('export function foo(){}');
    resolved = resolveExportDeclaration(exp, noopImporter);

    expect(resolved).toEqual([returnValue]);
    expect(resolveToValue).toBeCalledWith(exp.get('declaration'), noopImporter);

    exp = statement('export class Foo {}');
    resolved = resolveExportDeclaration(exp, noopImporter);

    expect(resolved).toEqual([returnValue]);
    expect(resolveToValue).toBeCalledWith(exp.get('declaration'), noopImporter);
  });

  it('resolves named exports', () => {
    const exp = statement('export {foo, bar, baz}; var foo, bar, baz;');
    const resolved = resolveExportDeclaration(exp, noopImporter);

    const specifiers = exp.get('specifiers');
    expect(resolved).toEqual([returnValue, returnValue, returnValue]);
    expect(resolveToValue).toBeCalledWith(
      specifiers.get(0, 'local'),
      noopImporter,
    );
    expect(resolveToValue).toBeCalledWith(
      specifiers.get(1, 'local'),
      noopImporter,
    );
    expect(resolveToValue).toBeCalledWith(
      specifiers.get(2, 'local'),
      noopImporter,
    );
  });
});
{'fraction_non_alphanumeric': 0.14424242424242426, 'fraction_numerical': 0.0044444444444444444, 'mean_word_length': 4.352432432432432, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '8661', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1387, 'n_words': 298}