Skip to content

Commit 2896706

Browse files
committed
Add tests for transform function
1 parent 797be4f commit 2896706

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`transform basic 1`] = `
4+
"module.exports = {
5+
plugins: [\\"@babel/plugin-transform-classes\\", \\"@babel/plugin-syntax-jsx\\"],
6+
presets: [\\"@babel/preset-env\\"]
7+
};
8+
"
9+
`;
10+
11+
exports[`transform function 1`] = `
12+
"function createBabelrc() {
13+
return {
14+
plugins: [
15+
\\"@babel/plugin-transform-classes\\",
16+
\\"@babel/plugin-syntax-jsx\\",
17+
\\"@babel/plugin-proposal-pipeline-operator\\"
18+
],
19+
presets: [\\"@babel/preset-env\\", \\"@babel/preset-react\\"]
20+
};
21+
}
22+
23+
module.exports = createBabelrc();
24+
"
25+
`;

__tests__/transform.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const pify = require('pify');
4+
const transform = require('../src/transform');
5+
6+
async function readFile(configPath) {
7+
return (await pify(fs.readFile)(path.join(__dirname, configPath), 'utf8'));
8+
}
9+
10+
describe('transform', () => {
11+
test('basic', async () => {
12+
const src = await readFile('../fixtures/transform/basic.js');
13+
expect(transform(src)).toMatchSnapshot();
14+
});
15+
16+
test('function', async () => {
17+
const src = await readFile('../fixtures/transform/function.js');
18+
expect(transform(src)).toMatchSnapshot();
19+
});
20+
});

fixtures/transform/basic.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
plugins: ['babel-plugin-transform-es2015-classes', 'babel-plugin-syntax-jsx'],
3+
presets: ['babel-preset-env']
4+
};

fixtures/transform/function.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function createBabelrc() {
2+
return {
3+
plugins: [
4+
'babel-plugin-transform-es2015-classes',
5+
'babel-plugin-syntax-jsx',
6+
'babel-plugin-transform-pipeline-operator'
7+
],
8+
presets: ['babel-preset-env', 'babel-preset-react']
9+
};
10+
}
11+
12+
module.exports = createBabelrc();

0 commit comments

Comments
 (0)