/**
 * 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.
 *
 * @emails oncall+react_native
 * @format
 */

'use strict';

const {transform: babelTransform} = require('@babel/core');
const fixtures = require('../__test_fixtures__/fixtures.js');
const failures = require('../__test_fixtures__/failures.js');

function transform(fixture, filename) {
  return babelTransform(fixture, {
    babelrc: false,
    cwd: '/',
    filename: filename,
    highlightCode: false,
    plugins: [require('@babel/plugin-syntax-flow'), require('../index')],
  }).code;
}

describe('Babel plugin inline view configs', () => {
  Object.keys(fixtures)
    .sort()
    .forEach(fixtureName => {
      it(`can inline config for ${fixtureName}`, () => {
        expect(transform(fixtures[fixtureName], fixtureName)).toMatchSnapshot();
      });
    });

  Object.keys(failures)
    .sort()
    .forEach(fixtureName => {
      it(`fails on inline config for ${fixtureName}`, () => {
        expect(() => {
          transform(failures[fixtureName], fixtureName);
        }).toThrowErrorMatchingSnapshot();
      });
    });
});

/**
 * 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.
 *
 * @emails oncall+react_native
 * @format
 */

'use strict';

const {transform: babelTransform} = require('@babel/core');
const fixtures = require('../__test_fixtures__/fixtures.js');
const failures = require('../__test_fixtures__/failures.js');

const transform = (fixture, filename) =>
  babelTransform(fixture, {
    babelrc: false,
    cwd: '/',
    filename: filename,
    highlightCode: false,
    plugins: [require('@babel/plugin-syntax-flow'), require('../index')],
  }).code.replace(/^[A-Z]:\\/g, '/'); // Ensure platform consistent snapshots.

describe('Babel plugin inline view configs', () => {
  Object.keys(fixtures)
    .sort()
    .forEach(fixtureName => {
      it(`can inline config for ${fixtureName}`, () => {
        expect(transform(fixtures[fixtureName], fixtureName)).toMatchSnapshot();
      });
    });

  Object.keys(failures)
    .sort()
    .forEach(fixtureName => {
      it(`fails on inline config for ${fixtureName}`, () => {
        expect(() => {
          transform(failures[fixtureName], fixtureName);
        }).toThrowErrorMatchingSnapshot();
      });
    });
});

Fix inline-view-configs test on Windows.
Fix inline-view-configs test on Windows.

Summary:
*facepalm* The file path is platform specific.

Changelog: [Internal]

Reviewed By: GijsWeterings

Differential Revision: D20793023

fbshipit-source-id: 4fbcbf982911ee449a4fa5067cc0c5d81088ce04
