Skip to content

Commit

Permalink
Add tests for transform function
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Feb 28, 2018
1 parent 117778e commit 8b46edf
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
21 changes: 21 additions & 0 deletions __tests__/__snapshots__/transform.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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\\"],
presets: [\\"@babel/preset-env\\"]
};
}
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']
};
8 changes: 8 additions & 0 deletions fixtures/transform/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function createBabelrc() {
return {
plugins: ['babel-plugin-transform-es2015-classes', 'babel-plugin-syntax-jsx'],
presets: ['babel-preset-env']
};
}

module.exports = createBabelrc();

0 comments on commit 8b46edf

Please sign in to comment.