Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Use .fusionrc babel plugins #93

Merged
merged 1 commit into from
Dec 28, 2017
Merged
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
9 changes: 9 additions & 0 deletions build/jest-transformer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-env node */

const loadFusionRC = require('./load-fusionrc.js');

const babelConfig = require('./babel-preset.js')(null, {
targets: {
node: 'current',
Expand All @@ -8,8 +10,15 @@ const babelConfig = require('./babel-preset.js')(null, {
transformGlobals: false,
});

const fusionConfig = loadFusionRC(process.cwd());
babelConfig.plugins.push(require.resolve('babel-plugin-dynamic-import-node'));

if (fusionConfig.babel && fusionConfig.babel.plugins) {
babelConfig.plugins = babelConfig.plugins.concat(
...fusionConfig.babel.plugins
);
}

const transformer = require('babel-jest').createTransformer(babelConfig);

const originalProcessFn = transformer.process;
Expand Down
13 changes: 12 additions & 1 deletion test/cli/test-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,18 @@ test('`fusion test-app` coverage', async t => {

test('`fusion test-app` environment variables', async t => {
const dir = path.resolve(__dirname, '../fixtures/test-jest-app');
const args = `test-app --dir=${dir} --configPath=../../../build/jest-config.js --coverage --match=environment-variables`;
const args = `test-app --dir=${dir} --configPath=../../../build/jest-config.js --match=environment-variables`;

const cmd = `require('${runnerPath}').run('${args}')`;
const response = await exec(`node -e "${cmd}"`);
t.equal(countTests(response.stderr), 2, 'ran 2 tests');

t.end();
});

test('`fusion test-app` uses .fusionjs.js', async t => {
const dir = path.resolve(__dirname, '../fixtures/test-jest-babel');
const args = `test-app --dir=${dir} --configPath=../../../build/jest-config.js`;

const cmd = `require('${runnerPath}').run('${args}')`;
const response = await exec(`node -e "${cmd}"`);
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/test-jest-babel/.fusionrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
babel: {
plugins: [require.resolve('./plugin.js')]
}
};
5 changes: 5 additions & 0 deletions test/fixtures/test-jest-babel/__tests__/babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {test} from 'fusion-test-utils';

test('string is transformed', assert => {
assert.equal("helloworld", "transformed_helloworld_custom_babel");
});
9 changes: 9 additions & 0 deletions test/fixtures/test-jest-babel/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = () => ({
visitor: {
StringLiteral(path) {
if (path.node.value === "helloworld") {
path.node.value = "transformed_helloworld_custom_babel";
}
}
}
});