Skip to content

Commit c1d0001

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

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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: [\\"@babel/plugin-transform-classes\\", \\"@babel/plugin-syntax-jsx\\"],
15+
presets: [\\"@babel/preset-env\\"]
16+
};
17+
}
18+
19+
module.exports = createBabelrc();
20+
"
21+
`;

__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

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

0 commit comments

Comments
 (0)