Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[First Step] implement transform function for .babelrc.js #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions __tests__/__snapshots__/transform.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`transform basic 1`] = `
"module.exports = {
plugins: [\\"@babel/plugin-transform-classes\\", \\"@babel/plugin-syntax-jsx\\"],
presets: [\\"@babel/preset-env\\"]
};
"
`;

exports[`transform function 1`] = `
"function createBabelrc() {
return {
plugins: [
\\"@babel/plugin-transform-classes\\",
\\"@babel/plugin-syntax-jsx\\",
\\"@babel/plugin-proposal-pipeline-operator\\"
],
presets: [\\"@babel/preset-env\\", \\"@babel/preset-react\\"]
};
}

module.exports = createBabelrc();
"
`;
20 changes: 20 additions & 0 deletions __tests__/transform.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require('fs');
const path = require('path');
const pify = require('pify');
const transform = require('../src/transform');

async function readFile(configPath) {
return (await pify(fs.readFile)(path.join(__dirname, configPath), 'utf8'));
}

describe('transform', () => {
test('basic', async () => {
const src = await readFile('../fixtures/transform/basic.js');
expect(transform(src)).toMatchSnapshot();
});

test('function', async () => {
const src = await readFile('../fixtures/transform/function.js');
expect(transform(src)).toMatchSnapshot();
});
});
4 changes: 4 additions & 0 deletions fixtures/transform/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
plugins: ['babel-plugin-transform-es2015-classes', 'babel-plugin-syntax-jsx'],
presets: ['babel-preset-env']
};
12 changes: 12 additions & 0 deletions fixtures/transform/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function createBabelrc() {
return {
plugins: [
'babel-plugin-transform-es2015-classes',
'babel-plugin-syntax-jsx',
'babel-plugin-transform-pipeline-operator'
],
presets: ['babel-preset-env', 'babel-preset-react']
};
}

module.exports = createBabelrc();
Loading