How to use babel-plugin-tester - 8 common examples

To help you get started, we’ve selected a few babel-plugin-tester examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kentcdodds / babel-plugin-macros / src / __tests__ / index.js View on Github external
print(val) {
    return (
      val
        .split(projectRoot)
        .join('/')
        .replace(/\\/g, '/')
        // Remove the path of file which thrown an error
        .replace(/Error:[^:]*:/, 'Error:')
    )
  },
  test(val) {
    return typeof val === 'string'
  },
})

pluginTester({
  plugin,
  snapshot: true,
  babelOptions: {
    filename: __filename,
    parserOpts: {
      plugins: ['jsx'],
    },
    generatorOpts: {quotes: 'double'},
  },
  tests: [
    {
      title: 'does nothing to code that does not import macro',
      snapshot: false,
      code: `
        import foo from "./some-file-without-macro";
github kentcdodds / glamorous-website / other / __tests__ / babel-plugin-l10-loader.js View on Github external
import pluginTester from 'babel-plugin-tester'
import plugin from '../babel-plugin-l10n-loader'

const locale = process.env.LOCALE

beforeAll(() => {
  process.env.LOCALE = 'en'
})

afterAll(() => {
  process.env.LOCALE = locale
})

pluginTester({
  plugin,
  snapshot: true,
  tests: [
    {
      fixture: require.resolve('./fixtures/some-component'),
      setup() {
        const errorSpy = jest
          .spyOn(console, 'error')
          .mockImplementation(() => {})
        return function teardown() {
          const allCalls = errorSpy.mock.calls
            .reduce((a, c) => a.concat(c), [])
            .join('\n')
            .split(__dirname)
            .join('')
github chengjianhua / penv.macro / src / __tests__ / helpers / create-tests.js View on Github external
export default function createTestsForPenvMacro({plugin}) {
  pluginTester({
    plugin,
    snapshot: true,
    babelOptions: {
      filename: __filename,
    },
    tests: {
      'should replace the environment variable to the matched value': {
        code: `
          import env from '../../macro';

          const variable = env({
            development: 'development',
            staging: 'staging',
            production: 'production',
            test: () => {
              console.log('test');
github merceyz / babel-plugin-optimize-clsx / test / index.js View on Github external
...options,
    fixtures: devDir,
  });
} else if (process.env.TEST_BUILD) {
  const pluginPath = path.join(__dirname, '../dist/index.js');
  if (!fs.existsSync(pluginPath)) {
    throw new Error('File not found, run "yarn build" first');
  }

  pluginTester({
    ...options,
    pluginName: 'optimize-clsx-BUILD',
    plugin: require(pluginPath),
  });
} else {
  pluginTester(options);
}
github akameco / babel-plugin-react-intl-auto / src / utils / testUtils.ts View on Github external
tests: { title: string; code: string }[]
    pluginOptions?: Opts
  }[]
) {
  const defaultOpts = {
    title: '',
    plugin,
    snapshot: true,
    babelOptions: { filename, parserOpts: { plugins: ['jsx'] } },
    formatResult: (r: any) => r,
    tests: [],
  }

  for (const testCase of testCases) {
    testCase.tests = testCase.tests.map(t => ({ ...t, title: t.title }))
    pluginTester({ ...defaultOpts, ...testCase })
  }
}
github ryansolid / babel-plugin-jsx-dom-expressions / test / dom.spec.js View on Github external
const path = require('path')
const pluginTester = require('babel-plugin-tester').default;
const plugin = require('../index');

pluginTester({
  plugin,
  pluginOptions: {
    moduleName: 'r-dom',
    builtIns: ['For'],
    generate: "dom",
    delegateEvents: true,
    wrapConditionals: true,
    contextToCustomElements: true
  },
  title: 'Convert JSX',
  fixtures: path.join(__dirname, '__dom_fixtures__'),
  snapshot: true
});
github ryansolid / babel-plugin-jsx-dom-expressions / test / ssr.spec.js View on Github external
const path = require('path')
const pluginTester = require('babel-plugin-tester').default;
const plugin = require('../index');

pluginTester({
  plugin,
  pluginOptions: {
    moduleName: 'r-dom',
    builtIns: ['For'],
    generate: "ssr",
    delegateEvents: true,
    contextToCustomElements: true
  },
  title: 'Convert JSX',
  fixtures: path.join(__dirname, '__ssr_fixtures__'),
  snapshot: true
});
github ryansolid / babel-plugin-jsx-dom-expressions / test / hydrate.spec.js View on Github external
const path = require('path')
const pluginTester = require('babel-plugin-tester').default;
const plugin = require('../index');

pluginTester({
  plugin,
  pluginOptions: {
    moduleName: 'r-dom',
    builtIns: ['For'],
    generate: "hydrate",
    delegateEvents: true,
    contextToCustomElements: true
  },
  title: 'Convert JSX',
  fixtures: path.join(__dirname, '__hydrate_fixtures__'),
  snapshot: true
});

babel-plugin-tester

Utilities for testing babel plugins

MIT
Latest version published 1 year ago

Package Health Score

69 / 100
Full package analysis

Popular babel-plugin-tester functions