Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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";
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('')
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');
...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);
}
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 })
}
}
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
});
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
});
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
});