{"size": 2067, "ext": "js", "max_stars_repo_path": "src/__tests__/test-helper.js", "max_stars_repo_name": "Eddort/babel-plugin-transform-react-pug", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/__tests__/test-helper.js", "max_issues_repo_name": "Eddort/babel-plugin-transform-react-pug", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/__tests__/test-helper.js", "max_forks_repo_name": "Eddort/babel-plugin-transform-react-pug", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.9324324324, "max_line_length": 80, "alphanum_fraction": 0.6100628931}
import React from 'react';
import ReactServer from 'react-dom/server';
import renderer from 'react-test-renderer';
import {transformFileSync} from 'babel-core';
import transformReactPug from '../';

export function testCompileError(filename) {
  test('Expect an error to be thrown', () => {
    try {
      transformFileSync(filename, {
        babelrc: false,
        plugins: [transformReactPug],
      });
    } catch (ex) {
      expect(ex.message).toMatchSnapshot('');
      return;
    }
    throw new Error('Expected an exception');
  });
}

export function testRuntimeError(filename) {
  test('Expect an error to be thrown', () => {
    try {
      const src = transformFileSync(filename, {
        babelrc: false,
        plugins: [
          transformReactPug,
          require('babel-plugin-transform-react-jsx'),
        ],
      }).code;
      const m = {exports: {}};
      Function('React,module', src)(React, m);
    } catch (ex) {
      expect(ex.message).toMatchSnapshot('');
      return;
    }
    throw new Error('Expected an exception');
  });
}

export default filename => {
  test('JavaScript output', () => {
    expect(
      transformFileSync(filename, {
        babelrc: false,
        plugins: [transformReactPug],
      }).code,
    ).toMatchSnapshot('transformed source code');
  });
  test('html output', () => {
    const src = transformFileSync(filename, {
      babelrc: false,
      plugins: [transformReactPug, require('babel-plugin-transform-react-jsx')],
    }).code;
    const m = {exports: {}};
    Function('React,module', src)(React, m);
    expect(renderer.create(m.exports).toJSON()).toMatchSnapshot(
      'generated html',
    );
  });
  test('static html output', () => {
    const src = transformFileSync(filename, {
      babelrc: false,
      plugins: [transformReactPug, require('babel-plugin-transform-react-jsx')],
    }).code;
    const m = {exports: {}};
    Function('React,module', src)(React, m);
    expect(ReactServer.renderToStaticMarkup(m.exports)).toMatchSnapshot(
      'static html',
    );
  });
};
